diff --git a/src/main/java/com/codingwasabi/howtodo/web/calendar/service/CalendarServiceImpl.java b/src/main/java/com/codingwasabi/howtodo/web/calendar/service/CalendarServiceImpl.java index 44f8677..260e229 100644 --- a/src/main/java/com/codingwasabi/howtodo/web/calendar/service/CalendarServiceImpl.java +++ b/src/main/java/com/codingwasabi/howtodo/web/calendar/service/CalendarServiceImpl.java @@ -19,7 +19,7 @@ import lombok.RequiredArgsConstructor; @Service -@Transactional +@Transactional(readOnly = true) @RequiredArgsConstructor public class CalendarServiceImpl implements CalendarService { private final CalendarRepository calendarRepository; @@ -28,6 +28,7 @@ public class CalendarServiceImpl implements CalendarService { private final PlanMakingPolicy planMakingPolicy; @Override + @Transactional public Calendar create(Account account, int tendency, String nickname, int dailyQuota, List exams) { Calendar calendar = new Calendar(account); List dailyPlans = addDailyPlans(account, exams, calendar, dailyQuota); @@ -53,7 +54,6 @@ private List addDailyPlans(Account account, List exams, Calenda } @Override - @Transactional(readOnly = true) public Calendar find(Account account) { return calendarRepository.findByAccount(account) .orElseThrow(() -> new AccessDeniedException("no data")); diff --git a/src/main/java/com/codingwasabi/howtodo/web/comment/CommentController.java b/src/main/java/com/codingwasabi/howtodo/web/comment/CommentController.java index c7ac77e..1891525 100644 --- a/src/main/java/com/codingwasabi/howtodo/web/comment/CommentController.java +++ b/src/main/java/com/codingwasabi/howtodo/web/comment/CommentController.java @@ -1,22 +1,20 @@ package com.codingwasabi.howtodo.web.comment; import java.time.LocalDate; -import java.util.ArrayList; -import java.util.List; import java.util.stream.Collectors; -import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.codingwasabi.howtodo.security.oauth2.OAuth2UserAdapter; import com.codingwasabi.howtodo.security.resolver.LoginAccount; import com.codingwasabi.howtodo.web.account.entity.Account; import com.codingwasabi.howtodo.web.comment.dto.CreateCommentsRequest; -import com.codingwasabi.howtodo.web.comment.dto.CreateCommentsResponse; import com.codingwasabi.howtodo.web.comment.dto.GetCommentsByUserIdResponse; import com.codingwasabi.howtodo.web.comment.entity.Comment; @@ -25,31 +23,40 @@ @RestController @RequiredArgsConstructor public class CommentController { - + private final CommentService commentService; - - @GetMapping("/survey/{userId}/result/comments/{targetDate}") + + @GetMapping("/calendar/{accountId}/result/comments") public GetCommentsByUserIdResponse getCommentsByUserId(@PathVariable("accountId") Long accountId, - @PathVariable("targetDate") LocalDate targetDate) { - - return new GetCommentsByUserIdResponse(commentService.getCommentsByAccountIdAndDate(accountId, targetDate) + @RequestParam("date") @DateTimeFormat(pattern = "yyyy-MM-dd") + LocalDate date) { + + return new GetCommentsByUserIdResponse(commentService.getCommentsByAccountIdAndDate(accountId, date) .stream() .map(GetCommentsByUserIdResponse.CommentResponse::new) .collect(Collectors.toList())); } - - @PostMapping("/survey/{accountId}/result/comments/{targetDate}") - public void createComments(@LoginAccount Account account, - @PathVariable("accountId") Long accountId, - @PathVariable("targetDate") LocalDate targetDate, - @RequestBody CreateCommentsRequest createCommentsRequest) { + + @PostMapping("/calendar/{accountId}/result/comments/{targetDate}") + public ResponseEntity createComments(@LoginAccount Account account, + @PathVariable("accountId") Long accountId, + @PathVariable("targetDate") @DateTimeFormat(pattern = "yyyy-MM-dd") + LocalDate date, + @RequestBody CreateCommentsRequest createCommentsRequest) { + if (account.isAnonymous()) { + return ResponseEntity.badRequest() + .body("need authenticate before write comment"); + } + Comment comment = Comment.builder() .account(account) .body(createCommentsRequest.getBody()) .profileNumber(createCommentsRequest.getProfileImageNumber()) .build(); - - commentService.saveComment(accountId, targetDate, comment); + + commentService.saveComment(accountId, date, comment); + return ResponseEntity.ok() + .build(); } - + } diff --git a/src/main/java/com/codingwasabi/howtodo/web/comment/CommentService.java b/src/main/java/com/codingwasabi/howtodo/web/comment/CommentService.java index cfaca3c..71a0d45 100644 --- a/src/main/java/com/codingwasabi/howtodo/web/comment/CommentService.java +++ b/src/main/java/com/codingwasabi/howtodo/web/comment/CommentService.java @@ -23,8 +23,8 @@ public class CommentService { private final CommentRepository commentRepository; private final DailyPlanRepository dailyPlanRepository; - public List getCommentsByAccountIdAndDate(Long accountId, LocalDate localDate) { - return commentRepository.findCommentByAccountIdAndDate(accountId, localDate); + public List getCommentsByAccountIdAndDate(Long accountId, LocalDate date) { + return commentRepository.findCommentByAccountIdAndDate(accountId, date); } @Transactional diff --git a/src/main/java/com/codingwasabi/howtodo/web/comment/dto/GetCommentsByUserIdResponse.java b/src/main/java/com/codingwasabi/howtodo/web/comment/dto/GetCommentsByUserIdResponse.java index cf88fed..c1d843b 100644 --- a/src/main/java/com/codingwasabi/howtodo/web/comment/dto/GetCommentsByUserIdResponse.java +++ b/src/main/java/com/codingwasabi/howtodo/web/comment/dto/GetCommentsByUserIdResponse.java @@ -24,12 +24,12 @@ public class GetCommentsByUserIdResponse { @NoArgsConstructor @Builder public static class CommentResponse { - private int profileNumber; + private int profileImageNumber; private String nickname; private String body; public CommentResponse(Comment comment) { - this.profileNumber = comment.getProfileNumber(); + this.profileImageNumber = comment.getProfileNumber(); this.nickname = comment.getAccount().getNickname(); this.body = comment.getBody(); }