-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/#53 내 리뷰 리스트 불러오기 #55
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
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
146fbfe
rebase
yuna83 6bc6222
rebase
yuna83 ce0b702
rebase
yuna83 e8f9ce9
rebase
yuna83 e147e95
#53 test(ReviewControllerTest): 테스트 코드 추가
yuna83 415bd21
#53 refactor(ReviewService): 서비스 리팩토링
yuna83 b206e63
#53 refactor(ReviewCommand): dto 리팩토링
yuna83 41861f2
service fix
yuna83 cde1d50
rebase
yuna83 1ea453e
build fix
yuna83 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
This file contains hidden or 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 hidden or 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
22 changes: 19 additions & 3 deletions
22
src/main/java/com/example/api/review/ReviewRepository.java
This file contains hidden or 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 |
|---|---|---|
| @@ -1,18 +1,34 @@ | ||
| package com.example.api.review; | ||
|
|
||
| import com.example.api.domain.Review; | ||
| import java.util.List; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.query.Param; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Repository | ||
| public interface ReviewRepository extends JpaRepository<Review, Long> { | ||
|
|
||
| @Query("SELECT r FROM Review r JOIN FETCH r.contract WHERE r.contract.offerEmployment.business.employer.accountId = :employerId") | ||
| @Query("SELECT r FROM Review r " + | ||
| "JOIN FETCH r.contract c " + | ||
| "WHERE c.offerEmployment.business.businessId = :employerId") | ||
| List<Review> loadReviewsByEmployerId(@Param("employerId") Long employerId); | ||
|
|
||
| @Query("SELECT r FROM Review r WHERE (:reviewId IS NULL OR r.reviewId = :reviewId)") | ||
| @Query("SELECT r FROM Review r " + | ||
| "WHERE (:reviewId IS NULL OR r.reviewId = :reviewId)") | ||
| List<Review> findReviewsByDynamicQuery(@Param("reviewId") Long reviewId); | ||
|
|
||
| @Query("SELECT r FROM Review r " + | ||
| "JOIN FETCH r.writer b " + | ||
| "JOIN FETCH r.employee a " + | ||
| "JOIN FETCH r.contract c " + | ||
| "WHERE a.accountId = :accountId") | ||
| List<Review> findReviewsByAccountIdWithDetails(@Param("accountId") Long accountId); | ||
|
|
||
| List<Review> findReviewsByEmployee_AccountId(Long accountId); | ||
| } | ||
|
|
||
|
|
||
|
|
This file contains hidden or 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 hidden or 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 hidden or 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,7 @@ | ||
| package com.example.api.review.dto; | ||
|
|
||
| public record ReviewCommand( | ||
| Long accountId | ||
| ){} | ||
|
|
||
|
|
21 changes: 12 additions & 9 deletions
21
src/main/java/com/example/api/review/dto/ReviewResponse.java
This file contains hidden or 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 |
|---|---|---|
| @@ -1,25 +1,28 @@ | ||
| package com.example.api.review.dto; | ||
|
|
||
| import com.example.api.domain.Account; | ||
| import com.example.api.domain.Business; | ||
| import com.example.api.domain.Review; | ||
| import java.time.LocalDateTime; | ||
|
|
||
| public record ReviewResponse( | ||
| Long reviewId, | ||
| Business writer, | ||
| Account employee, | ||
| Long reviewId, //Id | ||
| String businessName, | ||
| Long businessId, | ||
| LocalDateTime contractStartTime, | ||
| LocalDateTime contractEndTime, | ||
| int reviewStarPoint, | ||
| String reviewContent | ||
|
|
||
| ) { | ||
| public static ReviewResponse from(Review review) { | ||
| public static ReviewResponse from(final Review review) { | ||
| return new ReviewResponse( | ||
| review.getReviewId(), | ||
| review.getWriter(), | ||
| review.getEmployee(), | ||
| review.getContract().getOfferEmployment().getBusiness().getBusinessName(), | ||
| review.getContract().getOfferEmployment().getBusiness().getBusinessId(), | ||
| review.getContract().getContractStartTime(), | ||
| review.getContract().getContractEndTime(), | ||
| review.getReviewStarPoint(), | ||
| review.getReviewContent() | ||
| ); | ||
| } | ||
| } | ||
|
|
||
|
|
This file contains hidden or 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
65 changes: 65 additions & 0 deletions
65
src/test/java/com/example/api/review/controller/ReviewControllerTest.java
This file contains hidden or 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,65 @@ | ||
| package com.example.api.review.controller; | ||
|
|
||
| import com.example.api.review.ReviewService; | ||
| import com.example.api.review.dto.ReviewCommand; | ||
| import com.example.api.review.dto.ReviewResponse; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.InjectMocks; | ||
| import org.mockito.Mock; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
| import org.springframework.test.web.servlet.MockMvc; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| import static org.mockito.Mockito.*; | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
|
||
| @WebMvcTest(ReviewController.class) | ||
| public class ReviewControllerTest { | ||
| @Autowired | ||
| private MockMvc mockMvc; | ||
|
|
||
| @Mock | ||
| private ReviewService reviewService; | ||
|
|
||
| @InjectMocks | ||
| private ReviewController reviewController; | ||
|
|
||
| private ReviewResponse reviewResponse1; | ||
| private ReviewResponse reviewResponse2; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| reviewResponse1 = new ReviewResponse( | ||
| "Business A", 101L, LocalDateTime.now(), LocalDateTime.now(), 5, "Great service!"); | ||
| reviewResponse2 = new ReviewResponse( | ||
| "Business B", 102L, LocalDateTime.now(), LocalDateTime.now(), 4, "Good experience."); | ||
| } | ||
|
|
||
| @Test | ||
| void testGetMyReviews() throws Exception { | ||
| when(reviewService.getReviews(any(ReviewCommand.class))) | ||
| .thenReturn(List.of(reviewResponse1, reviewResponse2)); | ||
| mockMvc.perform(get("/api/v1/info/my/reviews") | ||
| .param("accountId", "123")) | ||
| .andExpect(status().isOk()) | ||
| .andExpect(jsonPath("$.reviews").isArray()) | ||
| .andExpect(jsonPath("$.reviews[0].businessName").value("Business A")) | ||
| .andExpect(jsonPath("$.reviews[1].reviewContent").value("Good experience.")); | ||
| } | ||
|
|
||
| @Test | ||
| void testGetMyReviewsNoData() throws Exception { | ||
| when(reviewService.getReviews(any(ReviewCommand.class))) | ||
| .thenReturn(Collections.emptyList()); | ||
| mockMvc.perform(get("/api/v1/info/my/reviews") | ||
| .param("accountId", "123")) | ||
| .andExpect(status().isOk()) | ||
| .andExpect(jsonPath("$.reviews").isEmpty()); | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
src/test/java/com/example/api/review/service/ReviewServiceTest.java
This file contains hidden or 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,41 @@ | ||
| package com.example.api.review.service; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import com.example.api.global.BaseIntegrationTest; | ||
| import com.example.api.review.ReviewService; | ||
| import com.example.api.review.dto.ReviewCommand; | ||
| import com.example.api.review.dto.ReviewResponse; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @SpringBootTest | ||
| public class ReviewServiceTest extends BaseIntegrationTest { | ||
| @Autowired | ||
| private ReviewService reviewService; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| } | ||
|
|
||
| @Test | ||
| void testGetReviews() { | ||
| ReviewCommand reviewCommand = new ReviewCommand(1L); | ||
| List<ReviewResponse> reviews = reviewService.getReviews(reviewCommand); | ||
| assertThat(reviews).isNotEmpty(); | ||
| assertThat(reviews.get(0).businessName()).isEqualTo("Tech Solutions Inc."); | ||
| assertThat(reviews.get(0).reviewContent()).isEqualTo("Good work"); | ||
| } | ||
|
|
||
| @Test | ||
| void testGetReviewsWhenNoReviews() { | ||
| ReviewCommand reviewCommand = new ReviewCommand(999L); | ||
| List<ReviewResponse> reviews = reviewService.getReviews(reviewCommand); | ||
| assertThat(reviews).isEmpty(); | ||
| } | ||
| } | ||
|
|
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.
Uh oh!
There was an error while loading. Please reload this page.