-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat/#70] 사물함 신청 API 추가 #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dcf044e
feat: 사물함 신청에 신청 일시와 사물함 유니크 제약 추가
leegain1 b2f1a19
feat: 사물함 신청 서비스 추가
leegain1 e7a6037
feat: 사물함 신청 API 추가
leegain1 c0eacc0
test: 사물함 신청 서비스 단위 테스트 추가
leegain1 c2e8c2d
refactor: 사물함 신청 검증을 private 메서드로 분리
leegain1 fb9e2da
refactor: 사물함 신청 레포지토리를 LockerApplicationRepository로 분리
leegain1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
20 changes: 20 additions & 0 deletions
20
...i/src/main/java/kr/ac/kookmin/stream/api/app/event/locker/request/LockerApplyRequest.java
This file contains hidden or 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,20 @@ | ||
| package kr.ac.kookmin.stream.api.app.event.locker.request; | ||
|
|
||
| import jakarta.validation.constraints.NotNull; | ||
| import kr.ac.kookmin.stream.event.domain.locker.domain.LockerApplyCommand; | ||
|
|
||
| /** | ||
| * @param lockerPeriodId 신청할 운영 회차. 구역 조회에 쓴 회차 식별자를 그대로 보낸다 | ||
| */ | ||
| public record LockerApplyRequest( | ||
| @NotNull(message = "사물함 운영 회차를 입력해 주세요.") | ||
| Long lockerPeriodId, | ||
|
|
||
| @NotNull(message = "신청할 사물함을 선택해 주세요.") | ||
| Long lockerId | ||
| ) { | ||
|
|
||
| public LockerApplyCommand toCommand() { | ||
| return new LockerApplyCommand(lockerPeriodId, lockerId); | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
...src/main/java/kr/ac/kookmin/stream/api/app/event/locker/response/LockerApplyResponse.java
This file contains hidden or 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,23 @@ | ||
| package kr.ac.kookmin.stream.api.app.event.locker.response; | ||
|
|
||
| import java.time.LocalDate; | ||
| import kr.ac.kookmin.stream.event.domain.locker.domain.LockerApplicationResult; | ||
|
|
||
| public record LockerApplyResponse( | ||
| Long lockerApplicationId, | ||
| Long lockerId, | ||
| String lockerLabel, | ||
| LocalDate usageStartDate, | ||
| LocalDate usageEndDate | ||
| ) { | ||
|
|
||
| public static LockerApplyResponse from(LockerApplicationResult result) { | ||
| return new LockerApplyResponse( | ||
| result.application().getId(), | ||
| result.locker().getId(), | ||
| result.locker().getLockerLabel(), | ||
| result.period().getUsageStartAt(), | ||
| result.period().getUsageEndAt() | ||
| ); | ||
| } | ||
| } |
This file contains hidden or 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
7 changes: 7 additions & 0 deletions
7
...rc/main/java/kr/ac/kookmin/stream/event/domain/locker/domain/LockerApplicationResult.java
This file contains hidden or 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,7 @@ | ||
| package kr.ac.kookmin.stream.event.domain.locker.domain; | ||
|
|
||
| /** | ||
| * 사물함 신청 결과. 생성된 신청과 배정된 사물함, 사용 기간을 알려줄 운영 회차를 함께 돌려준다. | ||
| */ | ||
| public record LockerApplicationResult(LockerApplication application, Locker locker, LockerPeriod period) { | ||
| } |
7 changes: 7 additions & 0 deletions
7
...ent/src/main/java/kr/ac/kookmin/stream/event/domain/locker/domain/LockerApplyCommand.java
This file contains hidden or 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,7 @@ | ||
| package kr.ac.kookmin.stream.event.domain.locker.domain; | ||
|
|
||
| /** | ||
| * 사물함 신청 요청. 신청할 운영 회차와 고른 사물함을 담는다. | ||
| */ | ||
| public record LockerApplyCommand(Long lockerPeriodId, Long lockerId) { | ||
| } |
This file contains hidden or 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
32 changes: 32 additions & 0 deletions
32
...java/kr/ac/kookmin/stream/event/domain/locker/repository/LockerApplicationRepository.java
This file contains hidden or 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,32 @@ | ||
| package kr.ac.kookmin.stream.event.domain.locker.repository; | ||
|
|
||
| import java.util.Optional; | ||
| import java.util.Set; | ||
| import kr.ac.kookmin.stream.event.domain.locker.domain.LockerApplication; | ||
|
|
||
| /** | ||
| * 사물함 신청 저장소. 운영 회차·구역·사물함은 {@link LockerRepository}가 맡는다. | ||
| */ | ||
| public interface LockerApplicationRepository { | ||
|
|
||
| /** | ||
| * 해당 운영 회차에 이 사물함이 이미 신청되었는지. | ||
| */ | ||
| boolean existsByLocker(Long lockerPeriodId, Long lockerId); | ||
|
|
||
| /** | ||
| * 해당 운영 회차에 이미 신청된 사물함 식별자. | ||
| */ | ||
| Set<Long> findAppliedLockerIds(Long lockerPeriodId); | ||
|
|
||
| /** | ||
| * 해당 운영 회차에서 회원이 신청한 사물함 식별자. 회차당 한 건만 신청할 수 있고 취소가 없어 최대 하나다. | ||
| */ | ||
| Optional<Long> findAppliedLockerId(Long lockerPeriodId, Long memberId); | ||
|
|
||
| /** | ||
| * 신청을 저장한다. 같은 회차의 같은 사물함에 먼저 저장된 신청이 있으면 | ||
| * {@link kr.ac.kookmin.stream.event.domain.locker.domain.LockerErrorCode#LOCKER_ALREADY_ASSIGNED}로 실패한다. | ||
| */ | ||
| LockerApplication save(LockerApplication application); | ||
| } |
This file contains hidden or 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
13 changes: 13 additions & 0 deletions
13
.../main/java/kr/ac/kookmin/stream/event/domain/locker/service/LockerApplicationService.java
This file contains hidden or 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,13 @@ | ||
| package kr.ac.kookmin.stream.event.domain.locker.service; | ||
|
|
||
| import kr.ac.kookmin.stream.event.domain.locker.domain.LockerApplicationResult; | ||
| import kr.ac.kookmin.stream.event.domain.locker.domain.LockerApplyCommand; | ||
|
|
||
| /** 사물함 신청. 구역·배치 조회는 {@link LockerService}가 맡는다. */ | ||
| public interface LockerApplicationService { | ||
|
|
||
| /** | ||
| * 고른 사물함을 신청하고 즉시 배정한다. 같은 사물함에 동시에 신청하면 먼저 저장된 신청만 성공한다. | ||
| */ | ||
| LockerApplicationResult apply(Long memberId, LockerApplyCommand command); | ||
| } |
58 changes: 58 additions & 0 deletions
58
...a/kr/ac/kookmin/stream/event/domain/locker/service/impl/LockerApplicationServiceImpl.java
This file contains hidden or 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,58 @@ | ||
| package kr.ac.kookmin.stream.event.domain.locker.service.impl; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import kr.ac.kookmin.stream.common.BusinessException; | ||
| import kr.ac.kookmin.stream.event.domain.locker.domain.Locker; | ||
| import kr.ac.kookmin.stream.event.domain.locker.domain.LockerApplication; | ||
| import kr.ac.kookmin.stream.event.domain.locker.domain.LockerApplicationResult; | ||
| import kr.ac.kookmin.stream.event.domain.locker.domain.LockerApplyCommand; | ||
| import kr.ac.kookmin.stream.event.domain.locker.domain.LockerErrorCode; | ||
| import kr.ac.kookmin.stream.event.domain.locker.domain.LockerPeriod; | ||
| import kr.ac.kookmin.stream.event.domain.locker.repository.LockerApplicationRepository; | ||
| import kr.ac.kookmin.stream.event.domain.locker.repository.LockerRepository; | ||
| import kr.ac.kookmin.stream.event.domain.locker.service.LockerApplicationService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| class LockerApplicationServiceImpl implements LockerApplicationService { | ||
|
|
||
| private final LockerRepository lockerRepository; | ||
| private final LockerApplicationRepository lockerApplicationRepository; | ||
|
|
||
| @Override | ||
| @Transactional | ||
| public LockerApplicationResult apply(Long memberId, LockerApplyCommand command) { | ||
| LockerPeriod period = getPublishedPeriod(command.lockerPeriodId()); | ||
| Locker locker = getSelectableLocker(period.getId(), command.lockerId()); | ||
|
|
||
| LockerApplication application = lockerApplicationRepository.save( | ||
| LockerApplication.create(period.getId(), memberId, locker.getId(), LocalDateTime.now()) | ||
| ); | ||
| return new LockerApplicationResult(application, locker, period); | ||
| } | ||
|
|
||
| /** 게시된 운영 회차. 아직 공개하지 않은 회차는 학생에게 없는 것으로 보여야 하므로 구역 조회와 같은 기준으로 거른다. */ | ||
| private LockerPeriod getPublishedPeriod(Long lockerPeriodId) { | ||
| return lockerRepository.findPublishedPeriodById(lockerPeriodId) | ||
| .orElseThrow(() -> new BusinessException(LockerErrorCode.LOCKER_PERIOD_NOT_FOUND)); | ||
| } | ||
|
|
||
| /** | ||
| * 해당 운영 회차에 선택할 수 있는 사물함. 구역 조회와 같은 기준({@link Locker#isSelectable})으로 판정한다. | ||
| * <p> | ||
| * 흔한 경우를 먼저 거르는 검사일 뿐이다. 이 검사와 저장 사이에 끼어든 신청은 저장 시 유니크 제약이 막는다. | ||
| */ | ||
| private Locker getSelectableLocker(Long lockerPeriodId, Long lockerId) { | ||
| // 구역 상세에서 선택 가능한 사물함만 고를 수 있어 정상 흐름에서는 없는 사물함이 들어오지 않는다 | ||
| Locker locker = lockerRepository.findLockerById(lockerId) | ||
| .orElseThrow(() -> new IllegalArgumentException("존재하지 않는 사물함입니다. lockerId=" + lockerId)); | ||
|
|
||
| if (!locker.isSelectable(lockerApplicationRepository.existsByLocker(lockerPeriodId, lockerId))) { | ||
| throw new BusinessException(LockerErrorCode.LOCKER_ALREADY_ASSIGNED); | ||
| } | ||
| return locker; | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
없는 사물함 요청이 500으로 응답됩니다.
lockerId는 클라이언트 요청 본문에서 옵니다. 클라이언트가 임의의 값이나 삭제된 사물함 ID를 보낼 수 있습니다. 이 경우IllegalArgumentException이 발생하고, 응답은 500이 됩니다. PR 설명에도 이 동작이 한계로 적혀 있습니다. path instructions는 "예외는 BusinessException 계층 + ErrorCode로 던진다"고 규정합니다.LockerErrorCode에LOCKER_NOT_FOUND(NOT_FOUND)를 추가하고, 이 코드로BusinessException을 던지세요.AppLockerApi의@ApiErrorCode목록도 함께 갱신하세요.수정 예시
📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Path instructions