Skip to content

Commit

Permalink
πŸ› 12μ‹œ 이후 λ―Έμ…˜ 인증 μ•ˆλ˜λŠ” μ—λŸ¬ 처리 (#380)
Browse files Browse the repository at this point in the history
* fix: λ―Έμ…˜ 인증 초과 validate

* fix: spotlessApply

* fix: magic number μƒμˆ˜ν™”

* fix: μ—λŸ¬ μ½”λ“œ λ³€κ²½

* fix: spotlessApply
  • Loading branch information
char-yb authored Apr 3, 2024
1 parent 0c1035f commit 50e5bcb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@
public class MissionRecordService {
private static final int EXPIRATION_TIME = 10;
private static final int DAYS_ADJUSTMENT = 1;
private static final long MAX_DURATION_HOUR = 24;

private final MemberUtil memberUtil;
private final MissionRepository missionRepository;
private final MissionRecordRepository missionRecordRepository;
private final MissionRecordTtlRepository missionRecordTtlRepository;

public MissionRecordCreateResponse createMissionRecord(MissionRecordCreateRequest request) {
long diffHour = Duration.between(request.startedAt(), request.finishedAt()).toHours();
validateMissionRecordDurationOverTime(diffHour);

final Mission mission = findMissionById(request.missionId());
final Member member = memberUtil.getCurrentMember();

Expand Down Expand Up @@ -65,6 +69,12 @@ public MissionRecordCreateResponse createMissionRecord(MissionRecordCreateReques
return MissionRecordCreateResponse.from(createdMissionRecord.getId());
}

private void validateMissionRecordDurationOverTime(long diffHour) {
if (diffHour >= MAX_DURATION_HOUR) {
throw new CustomException(ErrorCode.MISSION_RECORD_DURATION_OVERTIME);
}
}

private void validateMissionRecordExistsToday(Long missionId) {
if (missionRecordRepository.isCompletedMissionExistsToday(missionId)) {
throw new CustomException(ErrorCode.MISSION_RECORD_ALREADY_EXISTS_TODAY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public enum ErrorCode {
MISSION_RECORD_UPLOAD_STATUS_IS_NOT_PENDING(
HttpStatus.BAD_REQUEST, "λ―Έμ…˜ 기둝의 이미지 μ—…λ‘œλ“œ μƒνƒœκ°€ PENDING이 μ•„λ‹™λ‹ˆλ‹€."),
MISSION_RECORD_ALREADY_EXISTS_TODAY(HttpStatus.BAD_REQUEST, "였늘 이미 μž‘μ„± 된 λ―Έμ…˜ 기둝이 μ‘΄μž¬ν•©λ‹ˆλ‹€."),
MISSION_RECORD_DURATION_OVERTIME(HttpStatus.CONFLICT, "κ°€λŠ₯ν•œ λ―Έμ…˜ 인증 μ‹œκ°„μ΄ μ΄ˆκ³Όλ˜μ—ˆμŠ΅λ‹ˆλ‹€."),

// Follow
FOLLOW_TARGET_MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "νƒ€κ²Ÿ μœ μ €μ„ 찾을 수 μ—†μŠ΅λ‹ˆλ‹€."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ void setUp() {
missionRepository.save(mission);
}

@Test
void ν•˜λ£¨κ°€_μ§€λ‚˜_λ―Έμ…˜_μΈμ¦ν•œ_경우_μ—λŸ¬λ₯Ό_λ°œμƒμ‹œν‚¨λ‹€() {
// exception
assertThrows(
CustomException.class,
() ->
missionRecordService.createMissionRecord(
new MissionRecordCreateRequest(
mission.getId(), now, now.plusDays(1), 20, 0)));
}

@Test
void 진행쀑인_λ―Έμ…˜κΈ°λ‘μ„_μ‚­μ œν•œλ‹€() {
// given
Expand Down

0 comments on commit 50e5bcb

Please sign in to comment.