Skip to content

Commit

Permalink
Feat: 댓글 수정, 삭제 기능추가
Browse files Browse the repository at this point in the history
마이페이지에서 수정, 삭제 가능
  • Loading branch information
cmsong111 committed May 22, 2024
1 parent cddd05b commit 5671dfe
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@ public interface FoodTruckMapper {
FoodTruckMenu toFoodTruckMenu(FoodTruckMenuRequest foodTruckMenuRequest);

FoodTruckReview toFoodTruckReview(FoodTruckReviewRequest foodTruckReviewRequest);

FoodTruckReviewRequest toFoodTruckReviewRequest(FoodTruckReview foodTruckReview);
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
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;
import org.springframework.web.bind.annotation.PathVariable;
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")
Expand Down Expand Up @@ -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,
Expand All @@ -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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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')"
}
}
20 changes: 20 additions & 0 deletions src/main/resources/templates/food_truck/review_edit_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="ko" layout:decorate="layout/default_layout" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org">
<th:block layout:fragment="content">

<div class="container mt-5">
<h1>리뷰 수정</h1>
<form th:action="@{'/food-truck/' + ${id} + '/review/' + ${reviewId} + '/edit'}" method="post" th:object="${review}">
<div class="form-group">
<label for="content">내용</label>
<textarea class="form-control" id="content" name="content" rows="3" th:text="${review.content}"></textarea>
</div>
<div class="form-group">
<label for="rating">평점</label>
<input type="number" class="form-control" id="rating" name="rating" th:value="${review.rating}">
</div>
<button type="submit" class="btn btn-primary">수정</button>
</form>
</div>
</th:block>
</html>
7 changes: 6 additions & 1 deletion src/main/resources/templates/user/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ <h2>내가 작성한 리뷰</h2>
<p th:text="'답글: ' + ${review.reply}"></p>
</div>
<p th:text="'평점: ' + ${review.rating}"></p>
<!-- 필요한 리뷰 정보들을 추가로 표시 -->
</div>
<div class="col-md-12">
<a class="btn btn-primary"
th:href="@{'/food-truck/' + ${review.id} + '/review/' + ${review.id} + '/edit'}">수정</a>
<a class="btn btn-danger"
th:href="@{'/food-truck/' + ${review.id} + '/review/' + ${review.id} + '/delete'}">삭제</a>
</div>
</div>
</div>
Expand Down

0 comments on commit 5671dfe

Please sign in to comment.