-
Notifications
You must be signed in to change notification settings - Fork 1
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 #19 from MARKETFUBY/feat/help
[차소연] 도움돼요 생성/취소 구현
- Loading branch information
Showing
5 changed files
with
110 additions
and
0 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
28 changes: 28 additions & 0 deletions
28
src/main/java/MARKETFUBY/ReviewHelp/controller/ReviewHelpController.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,28 @@ | ||
package MARKETFUBY.ReviewHelp.controller; | ||
|
||
import MARKETFUBY.ReviewHelp.dto.ReviewHelpRequestDto; | ||
import MARKETFUBY.ReviewHelp.service.ReviewHelpService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/goods/reviews/{reviewId}/helps") | ||
public class ReviewHelpController { | ||
private final ReviewHelpService reviewHelpService; | ||
|
||
@PostMapping | ||
@ResponseStatus(value = HttpStatus.CREATED) | ||
public String createReviewHelp(@PathVariable Long reviewId, @RequestBody ReviewHelpRequestDto reviewHelpRequestDto){ | ||
Long memberId = reviewHelpRequestDto.getMemberId(); | ||
if(memberId != null){ | ||
reviewHelpService.createReviewHelp(reviewId, memberId); | ||
return "도움돼요가 반영되었습니다."; | ||
} | ||
else{ | ||
return "로그인이 필요한 서비스입니다."; | ||
} | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/MARKETFUBY/ReviewHelp/dto/ReviewHelpRequestDto.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 MARKETFUBY.ReviewHelp.dto; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class ReviewHelpRequestDto { | ||
private Long memberId; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/MARKETFUBY/ReviewHelp/repository/ReviewHelpRepository.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,12 @@ | ||
package MARKETFUBY.ReviewHelp.repository; | ||
|
||
import MARKETFUBY.Member.domain.Member; | ||
import MARKETFUBY.Review.domain.Review; | ||
import MARKETFUBY.ReviewHelp.domain.ReviewHelp; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface ReviewHelpRepository extends JpaRepository<ReviewHelp, Long> { | ||
boolean existsByMemberAndReview(Member member, Review review); | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/MARKETFUBY/ReviewHelp/service/ReviewHelpService.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,48 @@ | ||
package MARKETFUBY.ReviewHelp.service; | ||
|
||
import MARKETFUBY.Member.domain.Member; | ||
import MARKETFUBY.Member.service.MemberService; | ||
import MARKETFUBY.Review.domain.Review; | ||
import MARKETFUBY.Review.service.ReviewService; | ||
import MARKETFUBY.ReviewHelp.domain.ReviewHelp; | ||
import MARKETFUBY.ReviewHelp.repository.ReviewHelpRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Lazy; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Slf4j | ||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class ReviewHelpService { | ||
private final MemberService memberService; | ||
private final ReviewHelpRepository reviewHelpRepository; | ||
|
||
@Lazy | ||
@Autowired | ||
private ReviewService reviewService; | ||
|
||
public void createReviewHelp(Long reviewId, Long memberId){ | ||
Review review = reviewService.findReviewById(reviewId); | ||
Member member = memberService.findMemberById(memberId); | ||
|
||
if(isExistsByMemberAndReview(member, review)){ | ||
throw new RuntimeException("이미 도움돼요가 반영된 리뷰입니다."); | ||
} | ||
|
||
ReviewHelp reviewHelp = ReviewHelp.builder() | ||
.review(review) | ||
.member(member) | ||
.build(); | ||
|
||
reviewHelpRepository.save(reviewHelp); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public boolean isExistsByMemberAndReview(Member member, Review review){ | ||
return reviewHelpRepository.existsByMemberAndReview(member, review); | ||
} | ||
} |