Skip to content

Commit

Permalink
Merge pull request #24 from CMC-Hackathon-team5/feat/#23-monthTodoPer…
Browse files Browse the repository at this point in the history
…cent

Feat/#23 month todo percent
  • Loading branch information
kkyu0718 authored Jan 7, 2023
2 parents df88dbd + 8419c99 commit b41d15a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -26,7 +23,7 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/improvement-management")
@RequestMapping("/api/improvement-management")
@Slf4j
public class ImprovementController {

Expand Down Expand Up @@ -83,4 +80,10 @@ public ResponseEntity<ApiResponse<List<TodoDto>>> 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<ApiResponse<List<TodoPercentDto>>> showTodoPercent(@RequestParam("date") Date date){

return ResponseEntity.status(HttpStatus.CREATED).body(new ApiResponse(ResponseCode.TODO_MONTH_PERCENT, todoService.findMonthPercent(date)));
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -86,4 +85,34 @@ public List<TodoDto> findAllTodo(Date date) {
.build())
.collect(Collectors.toList());
}

public List<TodoPercentDto> findMonthPercent(Date date) {
Year year = Year.of(date.getYear());
Month month = Month.of(date.getMonth() + 1);
int lastDay = month.length(year.isLeap());
List<TodoPercentDto> 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<TodoDto> 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<TodoDto> todoDtos){
int cnt = 0;
for(TodoDto todoDto : todoDtos){
if(todoDto.isDone()){
cnt++;
}
}
return cnt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b41d15a

Please sign in to comment.