Skip to content

Commit

Permalink
Merge pull request #20 from cmsong111/11-푸드트럭-기능-web
Browse files Browse the repository at this point in the history
후기 작성 기능
  • Loading branch information
cmsong111 authored May 27, 2024
2 parents 1dea200 + c47c06c commit 0f99e8e
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 20 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
Expand Up @@ -2,8 +2,10 @@

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.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
Expand All @@ -16,29 +18,78 @@

@Slf4j
@Controller
@RequestMapping("/food-truck/{foodTruckId}/review")
@RequestMapping("/food-truck/{id}/review")
@AllArgsConstructor
public class FoodTruckReviewController {

private final FoodTruckReviewService foodTruckReviewService;
private final FoodTruckService foodTruckService;

@GetMapping
public String getFoodTruckReview(
@PathVariable("foodTruckId") Long foodTruckId,
public String getFoodTruckReviewList(
@PathVariable(value = "id") Long id,
Model model
) {
model.addAttribute("reviewRequestForm", new FoodTruckReviewRequest("", 0, null));
return "food_truck/food-truck-review-form";
model.addAttribute("foodTruckDetailResponse", foodTruckService.getFoodTruck(id));
return "food_truck/manager/review_manage";
}

@PostMapping(consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
public String postFoodTruckReview(
@PathVariable("foodTruckId") Long foodTruckId,
FoodTruckReviewRequest reviewRequest,
Principal principal
@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";
}

@PreAuthorize("isAuthenticated()")
@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";
}

@PreAuthorize("isAuthenticated()")
@GetMapping("/{reviewId}/delete")
public String deleteFoodTruckReview(
@PathVariable(value = "id") Long id,
@PathVariable(value = "reviewId") Long reviewId
) {
foodTruckReviewService.deleteFoodTruckReview(reviewId);
return "redirect:/user";
}

foodTruckReviewService.saveFoodTruckReview(foodTruckId, reviewRequest, principal.getName());
return "redirect:/food-truck/{foodTruckId}";
@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 @@ -93,4 +93,13 @@ 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();
}

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')"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ <h1 class="text-center">내 푸드트럭</h1>
<button class="btn btn-primary"
th:onclick="|location.href='/food-truck/menu/' + ${foodTruck.id}|" type="button">메뉴 수정
</button>
<button class="btn btn-primary"
th:onclick="|location.href='/food-truck/' + ${foodTruck.id} + '/review'|" type="button">후기 보기
</button>
</div>
</div>
</div>
Expand Down
58 changes: 58 additions & 0 deletions src/main/resources/templates/food_truck/manager/review_manage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!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">
<script th:inline="javascript">

// 삭제 버튼 클릭 시, 확인 후 URL 이동
function deleteReview(foodTruckId, reviewId) {
if (confirm('정말 삭제하시겠습니까?')) {
location.href = '/food-truck/' + foodTruckId + '/review/' + reviewId + '/delete';
}
}


</script>


<h1 class="text-center">후기 관리</h1>

<div class="container mt-5">
<div class="row">
<div class="col-md-4 mb-4" th:each="review : ${foodTruckDetailResponse.reviews()}">
<div class="card">
<div class="card-body">
<h5 class="card-title" th:text="${review.content()}"></h5>
<p class="card-text">
<span>평점: </span>
<span th:text="${review.rating()}"></span>
<span></span>
</p>
<p class="card-text">
<span>작성자: </span>
<span th:text="${review.authorName()}"></span>
</p>
<p class="card-text">
<span>작성일: </span>
<span th:text="${review.createdAt()}"></span>
</p>
<p class="card-text">
<span>답장: </span>
<span th:text="${review.reply()}"></span>
</p>
<button class="btn btn-primary"
th:onclick="|location.href='/food-truck/' + ${foodTruckDetailResponse.id()} + '/review/' + ${review.id} + '/reply'|"
type="button">
답장
</button>

<button class="btn btn-danger" th:onclick="|deleteReview(${foodTruckDetailResponse.id()}, ${review.id})|"
type="button">
삭제
</button>
</div>
</div>
</div>
</div>
</div>
</th:block>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!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 class="text-center">후기 답변</h1>
<form method="post" th:action="|/food-truck/${foodTruckId}/review/${reviewId}/reply|">
<div class="form-group mt-3">
<label for="content">내용:</label>
<textarea class="form-control" id="content" name="content" required th:text="${review.getReply()}"></textarea>
</div>
<button class="btn btn-primary" type="submit">등록</button>
</form>
</div>
</th:block>
</html>
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 0f99e8e

Please sign in to comment.