Skip to content

Commit

Permalink
chore (#3) : 시험 수정시 캘린더가 새롭게 저장되도록 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
daehwan2yo committed Apr 10, 2022
1 parent 2a2bda3 commit 7bc24d5
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@RequiredArgsConstructor
public class CalendarServiceImpl implements CalendarService {
private final CalendarRepository calendarRepository;
private final ExamRepository subjectRepository;
private final ExamRepository examRepository;
private final DailyPlanRepository dailyPlanRepository;
private final PlanMakingPolicy planMakingPolicy;

Expand All @@ -39,7 +39,7 @@ public Calendar create(Account account, int tendency, String nickname, int daily
account.setNickname(nickname);
account.setTendency(tendency);
dailyPlanRepository.saveAll(dailyPlans);
subjectRepository.saveAll(exams);
examRepository.saveAll(exams);
calendarRepository.save(calendar);
return calendar;
}
Expand Down
24 changes: 13 additions & 11 deletions src/main/java/com/codingwasabi/howtodo/web/exam/ExamController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static com.codingwasabi.howtodo.web.exam.dto.GetMyExamResponse.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -14,9 +13,9 @@

import com.codingwasabi.howtodo.security.resolver.LoginAccount;
import com.codingwasabi.howtodo.web.account.entity.Account;
import com.codingwasabi.howtodo.web.calendar.service.CalendarService;
import com.codingwasabi.howtodo.web.exam.dto.GetMyExamResponse;
import com.codingwasabi.howtodo.web.exam.dto.PutMyExamRequest;
import com.codingwasabi.howtodo.web.exam.dto.PutMyExamResponse;
import com.codingwasabi.howtodo.web.exam.entity.Exam;

import lombok.RequiredArgsConstructor;
Expand All @@ -25,29 +24,32 @@
@RequiredArgsConstructor
public class ExamController {
private final ExamService examService;

private final CalendarService calendarService;

@GetMapping("/my/exams")
public GetMyExamResponse getMyExam(@LoginAccount Account account) {

return new GetMyExamResponse(examService.getMyExam(account)
.stream()
.map(ExamResponse::new)
.collect(Collectors.toList()));
}

@PutMapping("/my/exams")
public void putMyExam(@LoginAccount Account account, @RequestBody PutMyExamRequest putMyExamRequest) {
List<Exam> exams = new ArrayList<>();
for (PutMyExamRequest.ExamRequest subjectRequest : putMyExamRequest.getSubjects()) {
examService.remove(account);

for (PutMyExamRequest.ExamRequest examRequest : putMyExamRequest.getExams()) {
exams.add(Exam.builder()
.account(account)
.name(subjectRequest.getName())
.dueDateTime(subjectRequest.getDate())
.studyDegree(subjectRequest.getPrepareTime())
.name(examRequest.getName())
.dueDateTime(examRequest.getDate())
.studyDegree(examRequest.getPrepareTime())
.build());
}
examService.insertColor(exams);
examService.putExam(account, exams);
calendarService.create(account, account.getTendency(), account.getNickname(), account.getDailyQuota(), exams);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
public interface ExamRepository extends JpaRepository<Exam, Long> {

List<Exam> findByAccount(Account account);

void deleteAllByAccount(Account account);
}
10 changes: 6 additions & 4 deletions src/main/java/com/codingwasabi/howtodo/web/exam/ExamService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@
@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 putExam(Account account, List<Exam> exams) {
examRepository.saveAll(exams);
}

public void insertColor(List<Exam> exams) {
Expand All @@ -32,4 +30,8 @@ public void insertColor(List<Exam> exams) {
exam.setColor(color++);
}
}

public void remove(Account account) {
examRepository.deleteAllByAccount(account);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@NoArgsConstructor
public class GetMyExamResponse {

List<ExamResponse> subjects;
List<ExamResponse> exams;

@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@NoArgsConstructor
public class PutMyExamRequest {

List<ExamRequest> subjects;
List<ExamRequest> exams;

@Getter
@Setter
Expand All @@ -26,7 +26,7 @@ public class PutMyExamRequest {
public static class ExamRequest {
private String name;

@JsonFormat(pattern = "yyyy/MM/dd kk:mm")
@JsonFormat(pattern = "yyyy/MM/dd hh:mm")
private LocalDateTime date;

private int prepareTime;
Expand Down

0 comments on commit 7bc24d5

Please sign in to comment.