Skip to content

Commit

Permalink
chore (#3) : 시험별로 color 부여
Browse files Browse the repository at this point in the history
  • Loading branch information
daehwan2yo committed Apr 10, 2022
1 parent ff1a16d commit 2a2bda3
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.codingwasabi.howtodo.web.calendar.dto.CreateCalendarRequest;
import com.codingwasabi.howtodo.web.calendar.entity.Calendar;
import com.codingwasabi.howtodo.web.calendar.service.CalendarService;
import com.codingwasabi.howtodo.web.exam.ExamService;
import com.codingwasabi.howtodo.web.exam.entity.Exam;
import com.codingwasabi.howtodo.web.policy.tendency.TendencyPolicy;

Expand All @@ -33,13 +34,15 @@
public class CalendarController {
private final CalendarService calendarService;
private final AccountService accountService;
private final ExamService examService;
private final TendencyPolicy tendencyPolicy;

@PostMapping(value = "/calendar", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
public ResponseEntity<CalendarResponse> createCalendar(@LoginAccount Account account,
@RequestBody CreateCalendarRequest createCalendarRequest) {

List<Exam> exams = extractExams(account, createCalendarRequest);
examService.insertColor(exams);

int tendency = tendencyPolicy.setUp(createCalendarRequest.getAnswers(),
createCalendarRequest.getDailyQuota(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
@RestController
@RequiredArgsConstructor
public class ExamController {

private final ExamService examService;

@GetMapping("/my/exams")
Expand All @@ -39,20 +38,16 @@ public GetMyExamResponse getMyExam(@LoginAccount Account account) {
@PutMapping("/my/exams")
public void putMyExam(@LoginAccount Account account, @RequestBody PutMyExamRequest putMyExamRequest) {
List<Exam> exams = new ArrayList<>();
int index = 0;
for (PutMyExamRequest.ExamRequest subjectRequest : putMyExamRequest.getSubjects()) {
exams.add(Exam.builder()
.account(account)
.name(subjectRequest.getName())
.dueDateTime(subjectRequest.getDate())
.studyDegree(subjectRequest.getPrepareTime())
.color(++index)
.build());
}

examService.insertColor(exams);
examService.putExam(account, exams);

return;
}

}
13 changes: 10 additions & 3 deletions src/main/java/com/codingwasabi/howtodo/web/exam/ExamService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@
@Service
@RequiredArgsConstructor
public class ExamService {

private final ExamRepository examRepository;

public List<Exam> getMyExam(Account account) {
return examRepository.findByAccount(account);
}

public void putExam(Account account, List<Exam> exam) {
examRepository.deleteAll(examRepository.findByAccount(account));
examRepository.saveAll(exam);
}

public void insertColor(List<Exam> exams) {
int color = 0;
for (Exam exam : exams) {
exam.setColor(color++);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Entity
@Getter
Expand All @@ -30,15 +31,16 @@ public class Exam {
private String name;
private LocalDateTime dueDateTime;
private int studyDegree;

@Setter
private int color;

@Builder
private Exam(Account account, String name, LocalDateTime dueDateTime, int studyDegree, int color) {
private Exam(Account account, String name, LocalDateTime dueDateTime, int studyDegree) {
this.account = account;
this.name = name;
this.dueDateTime = dueDateTime;
this.studyDegree = studyDegree;
this.color = color;
}

public int getDDay(LocalDate today) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ void init() {
.account(account)
.dueDateTime(LocalDateTime.now())
.studyDegree(3)
.color(3)
.build();

// then
assertThat(exam.getName()).isEqualTo("과목");
assertThat(exam.getStudyDegree()).isEqualTo(3);
assertThat(exam.getColor()).isEqualTo(3);
}

@DisplayName("과목 d-day 구하기")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ void init() {
Account account = Account.Anonymous;
List<DailyPlan> dailyPlans = List.of(DailyPlan_생성(account), DailyPlan_생성(account));
willReturn(dailyPlans).given(planMakingPolicy)
.makeDailyPlans(any(), any(), any(), any());
.makeDailyPlans(any(), any(), any(), any(Integer.class));

// when
Calendar calendar = calendarService.create(account, 3, "daehwan", 10, List.of(Exam_생성("물리", 2022, 4, 9)));
// then
Expand All @@ -54,7 +55,7 @@ void init() {
Account account = Account_생성();
List<DailyPlan> dailyPlans = List.of(DailyPlan_생성(account), DailyPlan_생성(account));
willReturn(dailyPlans).given(planMakingPolicy)
.makeDailyPlans(any(), any(), any(), any());
.makeDailyPlans(any(), any(), any(), any(Integer.class));

// when
Calendar calendar = calendarService.create(account, 3, "daehwan", 10, List.of(Exam_생성("물리", 2022, 4, 9)));
Expand Down

0 comments on commit 2a2bda3

Please sign in to comment.