Skip to content

Commit

Permalink
Merge pull request #256 from MOONSHOT-Team/feature/$255
Browse files Browse the repository at this point in the history
[Fix] #255 - KeyResult API, Task API Json 스펙 통일
  • Loading branch information
0lynny authored Mar 21, 2024
2 parents 20f90a8 + 364b120 commit 9c0faa8
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@ public record KeyResultCreateRequestDto(
@NotNull(message = "KR이 생성될 ObjectiveId를 입력해주세요.")
Long objectiveId,
@Size(min = 1, max = 30, message = "KR은 30자 이하여야 합니다.")
String title,
String krTitle,
@NotNull(message = "KR 시작 날짜를 선택해주세요.")
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
LocalDate startAt,
LocalDate krStartAt,
@NotNull(message = "KR 종료 날짜를 선택해주세요.")
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
LocalDate expireAt,
LocalDate krExpireAt,
@NotNull(message = "KR의 순서를 입력해주세요.")
@Range(min = 0, max = 2, message = "KeyResult의 순서는 0부터 2까지로 설정할 수 있습니다.")
Integer idx,
Integer krIdx,
@NotNull(message = "KR 목표 수치를 입력해주세요.")

@Range(min = 1, max = 999999L, message = "수치는 999,999 이하여야 합니다.")
Long target,
Long krTarget,
@NotNull(message = "KR 목표 수치의 단위를 입력해주세요.")
String metric
String krMetric
) {
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public record KeyResultModifyRequestDto(
@NotNull(message = "수정할 KeyResult Id를 입력해주세요")
Long keyResultId,
@Size(min = 1, max = 30, message = "KR은 30자 이하여야 합니다.")
String title,
LocalDate startAt,
LocalDate expireAt,
String krTitle,
LocalDate krStartAt,
LocalDate krExpireAt,
@Range(min = 1, max = 999999L, message = "수치는 999,999 이하여야 합니다.")
Long target,
KRState state,
Long krTarget,
KRState krState,
@Size(min = 1, max = 100, message = "본문은 100자 이하여야 합니다.")
String logContent
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ public void createKeyResult(final KeyResultCreateRequestDto request, final Long

List<KeyResult> krList = keyResultRepository.findAllByObjective(objective);
validateActiveKRSizeExceeded(krList.size());
validateIndexUnderMaximum(request.idx(), krList.size());
validateIndexUnderMaximum(request.krIdx(), krList.size());

keyResultRepository.bulkUpdateIdxIncrease(request.idx(), krList.size(), objective.getId(), -1L);
keyResultRepository.bulkUpdateIdxIncrease(request.krIdx(), krList.size(), objective.getId(), -1L);

KeyResult keyResult = keyResultRepository.save(KeyResult.builder()
.objective(objective)
.title(request.title())
.period(Period.of(request.startAt(), request.expireAt()))
.idx(request.idx())
.target(request.target())
.metric(request.metric()).build());
.title(request.krTitle())
.period(Period.of(request.krStartAt(), request.krExpireAt()))
.idx(request.krIdx())
.target(request.krTarget())
.metric(request.krMetric()).build());
logService.createKRLog(request, keyResult.getId());
}

Expand Down Expand Up @@ -140,33 +140,33 @@ public Optional<AchieveResponseDto> modifyKeyResult(final KeyResultModifyRequest
.orElseThrow(() -> new NotFoundException(NOT_FOUND_KEY_RESULT));
validateUserAuthorization(keyResult.getObjective().getUser().getId(), userId);

if (hasChange(request.title())) {
keyResult.modifyTitle(request.title());
if (hasChange(request.krTitle())) {
keyResult.modifyTitle(request.krTitle());
}

if (hasChange(request.state())) {
keyResult.modifyState(request.state());
if (hasChange(request.krState())) {
keyResult.modifyState(request.krState());
return Optional.empty();
}

if (hasDateChange(request.startAt(), request.expireAt())) {
LocalDate newStartAt = getLatestDate(request.startAt(), keyResult.getPeriod().getStartAt());
LocalDate newExpireAt = getLatestDate(request.expireAt(), keyResult.getPeriod().getExpireAt());
if (hasDateChange(request.krStartAt(), request.krExpireAt())) {
LocalDate newStartAt = getLatestDate(request.krStartAt(), keyResult.getPeriod().getStartAt());
LocalDate newExpireAt = getLatestDate(request.krExpireAt(), keyResult.getPeriod().getExpireAt());
validateKeyResultPeriod(keyResult.getObjective().getPeriod(), newStartAt, newExpireAt);

keyResult.modifyPeriod(Period.of(newStartAt, newExpireAt));
return Optional.empty();
}

if (request.target() == null || request.logContent() == null){
if (request.krTarget() == null || request.logContent() == null){
throw new BadRequestException(REQUIRED_KEY_RESULT_VALUE);
}

Log updateLog = logService.createUpdateLog(request, keyResult.getId());
validateLogNum(request.target(), updateLog.getKeyResult().getTarget());
validateLogNum(request.krTarget(), updateLog.getKeyResult().getTarget());

Optional<Log> prevLog = logRepository.findLatestLogByKeyResultId(LogState.RECORD, request.keyResultId());
keyResult.modifyTarget(request.target());
keyResult.modifyTarget(request.krTarget());
if(prevLog.isPresent()) {
keyResult.modifyProgress(logService.calculateKRProgressBar(prevLog.get(), keyResult.getTarget()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Log createUpdateLog(final KeyResultModifyRequestDto request, final Long k
return logRepository.save(Log.builder()
.date(LocalDateTime.now())
.state(LogState.UPDATE)
.currNum(request.target())
.currNum(request.krTarget())
.prevNum(keyResult.getTarget())
.content(request.logContent())
.keyResult(keyResult)
Expand All @@ -94,7 +94,7 @@ public void createKRLog(final Object request, final Long keyResultId) {
logRepository.save(Log.builder()
.date(LocalDateTime.now())
.state(LogState.CREATE)
.currNum(dto.target())
.currNum(dto.krTarget())
.content("")
.keyResult(keyResult)
.build());
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public record TaskSingleCreateRequestDto(
@NotNull(message = "KR이 생성될 KeyResult Id를 입력해주세요.")
Long keyResultId,
@Size(min = 1, max = 30, message = "Task는 30자 이하여야 합니다.")
String title,
String taskTitle,
@NotNull(message = "KR 순서를 입력해주세요")
@Range(min = 0, max = 2, message = "KeyResult의 순서는 0부터 2까지로 설정할 수 있습니다.")
Integer idx
Integer taskIdx
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ public void createTask(final TaskSingleCreateRequestDto request, final Long user

List<Task> taskList = taskRepository.findAllByKeyResultOrderByIdx(keyResult);
validateActiveTaskSizeExceeded(taskList.size());
validateIndexUnderMaximum(request.idx(), taskList.size());
validateIndexUnderMaximum(request.taskIdx(), taskList.size());

taskRepository.bulkUpdateTaskIdxIncrease(request.idx(), taskList.size(), keyResult.getId(), -1L);
taskRepository.bulkUpdateTaskIdxIncrease(request.taskIdx(), taskList.size(), keyResult.getId(), -1L);

saveTask(keyResult, request);
}

public void saveTask(final KeyResult keyResult, final TaskSingleCreateRequestDto request) {
taskRepository.save(Task.builder()
.title(request.title())
.idx(request.idx())
.title(request.taskTitle())
.idx(request.taskIdx())
.keyResult(keyResult)
.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ public class WhiteListConstants {
"/login/oauth2/code/kakao",
"/login/oauth2/code/google",
"/v1/user/login",
"/v1/user/googleLogin",
"/login",
"/googleLogin",
"/oauth/authorize",
"/actuator/health",
"/error",
Expand All @@ -29,8 +27,7 @@ public class WhiteListConstants {
"/swagger-resources/**",
"/api-docs/**",
"/v3/api-docs/**",
"/webjars/**",
"/googleLogin"
"/webjars/**"
};

}

0 comments on commit 9c0faa8

Please sign in to comment.