diff --git a/src/main/java/com/cmc/selfdevelopment/domain/improvement/controller/ImprovementController.java b/src/main/java/com/cmc/selfdevelopment/domain/improvement/controller/ImprovementController.java index e60dbd7..3e6cecb 100644 --- a/src/main/java/com/cmc/selfdevelopment/domain/improvement/controller/ImprovementController.java +++ b/src/main/java/com/cmc/selfdevelopment/domain/improvement/controller/ImprovementController.java @@ -1,9 +1,6 @@ package com.cmc.selfdevelopment.domain.improvement.controller; -import com.cmc.selfdevelopment.domain.improvement.dto.ChangeDoneDto; -import com.cmc.selfdevelopment.domain.improvement.dto.CreateTodoDto; -import com.cmc.selfdevelopment.domain.improvement.dto.ImprovementDto; -import com.cmc.selfdevelopment.domain.improvement.dto.TodoDto; +import com.cmc.selfdevelopment.domain.improvement.dto.*; import com.cmc.selfdevelopment.domain.improvement.service.ImprovementService; import com.cmc.selfdevelopment.domain.improvement.service.TodoService; import com.cmc.selfdevelopment.domain.user.UserTempService; @@ -26,7 +23,7 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/improvement-management") +@RequestMapping("/api/improvement-management") @Slf4j public class ImprovementController { @@ -83,4 +80,10 @@ public ResponseEntity>> showTodo(@RequestParam("date") return ResponseEntity.status(HttpStatus.CREATED).body(new ApiResponse(ResponseCode.TODO_LIST, todoService.findAllTodo(date))); } + @Operation(summary = "특정 월에 해당하는 퍼센트", description = "특정 월에 해당하는 모든 날짜의 완성도 퍼센티지를 리턴") + @GetMapping("/todo/month") + public ResponseEntity>> showTodoPercent(@RequestParam("date") Date date){ + + return ResponseEntity.status(HttpStatus.CREATED).body(new ApiResponse(ResponseCode.TODO_MONTH_PERCENT, todoService.findMonthPercent(date))); + } } diff --git a/src/main/java/com/cmc/selfdevelopment/domain/improvement/dto/TodoPercentDto.java b/src/main/java/com/cmc/selfdevelopment/domain/improvement/dto/TodoPercentDto.java new file mode 100644 index 0000000..64acfc1 --- /dev/null +++ b/src/main/java/com/cmc/selfdevelopment/domain/improvement/dto/TodoPercentDto.java @@ -0,0 +1,15 @@ +package com.cmc.selfdevelopment.domain.improvement.dto; + +import lombok.*; + +import java.sql.Date; + +@Getter +@Builder +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class TodoPercentDto { + private int percent; + private Date date; +} diff --git a/src/main/java/com/cmc/selfdevelopment/domain/improvement/service/TodoService.java b/src/main/java/com/cmc/selfdevelopment/domain/improvement/service/TodoService.java index 35a9df3..cb5cb97 100644 --- a/src/main/java/com/cmc/selfdevelopment/domain/improvement/service/TodoService.java +++ b/src/main/java/com/cmc/selfdevelopment/domain/improvement/service/TodoService.java @@ -1,9 +1,6 @@ package com.cmc.selfdevelopment.domain.improvement.service; -import com.cmc.selfdevelopment.domain.improvement.dto.ChangeDoneDto; -import com.cmc.selfdevelopment.domain.improvement.dto.CreateTodoDto; -import com.cmc.selfdevelopment.domain.improvement.dto.ImprovementDto; -import com.cmc.selfdevelopment.domain.improvement.dto.TodoDto; +import com.cmc.selfdevelopment.domain.improvement.dto.*; import com.cmc.selfdevelopment.domain.improvement.entity.Improvement; import com.cmc.selfdevelopment.domain.improvement.entity.Todo; import com.cmc.selfdevelopment.domain.improvement.repository.TodoRepository; @@ -15,6 +12,8 @@ import org.springframework.stereotype.Service; import java.sql.Date; +import java.time.Month; +import java.time.Year; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -86,4 +85,34 @@ public List findAllTodo(Date date) { .build()) .collect(Collectors.toList()); } + + public List findMonthPercent(Date date) { + Year year = Year.of(date.getYear()); + Month month = Month.of(date.getMonth() + 1); + int lastDay = month.length(year.isLeap()); + List todoPercentDtos = new ArrayList<>(); + System.out.println(year.getValue()); + System.out.println(month.getValue()); + System.out.println(lastDay); + for(int i = 1; i <= lastDay; i++){ + Date eachDate = new Date(year.getValue(), month.getValue() - 1, i); + List todos = findAllTodo(eachDate); + todoPercentDtos.add(TodoPercentDto.builder() + .percent(todos.size() == 0 ? 0 : countDone(todos)*100/todos.size()) + .date(eachDate) + .build()); + } + + return todoPercentDtos; + } + + public int countDone(List todoDtos){ + int cnt = 0; + for(TodoDto todoDto : todoDtos){ + if(todoDto.isDone()){ + cnt++; + } + } + return cnt; + } } diff --git a/src/main/java/com/cmc/selfdevelopment/global/common/api/ResponseCode.java b/src/main/java/com/cmc/selfdevelopment/global/common/api/ResponseCode.java index 0ed4b40..77f50fa 100644 --- a/src/main/java/com/cmc/selfdevelopment/global/common/api/ResponseCode.java +++ b/src/main/java/com/cmc/selfdevelopment/global/common/api/ResponseCode.java @@ -20,7 +20,8 @@ public enum ResponseCode { GET_DIARY(HttpStatus.OK, "회고 조회에 성공하였습니다."), DIARY_DELETED(HttpStatus.OK, "회고 삭제에 성공하였습니다." ), TODO_CHANGE(HttpStatus.OK, "isDone 변경에 성공했습니다."), - TODO_LIST(HttpStatus.OK, "해당 날짜의 Todo 리스트입니다") + TODO_LIST(HttpStatus.OK, "해당 날짜의 Todo 리스트입니다"), + TODO_MONTH_PERCENT(HttpStatus.OK, "특정 달의 TODO 성취도 입니다") ; private final HttpStatus status; private final String message;