Skip to content

Commit 6d47661

Browse files
authored
Merge pull request #264 from UMC-Closit/feature/#254-tag-search-sort
feat: 해시태그, 아이템 태그 검색 결과 정렬 기능 구현
2 parents c4880c1 + 2383ff7 commit 6d47661

4 files changed

Lines changed: 40 additions & 18 deletions

File tree

src/main/java/UMC_7th/Closit/domain/post/controller/PostController.java

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,31 +120,53 @@ public ApiResponse<PostResponseDTO.PostPreviewListDTO> getVisiblePostList(
120120
}
121121

122122

123-
@Operation(summary = "해시태그 기반 게시글 검색")
123+
@Operation(summary = "해시태그 기반 게시글 검색",
124+
description = """
125+
## 해시태그 기반 게시글 검색
126+
특정 해시태그가 포함된 게시글 목록을 페이징하여 조회합니다.
127+
128+
### Request Parameters
129+
- hashtag (선택): 검색할 해시태그 (예: ootd)
130+
- page (기본값: 0): 조회할 페이지 번호 (0부터 시작)
131+
- size (기본값: 10): 페이지당 항목 수
132+
- sorting (필수): 정렬 기준 (LATEST: 최신순, VIEW: 조회수순)
133+
""")
124134
@GetMapping("/hashtag")
125135
public ApiResponse<PostResponseDTO.PostPreviewListDTO> getPostListByHashtag(
126136
@RequestParam(name = "hashtag", required = false) String hashtag,
127137
@RequestParam(defaultValue = "0") int page,
128-
@RequestParam(defaultValue = "10") int size) {
138+
@RequestParam(defaultValue = "10") int size,
139+
@RequestParam(name ="sorting") PostSorting sorting) {
129140

130-
Pageable pageable = PageRequest.of(page, size);
141+
Pageable pageable = PageRequest.of(page, size, sorting.getSort());
131142
Slice<PostResponseDTO.PostPreviewDTO> posts = postQueryService.getPostListByHashtag(hashtag, pageable);
132143

133144
return ApiResponse.onSuccess(PostConverter.toPostPreviewListDTO(posts));
134145
}
135146

136-
@Operation(summary = "아이템 태그 기반 게시글 검색")
137-
@GetMapping("/itemtag")
138-
public ApiResponse<PostResponseDTO.PostPreviewListDTO> getPostListByItemTag(
139-
@RequestParam(name = "itemtag", required = false) String itemTag,
140-
@RequestParam(defaultValue = "0") int page,
141-
@RequestParam(defaultValue = "10") int size) {
142-
143-
Pageable pageable = PageRequest.of(page, size);
144-
Slice<PostResponseDTO.PostPreviewDTO> posts = postQueryService.getPostListByItemTag(itemTag, pageable);
145-
146-
return ApiResponse.onSuccess(PostConverter.toPostPreviewListDTO(posts));
147-
}
147+
// @Operation(summary = "아이템 태그 기반 게시글 검색",
148+
// description = """
149+
// ## 아이템 태그 기반 게시글 검색
150+
// 특정 아이템 태그가 포함된 게시글 목록을 페이징하여 조회합니다.
151+
//
152+
// ### Request Parameters
153+
// - itemtag (선택): 검색할 아이템 태그 (예: 청바지, 후드티 등)
154+
// - page (기본값: 0): 조회할 페이지 번호 (0부터 시작)
155+
// - size (기본값: 10): 페이지당 항목 수
156+
// - sorting (필수): 정렬 기준 (LATEST: 최신순, VIEW: 조회수순)
157+
// """)
158+
// @GetMapping("/itemtag")
159+
// public ApiResponse<PostResponseDTO.PostPreviewListDTO> getPostListByItemTag(
160+
// @RequestParam(name = "itemtag", required = false) String itemTag,
161+
// @RequestParam(defaultValue = "0") int page,
162+
// @RequestParam(defaultValue = "10") int size,
163+
// @RequestParam(name ="sorting") PostSorting sorting) {
164+
//
165+
// Pageable pageable = PageRequest.of(page, size, sorting.getSort());
166+
// Slice<PostResponseDTO.PostPreviewDTO> posts = postQueryService.getPostListByItemTag(itemTag, pageable);
167+
//
168+
// return ApiResponse.onSuccess(PostConverter.toPostPreviewListDTO(posts));
169+
// }
148170

149171
@Operation(summary = "게시글 수정")
150172
@PutMapping("/{post_id}")

src/main/java/UMC_7th/Closit/domain/post/entity/PostSorting.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,3 @@ public enum PostSorting {
1414
this.sort = sort;
1515
}
1616
}
17-

src/main/java/UMC_7th/Closit/domain/post/repository/PostRepository.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ public interface PostRepository extends JpaRepository<Post, Long> {
2424
@Query("SELECT p FROM Post p JOIN p.postHashtagList pht WHERE p.user IN :users AND pht.hashtag.id = :hashtagId ORDER BY p.createdAt DESC")
2525
Slice<Post> findByUsersAndHashtagId(List<User> users, Long hashtagId, Pageable pageable);
2626

27-
@Query("SELECT p FROM Post p JOIN p.postHashtagList pht WHERE pht.hashtag.id = :hashtagId ORDER BY p.createdAt DESC")
27+
@Query("SELECT p FROM Post p JOIN p.postHashtagList pht WHERE pht.hashtag.id = :hashtagId")
2828
Slice<Post> findByHashtagId(Long hashtagId, Pageable pageable);
2929

30-
@Query("SELECT p FROM Post p JOIN p.postItemTagList pit WHERE pit.itemTag.id = :itemTagId ORDER BY p.createdAt DESC")
30+
@Query("SELECT p FROM Post p JOIN p.postItemTagList pit WHERE pit.itemTag.id = :itemTagId")
3131
Slice<Post> findByItemTagId(@Param("itemTagId") Long itemTagId, Pageable pageable);
3232

3333
Slice<Post> findAllByOrderByCreatedAtDesc(Pageable pageable);

src/main/java/UMC_7th/Closit/domain/user/entity/User.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public class User extends BaseEntity {
6666
private LocalDateTime withdrawalRequestedAt;
6767

6868
@Column(name = "is_withdrawn", nullable = false)
69+
@Builder.Default
6970
private Boolean isWithdrawn = false;
7071

7172
@Column(nullable = false)

0 commit comments

Comments
 (0)