-
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.
Browse files
Browse the repository at this point in the history
특정 프로젝트에 따른 피드백 리스트 조회 api #23
- Loading branch information
Showing
13 changed files
with
329 additions
and
45 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
27 changes: 27 additions & 0 deletions
27
src/main/java/com/sendback/domain/feedback/dto/response/FeedbackResponseDto.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,27 @@ | ||
package com.sendback.domain.feedback.dto.response; | ||
|
||
import com.sendback.domain.feedback.entity.Feedback; | ||
|
||
public record FeedbackResponseDto( | ||
Long feedbackId, | ||
String title, | ||
String rewardMessage, | ||
String startedAt, | ||
String endedAt, | ||
boolean isFinished, | ||
boolean isAuthor, | ||
boolean isSubmitted | ||
) { | ||
public static FeedbackResponseDto of(Feedback feedback, boolean isAuthor, boolean isSubmitted) { | ||
return new FeedbackResponseDto( | ||
feedback.getId(), | ||
feedback.getTitle(), | ||
feedback.getRewardMessage(), | ||
feedback.getStartedAt().toString(), | ||
feedback.getEndedAt().toString(), | ||
feedback.isFinished(), | ||
isAuthor, | ||
isSubmitted | ||
); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/sendback/domain/feedback/dto/response/GetFeedbacksResponse.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,7 @@ | ||
package com.sendback.domain.feedback.dto.response; | ||
|
||
import java.util.List; | ||
|
||
public record GetFeedbacksResponse( | ||
List<FeedbackResponseDto> feedbacks | ||
) {} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/sendback/domain/feedback/repository/FeedbackRepository.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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
package com.sendback.domain.feedback.repository; | ||
|
||
import com.sendback.domain.feedback.entity.Feedback; | ||
import com.sendback.domain.project.entity.Project; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface FeedbackRepository extends JpaRepository<Feedback, Long> { | ||
|
||
List<Feedback> findTop3ByProjectAndIsDeletedIsFalseOrderByIdDesc(Project project); | ||
} |
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
74 changes: 74 additions & 0 deletions
74
src/test/java/com/sendback/domain/feedback/repository/FeedbackRepositoryTest.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,74 @@ | ||
package com.sendback.domain.feedback.repository; | ||
|
||
import com.sendback.domain.feedback.entity.Feedback; | ||
import com.sendback.domain.feedback.persister.FeedbackTestPersister; | ||
import com.sendback.global.RepositoryTest; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class FeedbackRepositoryTest extends RepositoryTest { | ||
|
||
@Autowired | ||
FeedbackRepository feedbackRepository; | ||
|
||
@Nested | ||
@DisplayName("feedback 테이블에서 삭제되지 않은 가장 최신의 피드백 3개 이하를 조회하는 경우") | ||
class findTop3ByProjectAndIsDeletedIsFalseOrderByIdDesc { | ||
|
||
@Test | ||
@DisplayName("한 개인 경우 한 개만 반환한다.") | ||
public void success_oneFeedback() throws Exception { | ||
//given | ||
Feedback feedback = feedbackTestPersister.builder().save(); | ||
|
||
//when | ||
List<Feedback> response = feedbackRepository.findTop3ByProjectAndIsDeletedIsFalseOrderByIdDesc(feedback.getProject()); | ||
|
||
//then | ||
assertThat(response.size()).isEqualTo(1); | ||
|
||
} | ||
|
||
@Test | ||
@DisplayName("두 개인 경우 두 개만 반환한다.") | ||
public void success_twoFeedback() throws Exception { | ||
//given | ||
FeedbackTestPersister.FeedbackBuilder feedbackBuilder = feedbackTestPersister.builder(); | ||
Feedback feedback_A = feedbackBuilder.save(); | ||
feedbackBuilder.project(feedback_A.getProject()).save(); | ||
|
||
//when | ||
List<Feedback> response = feedbackRepository.findTop3ByProjectAndIsDeletedIsFalseOrderByIdDesc(feedback_A.getProject()); | ||
|
||
//then | ||
assertThat(response.size()).isEqualTo(2); | ||
|
||
} | ||
|
||
@Test | ||
@DisplayName("세 개 이상인 경우 최신 세 개만 반환한다.") | ||
public void success_threeFeedback() throws Exception { | ||
//given | ||
FeedbackTestPersister.FeedbackBuilder feedbackBuilder = feedbackTestPersister.builder(); | ||
Feedback feedback_A = feedbackBuilder.save(); | ||
Feedback feedback_third = feedbackBuilder.project(feedback_A.getProject()).save(); | ||
Feedback feedback_second = feedbackBuilder.project(feedback_A.getProject()).save(); | ||
Feedback feedback_first = feedbackBuilder.project(feedback_A.getProject()).save(); | ||
|
||
//when | ||
List<Feedback> response = feedbackRepository.findTop3ByProjectAndIsDeletedIsFalseOrderByIdDesc(feedback_A.getProject()); | ||
|
||
//then | ||
assertThat(response.size()).isEqualTo(3); | ||
assertThat(response.get(0)).usingRecursiveComparison().isEqualTo(feedback_first); | ||
assertThat(response.get(1)).usingRecursiveComparison().isEqualTo(feedback_second); | ||
assertThat(response.get(2)).usingRecursiveComparison().isEqualTo(feedback_third); | ||
} | ||
} | ||
} |
Oops, something went wrong.