Skip to content

Commit e048268

Browse files
authored
Merge pull request #316 from prgrms-web-devcourse-final-project/refactor/recruitment-post-method-rename
refactor: 모집글 검색 Method Rename
2 parents 1ffe461 + 8bb37c5 commit e048268

File tree

6 files changed

+41
-52
lines changed

6 files changed

+41
-52
lines changed

src/main/java/grep/neogulcoder/domain/recruitment/post/controller/RecruitmentPostController.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,23 @@ public class RecruitmentPostController implements RecruitmentPostSpecification {
2525
private final RecruitmentPostService recruitmentPostService;
2626

2727
@GetMapping
28-
public ResponseEntity<ApiResponse<RecruitmentPostPagingInfo>> getPagingInfo(@PageableDefault(size = 10) Pageable pageable,
29-
@RequestParam(value = "category", required = false) Category category,
30-
@RequestParam(value = "studyType", required = false) StudyType studyType,
31-
@RequestParam(value = "keyword", required = false) String keyword) {
32-
RecruitmentPostPagingInfo response = recruitmentPostService.getPagingInfo(
28+
public ResponseEntity<ApiResponse<RecruitmentPostPagingInfo>> search(@PageableDefault(size = 10) Pageable pageable,
29+
@RequestParam(value = "category", required = false) Category category,
30+
@RequestParam(value = "studyType", required = false) StudyType studyType,
31+
@RequestParam(value = "keyword", required = false) String keyword) {
32+
RecruitmentPostPagingInfo response = recruitmentPostService.search(
3333
pageable, category, studyType, keyword, null
3434
);
3535
return ResponseEntity.ok(ApiResponse.success(response));
3636
}
3737

3838
@GetMapping("/me")
39-
public ResponseEntity<ApiResponse<RecruitmentPostPagingInfo>> getMyPostPagingInfo(@PageableDefault(size = 10) Pageable pageable,
40-
@RequestParam(value = "category", required = false) Category category,
41-
@RequestParam(value = "studyType", required = false) StudyType studyType,
42-
@RequestParam(value = "keyword", required = false) String keyword,
43-
@AuthenticationPrincipal Principal userDetails) {
44-
RecruitmentPostPagingInfo response = recruitmentPostService.getPagingInfo(
39+
public ResponseEntity<ApiResponse<RecruitmentPostPagingInfo>> searchMyRecruitmentPost(@PageableDefault(size = 10) Pageable pageable,
40+
@RequestParam(value = "category", required = false) Category category,
41+
@RequestParam(value = "studyType", required = false) StudyType studyType,
42+
@RequestParam(value = "keyword", required = false) String keyword,
43+
@AuthenticationPrincipal Principal userDetails) {
44+
RecruitmentPostPagingInfo response = recruitmentPostService.search(
4545
pageable, category, studyType,
4646
keyword, userDetails.getUserId()
4747
);
@@ -56,23 +56,23 @@ public ResponseEntity<ApiResponse<RecruitmentPostInfo>> get(@PathVariable("recru
5656

5757
@PutMapping("/{recruitment-post-id}")
5858
public ResponseEntity<ApiResponse<Long>> update(@PathVariable("recruitment-post-id") long recruitmentPostId,
59-
@Valid @RequestBody RecruitmentPostUpdateRequest request,
60-
@AuthenticationPrincipal Principal userDetails) {
59+
@Valid @RequestBody RecruitmentPostUpdateRequest request,
60+
@AuthenticationPrincipal Principal userDetails) {
6161
long postId = recruitmentPostService.update(request.toServiceRequest(), recruitmentPostId, userDetails.getUserId());
6262
return ResponseEntity.ok(ApiResponse.success(postId));
6363
}
6464

6565
@DeleteMapping("/{recruitment-post-id}")
6666
public ResponseEntity<ApiResponse<Void>> delete(@PathVariable("recruitment-post-id") long recruitmentPostId,
67-
@AuthenticationPrincipal Principal userDetails) {
67+
@AuthenticationPrincipal Principal userDetails) {
6868
recruitmentPostService.delete(recruitmentPostId, userDetails.getUserId());
6969
return ResponseEntity.ok(ApiResponse.noContent());
7070
}
7171

7272
@PutMapping("/{recruitment-post-id}/status")
7373
public ResponseEntity<ApiResponse<Long>> changeStatus(@PathVariable("recruitment-post-id") long recruitmentPostId,
74-
@RequestBody RecruitmentPostStatusUpdateRequest request,
75-
@AuthenticationPrincipal Principal userDetails) {
74+
@RequestBody RecruitmentPostStatusUpdateRequest request,
75+
@AuthenticationPrincipal Principal userDetails) {
7676
long postId = recruitmentPostService.updateStatus(request.toServiceRequest(), recruitmentPostId, userDetails.getUserId());
7777
return ResponseEntity.ok(ApiResponse.success(postId));
7878
}

src/main/java/grep/neogulcoder/domain/recruitment/post/controller/RecruitmentPostSpecification.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ public interface RecruitmentPostSpecification {
8484
```
8585
"""
8686
)
87-
ResponseEntity<ApiResponse<RecruitmentPostPagingInfo>> getMyPostPagingInfo(Pageable pageable, Category category, StudyType studyType,
88-
String keyword, Principal userDetails);
87+
ResponseEntity<ApiResponse<RecruitmentPostPagingInfo>> searchMyRecruitmentPost(Pageable pageable, Category category, StudyType studyType,
88+
String keyword, Principal userDetails);
8989

9090
@Operation(
9191
summary = "모집글 페이징 조회",
@@ -143,5 +143,5 @@ ResponseEntity<ApiResponse<RecruitmentPostPagingInfo>> getMyPostPagingInfo(Pagea
143143
```
144144
"""
145145
)
146-
ResponseEntity<ApiResponse<RecruitmentPostPagingInfo>> getPagingInfo(Pageable pageable, Category category, StudyType studyType, String keyword);
146+
ResponseEntity<ApiResponse<RecruitmentPostPagingInfo>> search(Pageable pageable, Category category, StudyType studyType, String keyword);
147147
}

src/main/java/grep/neogulcoder/domain/recruitment/post/repository/RecruitmentPostQueryRepository.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public RecruitmentPostWithStudyInfo findPostWithStudyInfo(Long recruitmentPostId
6262
).fetchOne();
6363
}
6464

65-
public Page<RecruitmentPost> findAllByFilter(Pageable pageable, Category category, StudyType studyType, String keyword) {
65+
public Page<RecruitmentPost> search(Pageable pageable, Category category, StudyType studyType, String keyword) {
6666
List<RecruitmentPost> content = queryFactory.select(recruitmentPost)
6767
.from(recruitmentPost)
6868
.join(study).on(recruitmentPost.studyId.eq(study.id))
@@ -93,7 +93,7 @@ public Page<RecruitmentPost> findAllByFilter(Pageable pageable, Category categor
9393
return new PageImpl<>(content, pageable, count == null ? 0 : count);
9494
}
9595

96-
public Page<RecruitmentPost> findAllByFilter(Pageable pageable, Category category, StudyType studyType, String keyword, Long userId) {
96+
public Page<RecruitmentPost> search(Pageable pageable, Category category, StudyType studyType, String keyword, Long userId) {
9797
List<RecruitmentPost> content = queryFactory.select(recruitmentPost)
9898
.from(recruitmentPost)
9999
.join(study).on(recruitmentPost.studyId.eq(study.id))
@@ -127,17 +127,6 @@ public Page<RecruitmentPost> findAllByFilter(Pageable pageable, Category categor
127127
return new PageImpl<>(content, pageable, count == null ? 0 : count);
128128
}
129129

130-
public Optional<RecruitmentPost> findMyPostBy(long postId, long userId) {
131-
RecruitmentPost findRecruitmentPost = queryFactory.selectFrom(recruitmentPost)
132-
.where(
133-
recruitmentPost.activated.isTrue(),
134-
recruitmentPost.userId.eq(userId),
135-
recruitmentPost.id.eq(postId)
136-
)
137-
.fetchOne();
138-
return Optional.ofNullable(findRecruitmentPost);
139-
}
140-
141130
public Optional<RecruitmentPost> findPostBy(long postId) {
142131
RecruitmentPost findRecruitmentPost = queryFactory.selectFrom(recruitmentPost)
143132
.where(

src/main/java/grep/neogulcoder/domain/recruitment/post/service/RecruitmentPostService.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public RecruitmentPostInfo get(long recruitmentPostId) {
5656
return new RecruitmentPostInfo(postInfo, comments, applications.size());
5757
}
5858

59-
public RecruitmentPostPagingInfo getPagingInfo(Pageable pageable, Category category, StudyType studyType, String keyword, Long userId) {
60-
Page<RecruitmentPost> pages = findPostsFilteredByUser(pageable, category, studyType, keyword, userId);
59+
public RecruitmentPostPagingInfo search(Pageable pageable, Category category, StudyType studyType, String keyword, Long userId) {
60+
Page<RecruitmentPost> pages = searchRecruitmentPost(pageable, category, studyType, keyword, userId);
6161
List<RecruitmentPost> content = pages.getContent();
6262
List<Long> recruitmentPostIds = extractId(content);
6363

@@ -112,12 +112,12 @@ private List<CommentsWithWriterInfo> findCommentsWithWriterInfo(RecruitmentPost
112112
return applyWithdrawnUserNameChanges(comments, withdrawnUserComments);
113113
}
114114

115-
private Page<RecruitmentPost> findPostsFilteredByUser(Pageable pageable, Category category, StudyType studyType,
116-
String keyword, Long userId) {
115+
private Page<RecruitmentPost> searchRecruitmentPost(Pageable pageable, Category category, StudyType studyType,
116+
String keyword, Long userId) {
117117
if (userId == null) {
118-
return postQueryRepository.findAllByFilter(pageable, category, studyType, keyword);
118+
return postQueryRepository.search(pageable, category, studyType, keyword);
119119
}
120-
return postQueryRepository.findAllByFilter(pageable, category, studyType, keyword, userId);
120+
return postQueryRepository.search(pageable, category, studyType, keyword, userId);
121121
}
122122

123123
private List<CommentsWithWriterInfo> withdrawnUserChangeNameFrom(List<CommentsWithWriterInfo> comments) {

src/main/java/grep/neogulcoder/domain/study/controller/StudyController.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,38 +58,38 @@ public ResponseEntity<ApiResponse<List<StudyImageResponse>>> getStudyImages(@Aut
5858

5959
@GetMapping("/{studyId}/info")
6060
public ResponseEntity<ApiResponse<StudyInfoResponse>> getStudyInfo(@PathVariable("studyId") Long studyId,
61-
@AuthenticationPrincipal Principal userDetails) {
61+
@AuthenticationPrincipal Principal userDetails) {
6262
Long userId = userDetails.getUserId();
6363
return ResponseEntity.ok(ApiResponse.success(studyService.getStudyInfo(studyId, userId)));
6464
}
6565

6666
@GetMapping("/{studyId}/me")
6767
public ResponseEntity<ApiResponse<StudyMemberInfoResponse>> getMyStudyMemberInfo(@PathVariable("studyId") Long studyId,
68-
@AuthenticationPrincipal Principal userDetails) {
68+
@AuthenticationPrincipal Principal userDetails) {
6969
Long userId = userDetails.getUserId();
7070
return ResponseEntity.ok(ApiResponse.success(studyService.getMyStudyMemberInfo(studyId, userId)));
7171
}
7272

7373
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
7474
public ResponseEntity<ApiResponse<Long>> createStudy(@RequestPart("request") @Valid StudyCreateRequest request,
75-
@RequestPart(value = "image", required = false) MultipartFile image,
76-
@AuthenticationPrincipal Principal userDetails) throws IOException {
75+
@RequestPart(value = "image", required = false) MultipartFile image,
76+
@AuthenticationPrincipal Principal userDetails) throws IOException {
7777
Long id = studyService.createStudy(request, userDetails.getUserId(), image);
7878
return ResponseEntity.ok(ApiResponse.success(id));
7979
}
8080

8181
@PutMapping(value = "/{studyId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
8282
public ResponseEntity<ApiResponse<Void>> updateStudy(@PathVariable("studyId") Long studyId,
83-
@RequestPart @Valid StudyUpdateRequest request,
84-
@RequestPart(value = "image", required = false) MultipartFile image,
85-
@AuthenticationPrincipal Principal userDetails) throws IOException {
83+
@RequestPart @Valid StudyUpdateRequest request,
84+
@RequestPart(value = "image", required = false) MultipartFile image,
85+
@AuthenticationPrincipal Principal userDetails) throws IOException {
8686
studyService.updateStudy(studyId, request, userDetails.getUserId(), image);
8787
return ResponseEntity.ok(ApiResponse.noContent());
8888
}
8989

9090
@DeleteMapping("/{studyId}")
9191
public ResponseEntity<ApiResponse<Void>> deleteStudy(@PathVariable("studyId") Long studyId,
92-
@AuthenticationPrincipal Principal userDetails) {
92+
@AuthenticationPrincipal Principal userDetails) {
9393
studyService.deleteStudy(studyId, userDetails.getUserId());
9494
return ResponseEntity.ok(ApiResponse.noContent());
9595
}

src/test/java/grep/neogulcoder/domain/recruitment/post/service/RecruitmentPostServiceTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ void get_WhenWithdrawnUser_ThenNicknameUpdate() {
156156
}
157157

158158

159-
@DisplayName("모집글과 관련된 정보들을 페이징 조회 합니다.")
159+
@DisplayName("모집글을 검색 합니다.")
160160
@Test
161-
void getPagingInfo() {
161+
void search() {
162162
//given
163163
Study study1 = createStudy("자바 스터디", Category.IT, ONLINE);
164164
Study study2 = createStudy("클라이밍 동아리", Category.HOBBY, OFFLINE);
@@ -176,7 +176,7 @@ void getPagingInfo() {
176176
commentRepository.saveAll(comments);
177177

178178
//when
179-
RecruitmentPostPagingInfo result = recruitmentPostService.getPagingInfo(PageRequest.of(0, 2),
179+
RecruitmentPostPagingInfo result = recruitmentPostService.search(PageRequest.of(0, 2),
180180
Category.IT, ONLINE, null, null);
181181
System.out.println("result = " + result);
182182

@@ -188,9 +188,9 @@ void getPagingInfo() {
188188
);
189189
}
190190

191-
@DisplayName("내가 작성한 모집글과 관련된 정보들을 페이징 조회 합니다.")
191+
@DisplayName("내가 작성한 모집글을 검색 합니다.")
192192
@Test
193-
void getPagingInfo_WhenWrittenByUser() {
193+
void search_WhenWrittenByUser() {
194194
//given
195195
User myUser = createUser("myNickname");
196196
User user2 = createUser("회원");
@@ -213,7 +213,7 @@ void getPagingInfo_WhenWrittenByUser() {
213213
commentRepository.saveAll(comments);
214214

215215
//when
216-
RecruitmentPostPagingInfo result = recruitmentPostService.getPagingInfo(PageRequest.of(0, 2),
216+
RecruitmentPostPagingInfo result = recruitmentPostService.search(PageRequest.of(0, 2),
217217
Category.HOBBY, OFFLINE, null, myUser.getId());
218218
System.out.println("result = " + result);
219219

0 commit comments

Comments
 (0)