Skip to content

Commit

Permalink
Merge pull request #243 from MOONSHOT-Team/feature/#241
Browse files Browse the repository at this point in the history
[Fix] Objective API Json POST, GET 스펙 통일 및 History GET 스펙 변경
  • Loading branch information
its-sky authored Mar 7, 2024
2 parents fa48d73 + 7ac7efb commit 1b2aca6
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@

public record KeyResultCreateRequestInfoDto(
@Size(min = 1, max = 30, message = "KR은 30자 이하여야 합니다.")
String title,
String krTitle,
@NotNull(message = "KR 시작 날짜를 선택해주세요.")
LocalDate startAt,
LocalDate krStartAt,
@NotNull(message = "KR 종료 날짜를 선택해주세요.")
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,
@Valid @Size(max = 3, message = "Task 개수는 최대 3개로 제한되어 있습니다.")
List<TaskCreateRequestDto> taskList
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import org.moonshot.task.dto.response.TaskResponseDto;

public record KeyResultResponseDto(
Long keyResultId,
String keyResultTitle,
Integer idx,
Long krId,
String krTitle,
Integer krIdx,
List<TaskResponseDto> taskList
) {
public static List<KeyResultResponseDto> of(List<KeyResult> krList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ public void createInitKRWithObjective(final Objective objective, final List<KeyR
List<KeyResultCreateRequestInfoDto> nonNullRequests = requests.stream().filter(Objects::nonNull).toList();
for (int i = 0; i < nonNullRequests.size(); i++) {
KeyResultCreateRequestInfoDto dto = nonNullRequests.get(i);
validateKeyResultIndex(i, dto.idx());
validateKRPeriodWithInObjPeriod(objective.getPeriod(), dto.startAt(), dto.expireAt());
validateKeyResultIndex(i, dto.krIdx());
validateKRPeriodWithInObjPeriod(objective.getPeriod(), dto.krStartAt(), dto.krExpireAt());

KeyResult keyResult = keyResultRepository.save(KeyResult.builder()
.title(dto.title())
.period(Period.of(dto.startAt(), dto.expireAt()))
.idx(dto.idx())
.target(dto.target())
.metric(dto.metric())
.title(dto.krTitle())
.period(Period.of(dto.krStartAt(), dto.krExpireAt()))
.idx(dto.krIdx())
.target(dto.krTarget())
.metric(dto.krMetric())
.objective(objective)
.build());
logService.createKRLog(dto, keyResult.getId());
Expand Down Expand Up @@ -228,7 +228,7 @@ private void saveTasks(final KeyResult keyResult, final List<TaskCreateRequestDt
List<TaskCreateRequestDto> nonNullTaskList = taskList.stream().filter(Objects::nonNull).toList();
for (int i = 0; i < nonNullTaskList.size(); i++) {
TaskCreateRequestDto taskDto = nonNullTaskList.get(i);
validateTaskIndex(i, taskDto.idx());
validateTaskIndex(i, taskDto.taskIdx());
taskService.saveTask(keyResult, taskDto);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.moonshot.exception.keyresult.KeyResultNotFoundException;
import org.moonshot.exception.log.InvalidLogValueException;
import org.moonshot.keyresult.dto.request.KeyResultCreateRequestDto;
import org.moonshot.keyresult.dto.request.KeyResultCreateRequestInfoDto;
import org.moonshot.keyresult.dto.request.KeyResultModifyRequestDto;
Expand Down Expand Up @@ -84,7 +83,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
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public ResponseEntity<MoonshotResponse<DashboardResponseDto>> getObjectiveInDash

@GetMapping("/history")
@Logging(item = "Objective", action = "Get")
public ResponseEntity<MoonshotResponse<HistoryResponseDto>> getObjectiveHistory(@LoginUser Long userId, @RequestParam(required = false) final Integer year,
@RequestParam(required = false) final Category category,
@RequestParam(required = false) final Criteria criteria) {
public ResponseEntity<MoonshotResponse<HistoryResponseDto>> getObjectiveHistory(@LoginUser Long userId, @RequestParam(required = false, name = "year") final Integer year,
@RequestParam(required = false, name = "category") final Category category,
@RequestParam(required = false, name = "criteria") final Criteria criteria) {
HistoryResponseDto response = objectiveService.getObjectiveHistory(userId, year, category, criteria);
return ResponseEntity.ok(MoonshotResponse.success(SuccessType.OK, response));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

public record HistoryObjectiveListDto(
Long objId,
String title,
String objTitle,
String objCategory,
int progress,
int objProgress,
String objPeriod,
int objIdx,
List<HistoryKeyResultDto> krList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

public record TaskCreateRequestDto(
@Size(max = 30, message = "Task는 30자 이하여야 합니다.")
String title,
String taskTitle,
@NotNull(message = "KR 순서를 입력해주세요")
@Range(min = 0, max = 2, message = "Task의 순서는 0부터 2까지로 설정할 수 있습니다.")
Integer idx
Integer taskIdx
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import org.moonshot.task.model.Task;

public record TaskResponseDto(
Long id,
String title,
Integer idx
Long taskId,
String taskTitle,
Integer taskIdx
) {
public static List<TaskResponseDto> of(List<Task> taskList) {
return taskList.stream().map(task -> new TaskResponseDto(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public void saveTask(final KeyResult keyResult, final TaskSingleCreateRequestDto
}

public void saveTask(final KeyResult keyResult, final TaskCreateRequestDto request) {
if (!request.title().isEmpty()) {
if (!request.taskTitle().isEmpty()) {
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 @@ -198,7 +198,7 @@ static void setUp() {
ObjectiveGroupByYearDto dto = response.groups().get(0);
assertThat(dto.year()).isEqualTo(2023);
assertThat(dto.objList().size()).isEqualTo(2);
assertThat(dto.objList().get(0).title()).isEqualTo("Objective 2");
assertThat(dto.objList().get(0).objTitle()).isEqualTo("Objective 2");
}

}

0 comments on commit 1b2aca6

Please sign in to comment.