-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BE] FEAT & REFACTOR : 연장권 사용 로직 추가 및 LentExtensionService로 연장권 관련 서비…
…스 로직 이동
- Loading branch information
1 parent
0164a6f
commit 4dc1362
Showing
8 changed files
with
158 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
backend/src/main/java/org/ftclub/cabinet/user/service/LentExtensionService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.ftclub.cabinet.user.service; | ||
|
||
import java.util.List; | ||
import org.ftclub.cabinet.dto.UserSessionDto; | ||
import org.ftclub.cabinet.user.domain.LentExtension; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
|
||
public interface LentExtensionService { | ||
|
||
List<LentExtension> getLentExtensionByUserId(Long userId); | ||
|
||
List<LentExtension> getLentExtensionNotExpiredByUserId(Long userId); | ||
|
||
Page<LentExtension> getAllLentExtension(PageRequest pageable); | ||
|
||
Page<LentExtension> getAllActiveLentExtension(PageRequest pageable); | ||
|
||
public void issueLentExtension(); | ||
|
||
public void deleteLentExtension(); | ||
|
||
public void useLentExtension(UserSessionDto userSessionDto); | ||
} |
89 changes: 89 additions & 0 deletions
89
backend/src/main/java/org/ftclub/cabinet/user/service/LentExtensionServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package org.ftclub.cabinet.user.service; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import javax.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.ftclub.cabinet.config.CabinetProperties; | ||
import org.ftclub.cabinet.dto.UserSessionDto; | ||
import org.ftclub.cabinet.lent.domain.LentHistory; | ||
import org.ftclub.cabinet.lent.repository.LentOptionalFetcher; | ||
import org.ftclub.cabinet.occupiedtime.OccupiedTimeManager; | ||
import org.ftclub.cabinet.occupiedtime.UserMonthDataDto; | ||
import org.ftclub.cabinet.user.domain.LentExtension; | ||
import org.ftclub.cabinet.user.domain.LentExtensionType; | ||
import org.ftclub.cabinet.user.repository.LentExtensionRepository; | ||
import org.ftclub.cabinet.user.repository.UserOptionalFetcher; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
@Log4j2 | ||
public class LentExtensionServiceImpl implements LentExtensionService { | ||
|
||
private final LentExtensionRepository lentExtensionRepository; | ||
private final LentOptionalFetcher lentOptionalFetcher; | ||
private final UserOptionalFetcher userOptionalFetcher; | ||
private final CabinetProperties cabinetProperties; | ||
private final OccupiedTimeManager occupiedTimeManager; | ||
|
||
@Override | ||
public Page<LentExtension> getAllLentExtension(PageRequest pageable) { | ||
return lentExtensionRepository.findAll(pageable); | ||
} | ||
|
||
@Override | ||
public Page<LentExtension> getAllActiveLentExtension(PageRequest pageable) { | ||
return lentExtensionRepository.findAllNotExpired(pageable); | ||
} | ||
|
||
@Override | ||
public List<LentExtension> getLentExtensionByUserId(Long userId) { | ||
return lentExtensionRepository.findAllByUserId(userId); | ||
} | ||
|
||
@Override | ||
public List<LentExtension> getLentExtensionNotExpiredByUserId(Long userId) { | ||
return lentExtensionRepository.findAllByUserIdNotExpired(userId); | ||
} | ||
|
||
@Override | ||
@Scheduled(cron = "${spring.schedule.cron.extension-issue-time}") | ||
public void issueLentExtension() { | ||
log.debug("Called issueLentExtension"); | ||
List<UserMonthDataDto> userMonthDataDtos = occupiedTimeManager.metLimitTimeUser( | ||
occupiedTimeManager.getUserLastMonthOccupiedTime()); | ||
LocalDateTime now = LocalDateTime.now(); | ||
userMonthDataDtos.stream().forEach(userMonthDataDto -> { | ||
LentExtension lentExtension = LentExtension.of("lentExtension", | ||
cabinetProperties.getLentExtendTerm(), | ||
LocalDateTime.of(now.getYear(), now.getMonth(), | ||
now.getMonth().length(now.toLocalDate().isLeapYear()), 23, 59, 0), | ||
LentExtensionType.ALL, | ||
userOptionalFetcher.findUserByName(userMonthDataDto.getLogin()).getUserId()); | ||
lentExtensionRepository.save(lentExtension); | ||
}); | ||
} | ||
|
||
@Override | ||
@Scheduled(cron = "${spring.schedule.cron.extension-delete-time}") | ||
public void deleteLentExtension() { | ||
log.debug("Called deleteExtension"); | ||
lentExtensionRepository.deleteAll(); | ||
} | ||
|
||
@Override | ||
public void useLentExtension(UserSessionDto userSessionDto) { | ||
log.debug("Called useLentExtension"); | ||
|
||
LentHistory lentHistory = lentOptionalFetcher.getActiveLentHistoryWithUserId( | ||
userSessionDto.getUserId()); | ||
lentHistory.setExpiredAt( | ||
lentHistory.getExpiredAt().plusDays(cabinetProperties.getLentExtendTerm())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters