-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from kakao-tech-campus-2nd-step3/develop
Develop 정기병합
- Loading branch information
Showing
14 changed files
with
220 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/com/helpmeCookies/review/controller/ReviewController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.helpmeCookies.review.controller; | ||
|
||
import com.helpmeCookies.review.dto.ReviewRequest; | ||
import com.helpmeCookies.review.dto.ReviewResponse; | ||
import com.helpmeCookies.review.entity.Review; | ||
import com.helpmeCookies.review.service.ReviewService; | ||
import lombok.RequiredArgsConstructor; | ||
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.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/v1/reviews") | ||
@RequiredArgsConstructor | ||
public class ReviewController { | ||
|
||
private final ReviewService reviewService; | ||
|
||
//TODO 감상평 삭제 | ||
//TODO 해당 상품의 감상평 조회 | ||
//TODO 내 감상평 조회 | ||
|
||
@PostMapping("/{productId}") | ||
public ResponseEntity<Void> postReview(@RequestBody ReviewRequest request, @PathVariable Long productId) { | ||
reviewService.saveReview(request, productId); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@PutMapping("/{productId}/{reviewId}") | ||
public ResponseEntity<Void> editReview(@RequestBody ReviewRequest request, @PathVariable Long productId, @PathVariable Long reviewId) { | ||
reviewService.editReview(request, productId, reviewId); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@GetMapping("/{reviewId}") | ||
public ResponseEntity<ReviewResponse> getReview(@PathVariable Long reviewId) { | ||
Review response = reviewService.getReview(reviewId); | ||
return ResponseEntity.ok(ReviewResponse.fromEntity(response)); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/helpmeCookies/review/dto/ReviewRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.helpmeCookies.review.dto; | ||
|
||
import com.helpmeCookies.product.entity.Product; | ||
import com.helpmeCookies.review.entity.Review; | ||
import com.helpmeCookies.user.entity.User; | ||
|
||
public record ReviewRequest(Long writerId, String content) { | ||
public Review toEntity(User writer, Product product) { | ||
return Review.builder() | ||
.content(content) | ||
.writer(writer) | ||
.product(product) | ||
.build(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/helpmeCookies/review/dto/ReviewResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.helpmeCookies.review.dto; | ||
|
||
import com.helpmeCookies.product.entity.Product; | ||
import com.helpmeCookies.review.entity.Review; | ||
import com.helpmeCookies.user.entity.User; | ||
|
||
public record ReviewResponse(Long id, String content,User writer, Product product) { | ||
public static ReviewResponse fromEntity(Review review) { | ||
return new ReviewResponse(review.getId(), review.getContent(),review.getWriter(), review.getProduct()); | ||
} | ||
} |
Oops, something went wrong.