-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat : 리뷰 작성 #45
Merged
The head ref may contain hidden characters: "24-be-\uB9AC\uBDF0-\uC791\uC131"
Merged
Feat : 리뷰 작성 #45
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/main/java/com/example/likelion12/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,32 @@ | ||
package com.example.likelion12.controller; | ||
import com.example.likelion12.common.response.BaseResponse; | ||
import com.example.likelion12.dto.PostReviewRequest; | ||
import com.example.likelion12.dto.PostReviewResponse; | ||
import com.example.likelion12.service.ReviewService; | ||
import com.example.likelion12.util.JwtProvider; | ||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@Slf4j | ||
@RestController | ||
@AllArgsConstructor | ||
@RequestMapping("/review") | ||
public class ReviewController { | ||
|
||
private final ReviewService reviewService; | ||
private final JwtProvider jwtProvider; | ||
|
||
@PostMapping | ||
public BaseResponse<PostReviewResponse> createReview(@RequestHeader("Authorization") String authorization , @RequestBody PostReviewRequest postReviewRequest) { | ||
|
||
Long memberId = jwtProvider.extractIdFromHeader(authorization); | ||
|
||
Long reviewId = reviewService.createReview(postReviewRequest.getFacilityId(), | ||
postReviewRequest.getRanking(), | ||
postReviewRequest.getComment(), | ||
memberId); | ||
PostReviewResponse response = new PostReviewResponse(reviewId); | ||
return new BaseResponse<>(response); | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
src/main/java/com/example/likelion12/dto/PostReviewRequest.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 com.example.likelion12.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class PostReviewRequest { | ||
private Long facilityId; | ||
private int ranking; | ||
private String comment; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/example/likelion12/dto/PostReviewResponse.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,10 @@ | ||
package com.example.likelion12.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class PostReviewResponse { | ||
private Long ReviewId; | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/example/likelion12/repository/ReviewRepository.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,20 @@ | ||
package com.example.likelion12.repository; | ||
|
||
import com.example.likelion12.domain.Review; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface ReviewRepository extends JpaRepository<Review, Long> { | ||
|
||
// 리뷰 작성 | ||
// 기본적으로 JpaRepository의 save() 메서드를 사용하여 작성할 수 있습니다. | ||
// 예: reviewRepository.save(review); | ||
|
||
// 리뷰 수정 | ||
// 기본적으로 JpaRepository의 save() 메서드를 사용하여 수정할 수 있습니다. | ||
// 예: reviewRepository.save(updatedReview); | ||
|
||
// 리뷰 삭제 | ||
void deleteById(Long reviewId); | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/example/likelion12/service/ReviewService.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 com.example.likelion12.service; | ||
|
||
import com.example.likelion12.common.exception.MemberException; | ||
import com.example.likelion12.domain.Facility; | ||
import com.example.likelion12.domain.Member; | ||
import com.example.likelion12.domain.Review; | ||
import com.example.likelion12.domain.base.BaseStatus; | ||
import com.example.likelion12.repository.FacilityRepository; | ||
import com.example.likelion12.repository.MemberRepository; | ||
import com.example.likelion12.repository.ReviewRepository; | ||
import jakarta.transaction.Transactional; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import static com.example.likelion12.common.response.status.BaseExceptionResponseStatus.CANNOT_FOUND_MEMBER; | ||
|
||
@Service | ||
public class ReviewService { | ||
|
||
@Autowired | ||
private ReviewRepository reviewRepository; | ||
|
||
@Autowired | ||
private FacilityRepository facilityRepository; | ||
|
||
@Autowired | ||
private MemberRepository memberRepository; | ||
|
||
@Transactional | ||
public Long createReview(Long facilityId, int ranking, String comment , Long memberId) { | ||
|
||
Member member = memberRepository.findByMemberIdAndStatus(memberId, BaseStatus.ACTIVE) | ||
.orElseThrow(()-> new MemberException(CANNOT_FOUND_MEMBER)); | ||
|
||
// facilityId로 facility 찾고 | ||
Facility facility = facilityRepository.findById(facilityId) | ||
.orElseThrow(() -> new IllegalArgumentException("Invalid facility ID")); | ||
|
||
//리뷰에 받아온 값들 넣고 | ||
Review review = new Review(); | ||
review.setReview(facility, ranking, comment, member); | ||
|
||
//레퍼지토리에 저장 | ||
Review savedReview = reviewRepository.save(review); | ||
|
||
return savedReview.getReviewId(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
헤더에 토큰 받는 부분 누락된 것 같습니다!