Skip to content

Commit

Permalink
[BE] REFACTOR:
Browse files Browse the repository at this point in the history
getMyProfile 에서, LentExtension 하나만 가져오도록 메소드 수정
  • Loading branch information
enaenen committed Nov 25, 2023
1 parent f44d8db commit 13c87b5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
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
Expand Up @@ -62,15 +62,14 @@ public MyProfileResponseDto getMyProfile(UserSessionDto user) {
BanHistory banHistory = userOptionalFetcher.findRecentActiveBanHistory(user.getUserId(),
LocalDateTime.now());

List<LentExtensionResponseDto> lentExtensionResponseDtos = lentExtensionService.getActiveLentExtensionList(
user);

if (lentExtensionResponseDtos.isEmpty()) {
return userMapper.toMyProfileResponseDto(user, cabinet, banHistory, null);
}
LentExtensionResponseDto lentExtensionResponseDto =
userMapper.toLentExtensionResponseDto(
lentExtensionOptionalFetcher.findActiveLentExtensionByUserId(
user.getUserId())
);

return userMapper.toMyProfileResponseDto(user, cabinet, banHistory,
lentExtensionResponseDtos.get(0));
lentExtensionResponseDto);
}

@Override
Expand Down

0 comments on commit 13c87b5

Please sign in to comment.