From cddd05ba6c12de897a17d671355bf3f7405687ea Mon Sep 17 00:00:00 2001 From: Namju Kim Date: Wed, 22 May 2024 01:20:48 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Feat:=20=EB=8C=93=EA=B8=80=20=EB=8B=B5?= =?UTF-8?q?=EA=B8=80=EC=9E=91=EC=84=B1=ED=95=98=EA=B8=B0=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FoodTruckReviewController.java | 46 ++++++++++++++- .../service/FoodTruckReviewService.java | 4 ++ .../manager/my_food_truck_list.html | 3 + .../food_truck/manager/review_manage.html | 58 +++++++++++++++++++ .../food_truck/manager/review_reply_form.html | 15 +++++ 5 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/templates/food_truck/manager/review_manage.html create mode 100644 src/main/resources/templates/food_truck/manager/review_reply_form.html diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckReviewController.java b/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckReviewController.java index 464d77a..cc53bd7 100644 --- a/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckReviewController.java +++ b/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckReviewController.java @@ -1,12 +1,54 @@ package ac.kr.deu.connect.luck.food_truck.controller; import ac.kr.deu.connect.luck.food_truck.service.FoodTruckReviewService; +import ac.kr.deu.connect.luck.food_truck.service.FoodTruckService; import lombok.AllArgsConstructor; -import org.springframework.web.bind.annotation.RestController; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +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.RequestMapping; -@RestController +@Slf4j +@Controller +@RequestMapping("/food-truck/{id}/review") @AllArgsConstructor public class FoodTruckReviewController { private final FoodTruckReviewService foodTruckReviewService; + private final FoodTruckService foodTruckService; + + @GetMapping + public String getFoodTruckReviewList( + @PathVariable(value = "id") Long id, + Model model + ) { + model.addAttribute("foodTruckDetailResponse", foodTruckService.getFoodTruck(id)); + return "food_truck/manager/review_manage"; + } + + @GetMapping("/{reviewId}/reply") + public String getFoodTruckReviewDetail( + @PathVariable(value = "id") Long id, + @PathVariable(value = "reviewId") Long reviewId, + Model model + ) { + log.info("reviewId: {}", foodTruckReviewService.getFoodTruckReview(reviewId).getContent()); + model.addAttribute("review", foodTruckReviewService.getFoodTruckReview(reviewId)); + model.addAttribute("foodTruckId", id); + model.addAttribute("reviewId", reviewId); + return "food_truck/manager/review_reply_form"; + } + + @PostMapping("/{reviewId}/reply") + public String replyFoodTruckReview( + @PathVariable(value = "id") Long id, + @PathVariable(value = "reviewId") Long reviewId, + String content + ) { + foodTruckReviewService.addReplyToReview(reviewId, content); + return "redirect:/food-truck/" + id + "/review"; + } } diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckReviewService.java b/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckReviewService.java index 983e0f2..381fc44 100644 --- a/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckReviewService.java +++ b/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckReviewService.java @@ -93,4 +93,8 @@ public FoodTruckReviewResponse addReplyToReview(Long reviewId, String content) { review.setReply(content); return foodTruckMapper.toFoodTruckReviewResponse(foodTruckReviewRepository.save(review)); } + + public FoodTruckReview getFoodTruckReview(Long reviewId) { + return foodTruckReviewRepository.findById(reviewId).get(); + } } diff --git a/src/main/resources/templates/food_truck/manager/my_food_truck_list.html b/src/main/resources/templates/food_truck/manager/my_food_truck_list.html index 57ca470..89f36af 100644 --- a/src/main/resources/templates/food_truck/manager/my_food_truck_list.html +++ b/src/main/resources/templates/food_truck/manager/my_food_truck_list.html @@ -37,6 +37,9 @@

내 푸드트럭

+ diff --git a/src/main/resources/templates/food_truck/manager/review_manage.html b/src/main/resources/templates/food_truck/manager/review_manage.html new file mode 100644 index 0000000..1d8ea4a --- /dev/null +++ b/src/main/resources/templates/food_truck/manager/review_manage.html @@ -0,0 +1,58 @@ + + + + + + +

후기 관리

+ +
+
+
+
+
+
+

+ 평점: + + +

+

+ 작성자: + +

+

+ 작성일: + +

+

+ 답장: + +

+ + + +
+
+
+
+
+
+ diff --git a/src/main/resources/templates/food_truck/manager/review_reply_form.html b/src/main/resources/templates/food_truck/manager/review_reply_form.html new file mode 100644 index 0000000..f8c45a0 --- /dev/null +++ b/src/main/resources/templates/food_truck/manager/review_reply_form.html @@ -0,0 +1,15 @@ + + + +
+

후기 답변

+
+
+ + +
+ +
+
+
+ From 5671dfeb394001231ec498904dfee4a1b7a38912 Mon Sep 17 00:00:00 2001 From: Namju Kim Date: Wed, 22 May 2024 15:44:43 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Feat:=20=EB=8C=93=EA=B8=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95,=20=EC=82=AD=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 마이페이지에서 수정, 삭제 가능 --- .../luck/food_truck/FoodTruckMapper.java | 2 + .../controller/FoodTruckReviewController.java | 39 +++++++++++++++++++ .../service/FoodTruckReviewService.java | 5 +++ .../luck/image/ImageRestController.java | 1 + .../connect/luck/image/ImageUrlResponse.java | 6 --- .../luck/image/dto/ImageUrlResponse.kt | 9 +++++ .../food_truck/review_edit_form.html | 20 ++++++++++ .../resources/templates/user/profile.html | 7 +++- 8 files changed, 82 insertions(+), 7 deletions(-) delete mode 100644 src/main/java/ac/kr/deu/connect/luck/image/ImageUrlResponse.java create mode 100644 src/main/java/ac/kr/deu/connect/luck/image/dto/ImageUrlResponse.kt create mode 100644 src/main/resources/templates/food_truck/review_edit_form.html diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/FoodTruckMapper.java b/src/main/java/ac/kr/deu/connect/luck/food_truck/FoodTruckMapper.java index 5089801..1299186 100644 --- a/src/main/java/ac/kr/deu/connect/luck/food_truck/FoodTruckMapper.java +++ b/src/main/java/ac/kr/deu/connect/luck/food_truck/FoodTruckMapper.java @@ -78,4 +78,6 @@ public interface FoodTruckMapper { FoodTruckMenu toFoodTruckMenu(FoodTruckMenuRequest foodTruckMenuRequest); FoodTruckReview toFoodTruckReview(FoodTruckReviewRequest foodTruckReviewRequest); + + FoodTruckReviewRequest toFoodTruckReviewRequest(FoodTruckReview foodTruckReview); } diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckReviewController.java b/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckReviewController.java index cc53bd7..7622aa6 100644 --- a/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckReviewController.java +++ b/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckReviewController.java @@ -1,9 +1,11 @@ package ac.kr.deu.connect.luck.food_truck.controller; +import ac.kr.deu.connect.luck.food_truck.dto.FoodTruckReviewRequest; import ac.kr.deu.connect.luck.food_truck.service.FoodTruckReviewService; import ac.kr.deu.connect.luck.food_truck.service.FoodTruckService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @@ -11,6 +13,8 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; +import java.security.Principal; + @Slf4j @Controller @RequestMapping("/food-truck/{id}/review") @@ -42,6 +46,7 @@ public String getFoodTruckReviewDetail( return "food_truck/manager/review_reply_form"; } + @PreAuthorize("isAuthenticated()") @PostMapping("/{reviewId}/reply") public String replyFoodTruckReview( @PathVariable(value = "id") Long id, @@ -51,4 +56,38 @@ public String replyFoodTruckReview( foodTruckReviewService.addReplyToReview(reviewId, content); return "redirect:/food-truck/" + id + "/review"; } + + @PreAuthorize("isAuthenticated()") + @GetMapping("/{reviewId}/delete") + public String deleteFoodTruckReview( + @PathVariable(value = "id") Long id, + @PathVariable(value = "reviewId") Long reviewId + ) { + foodTruckReviewService.deleteFoodTruckReview(reviewId); + return "redirect:/user"; + } + + @PreAuthorize("isAuthenticated()") + @GetMapping("/{reviewId}/edit") + public String editFoodTruckReview( + @PathVariable(value = "id") Long id, + @PathVariable(value = "reviewId") Long reviewId, + Model model + ) { + model.addAttribute("review", foodTruckReviewService.getFoodTruckReviewForRequest(reviewId)); + model.addAttribute("foodTruckId", id); + model.addAttribute("reviewId", reviewId); + return "food_truck/review_edit_form"; + } + + @PreAuthorize("isAuthenticated()") + @PostMapping("/{reviewId}/edit") + public String editFoodTruckReview( + @PathVariable(value = "id") Long id, + @PathVariable(value = "reviewId") Long reviewId, + FoodTruckReviewRequest foodTruckReview, Principal principal + ) { + foodTruckReviewService.saveFoodTruckReview(id, foodTruckReview, principal.getName(), reviewId); + return "redirect:/user"; + } } diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckReviewService.java b/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckReviewService.java index 381fc44..eb3465e 100644 --- a/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckReviewService.java +++ b/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckReviewService.java @@ -97,4 +97,9 @@ public FoodTruckReviewResponse addReplyToReview(Long reviewId, String content) { public FoodTruckReview getFoodTruckReview(Long reviewId) { return foodTruckReviewRepository.findById(reviewId).get(); } + + public FoodTruckReviewRequest getFoodTruckReviewForRequest(Long reviewId) { + FoodTruckReview review = foodTruckReviewRepository.findById(reviewId).get(); + return foodTruckMapper.toFoodTruckReviewRequest(review); + } } diff --git a/src/main/java/ac/kr/deu/connect/luck/image/ImageRestController.java b/src/main/java/ac/kr/deu/connect/luck/image/ImageRestController.java index a7ed262..e78b993 100644 --- a/src/main/java/ac/kr/deu/connect/luck/image/ImageRestController.java +++ b/src/main/java/ac/kr/deu/connect/luck/image/ImageRestController.java @@ -1,5 +1,6 @@ package ac.kr.deu.connect.luck.image; +import ac.kr.deu.connect.luck.image.dto.ImageUrlResponse; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.AllArgsConstructor; diff --git a/src/main/java/ac/kr/deu/connect/luck/image/ImageUrlResponse.java b/src/main/java/ac/kr/deu/connect/luck/image/ImageUrlResponse.java deleted file mode 100644 index 1a55991..0000000 --- a/src/main/java/ac/kr/deu/connect/luck/image/ImageUrlResponse.java +++ /dev/null @@ -1,6 +0,0 @@ -package ac.kr.deu.connect.luck.image; - -public record ImageUrlResponse( - String url -) { -} diff --git a/src/main/java/ac/kr/deu/connect/luck/image/dto/ImageUrlResponse.kt b/src/main/java/ac/kr/deu/connect/luck/image/dto/ImageUrlResponse.kt new file mode 100644 index 0000000..0498ccd --- /dev/null +++ b/src/main/java/ac/kr/deu/connect/luck/image/dto/ImageUrlResponse.kt @@ -0,0 +1,9 @@ +package ac.kr.deu.connect.luck.image.dto + +data class ImageUrlResponse( + val imageUrl: String +) { + override fun toString(): String { + return "ImageUrlResponse(imageUrl='$imageUrl')" + } +} diff --git a/src/main/resources/templates/food_truck/review_edit_form.html b/src/main/resources/templates/food_truck/review_edit_form.html new file mode 100644 index 0000000..e3640ed --- /dev/null +++ b/src/main/resources/templates/food_truck/review_edit_form.html @@ -0,0 +1,20 @@ + + + + +
+

리뷰 수정

+
+
+ + +
+
+ + +
+ +
+
+
+ diff --git a/src/main/resources/templates/user/profile.html b/src/main/resources/templates/user/profile.html index 433712c..630f0ae 100644 --- a/src/main/resources/templates/user/profile.html +++ b/src/main/resources/templates/user/profile.html @@ -26,7 +26,12 @@

내가 작성한 리뷰

- + +