Skip to content

Commit

Permalink
feat : mentorPostCategory
Browse files Browse the repository at this point in the history
  • Loading branch information
sjmjys954646 committed Oct 26, 2023
1 parent ff93ade commit 35d01fd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
package com.example.demo.mentoring;public enum MentorPostCategoryEnum {
package com.example.demo.mentoring;

public enum MentorPostCategoryEnum {
NULL, TITLE, WRITER, INTEREST;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ public ResponseEntity<?> createMentorPost(@RequestBody @Valid MentorPostRequest.

@GetMapping("/mentorings/post")
public ResponseEntity<?> getMentorPost(
@RequestParam(value = "category", defaultValue = "") String category,
@RequestParam(value = "category", required = false) MentorPostCategoryEnum category,
@RequestParam(value = "search", defaultValue = "") String keyword,
@RequestParam(value = "page", defaultValue = "0") Integer page,
@AuthenticationPrincipal CustomUserDetails userDetails) {

if(category == null)
category = MentorPostCategoryEnum.NULL;

List<MentorPostResponse.MentorPostAllDTO> responseDTOs = mentorPostService.findAllMentorPost(category, keyword, page);
return ResponseEntity.ok(ApiUtils.success(responseDTOs));
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/example/demo/mentoring/MentorPostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,24 @@ public void createMentorPost(MentorPostRequest.CreateDTO createDTO, User writer)
/* 1. mentorPostList를 조회
2. 각 List당 writer별 writerInterests를 조회
3. MentorPostDTO 생성*/
public List<MentorPostResponse.MentorPostAllDTO> findAllMentorPost(String serachCategory, String keyword, int page) {
public List<MentorPostResponse.MentorPostAllDTO> findAllMentorPost(MentorPostCategoryEnum searchCategory, String keyword, int page) {
Pageable pageable = PageRequest.of(page,5);
Page<MentorPost> pageContent = null;

//검색별 pageContent 검색
if(serachCategory == "")
if(searchCategory == MentorPostCategoryEnum.NULL)
{
pageContent = mentorPostJPARepository.findAll(pageable);
}
else if(serachCategory == "title")
else if(searchCategory == MentorPostCategoryEnum.TITLE)
{
pageContent = mentorPostJPARepository.findAllByTitleKeyword("%" + keyword + "%", pageable);
}
else if(serachCategory == "writer")
else if(searchCategory == MentorPostCategoryEnum.WRITER)
{
pageContent = mentorPostJPARepository.findAllByWriterKeyword("%" + keyword + "%", pageable);
}
else if(serachCategory == "interest")
else if(searchCategory == MentorPostCategoryEnum.INTEREST)
{
pageContent = mentorPostJPARepository.findAllByInterestKeyword("%" + keyword + "%", pageable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ public void PatchDoneMentorPost() throws Exception{

@Test
void mentorPostServiceTest() throws Exception {
List<MentorPostResponse.MentorPostAllDTO> mentorPostFind = mentorPostService.findAllMentorPost("interest","test1",0);
List<MentorPostResponse.MentorPostAllDTO> mentorPostFind = mentorPostService.findAllMentorPost(MentorPostCategoryEnum.NULL,"",2);

String responseBody = om.writeValueAsString(mentorPostFind);

Expand Down

0 comments on commit 35d01fd

Please sign in to comment.