Skip to content

Commit

Permalink
t pushMerge branch 'be/dev/fix_put_lentExtension_to_MyProfileResponse…
Browse files Browse the repository at this point in the history
…Dto/#1424' of github.com:innovationacademy-kr/42cabi into be/dev/fix_put_lentExtension_to_MyProfileResponseDto/#1424
  • Loading branch information
junyoung2015 committed Nov 25, 2023
2 parents 1571d93 + 13c87b5 commit 4d07b90
Show file tree
Hide file tree
Showing 13 changed files with 742 additions and 724 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public LentExtensionPaginationDto getMyLentExtension(
public LentExtensionPaginationDto getMyActiveLentExtension(
@UserSession UserSessionDto userSessionDto) {
log.info("Called getMyActiveLentExtension: {}", userSessionDto.getName());
return userFacadeService.getMyActiveLentExtension(userSessionDto);
return userFacadeService.getMyActiveLentExtensionPage(userSessionDto);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.ftclub.cabinet.exception.ExceptionStatus;
import org.ftclub.cabinet.exception.ServiceException;
import org.ftclub.cabinet.user.domain.LentExtension;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
Expand Down Expand Up @@ -33,4 +31,9 @@ public Page<LentExtension> findAllNotExpired(PageRequest pageable) {
public List<LentExtension> findLentExtensionByUserId(Long userId) {
return lentExtensionRepository.findAllByUserId(userId);
}

@Transactional(readOnly = true)
public LentExtension findActiveLentExtensionByUserId(Long userId) {
return lentExtensionRepository.findByUserId(userId);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.ftclub.cabinet.user.repository;

import java.util.List;
import java.util.Optional;
import org.ftclub.cabinet.user.domain.LentExtension;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -26,4 +25,6 @@ public interface LentExtensionRepository extends JpaRepository<LentExtension, Lo
"FROM LentExtension le " +
"WHERE le.userId =:userId ")
List<LentExtension> findAllByUserId(@Param("userId") Long userId);

LentExtension findByUserId(@Param("userId") Long userId);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.ftclub.cabinet.user.service;

import java.util.List;
import org.ftclub.cabinet.dto.LentExtensionResponseDto;
import org.ftclub.cabinet.dto.UserSessionDto;

public interface LentExtensionService {
Expand All @@ -12,4 +14,6 @@ public interface LentExtensionService {

void assignLentExtension(String username);

List<LentExtensionResponseDto> getActiveLentExtensionList(UserSessionDto userSessionDto);

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.ftclub.cabinet.config.CabinetProperties;
import org.ftclub.cabinet.dto.LentExtensionResponseDto;
import org.ftclub.cabinet.dto.UserMonthDataDto;
import org.ftclub.cabinet.dto.UserSessionDto;
import org.ftclub.cabinet.exception.ExceptionStatus;
import org.ftclub.cabinet.exception.ServiceException;
import org.ftclub.cabinet.lent.domain.LentHistory;
import org.ftclub.cabinet.lent.repository.LentOptionalFetcher;
import org.ftclub.cabinet.mapper.UserMapper;
import org.ftclub.cabinet.occupiedtime.OccupiedTimeManager;
import org.ftclub.cabinet.user.domain.LentExtension;
import org.ftclub.cabinet.user.domain.LentExtensionType;
Expand All @@ -33,6 +36,7 @@ public class LentExtensionServiceImpl implements LentExtensionService {
private final UserOptionalFetcher userOptionalFetcher;
private final CabinetProperties cabinetProperties;
private final OccupiedTimeManager occupiedTimeManager;
private final UserMapper userMapper;

@Override
@Scheduled(cron = "${spring.schedule.cron.extension-issue-time}")
Expand Down Expand Up @@ -67,6 +71,18 @@ public void assignLentExtension(String username) {
lentExtensionRepository.save(lentExtension);
}

@Override
public List<LentExtensionResponseDto> getActiveLentExtensionList(
UserSessionDto userSessionDto) {
log.debug("Called getLentExtensionList {}", userSessionDto.getName());
return lentExtensionOptionalFetcher.findLentExtensionByUserId(userSessionDto.getUserId())
.parallelStream()
.filter(lentExtension -> lentExtension.getUsedAt() == null &&
lentExtension.getExpiredAt().isAfter(LocalDateTime.now()))
.map(userMapper::toLentExtensionResponseDto)
.collect(Collectors.toList());
}

@Override
@Scheduled(cron = "${spring.schedule.cron.extension-delete-time}")
public void deleteLentExtension() {
Expand All @@ -80,18 +96,19 @@ public void useLentExtension(Long userId, String username) {

List<LentExtension> findLentExtension =
lentExtensionOptionalFetcher.findLentExtensionByUserId(userId)
.stream()
.filter(lentExtension ->
lentExtension.getExpiredAt().isAfter(LocalDateTime.now())
&& lentExtension.getUsedAt() == null)
.collect(Collectors.toList());
.stream()
.filter(lentExtension ->
lentExtension.getExpiredAt().isAfter(LocalDateTime.now())
&& lentExtension.getUsedAt() == null)
.collect(Collectors.toList());
if (findLentExtension.isEmpty()) {
throw new ServiceException(ExceptionStatus.EXTENSION_NOT_FOUND);
}
LentExtension lentExtension = findLentExtension.get(0);
LentHistory lentHistory = lentOptionalFetcher.getActiveLentHistoryWithUserId(userId);
lentExtension.use();
lentHistory.setExpiredAt(lentHistory.getExpiredAt().plusDays(lentExtension.getExtensionPeriod()));
lentHistory.setExpiredAt(
lentHistory.getExpiredAt().plusDays(lentExtension.getExtensionPeriod()));
}

}
Loading

0 comments on commit 4d07b90

Please sign in to comment.