Skip to content

Commit

Permalink
[BE] 동아리 사물함 여러개 배정 오류 #1560 (#1561)
Browse files Browse the repository at this point in the history
* [BE] FIX: ADMIN 동아리 대여(할당) 전 이미 대여중인 사물함이 있는지 확인

* [BE]FIX: config change
  • Loading branch information
enaenen authored Mar 8, 2024
1 parent 626052f commit 74a62f8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void endCabinetLent(List<Long> cabinetIds) {
lentQueryService.findCabinetsActiveLentHistories(cabinetIds);
Map<Long, List<LentHistory>> lentHistoriesByCabinetId = lentHistories.stream()
.collect(Collectors.groupingBy(LentHistory::getCabinetId));

// is club cabinet
if (lentHistories.isEmpty()) {
endClubCabinetLent(cabinetIds, cabinets);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ public interface ClubLentRepository extends JpaRepository<ClubLentHistory, Long>
+ "WHERE clh.cabinetId IN :cabinetIds "
+ "AND clh.endedAt IS NULL ")
Optional<List<ClubLentHistory>> findByEndedAtIsNullJoinCabinets(List<Long> cabinetIds);

Optional<ClubLentHistory> findByClubIdAndEndedAtIsNull(Long clubId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public class ClubLentQueryService {

private final ClubLentRepository clubLentRepository;

public void findAlreadyExistsClubLentHistory(Long clubId) {
clubLentRepository.findByClubIdAndEndedAtIsNull(clubId).ifPresent(clubLentHistory -> {
throw ExceptionStatus.LENT_ALREADY_EXISTED.asServiceException();
});
}

public ClubLentHistory findActiveLentHistoryWithClub(Long cabinetId) {
return clubLentRepository.findByCabinetIdAndEndedAtIsNullJoinClub(cabinetId)
.orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ public void startLentClubCabinet(Long clubId, Long cabinetId) {

LocalDateTime expiredAt = lentPolicyService.generateExpirationDate(now,
cabinet.getLentType(), 1);
clubLentQueryService.findAlreadyExistsClubLentHistory(clubId);
clubLentCommandService.startLent(clubId, cabinetId, expiredAt);
cabinetCommandService.updateTitle(cabinet, club.getName());
cabinetCommandService.changeUserCount(cabinet, userCount + 1);
Expand Down
2 changes: 1 addition & 1 deletion config

0 comments on commit 74a62f8

Please sign in to comment.