Skip to content
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

[LIME-52] 아이템 목록 조회에 취미 추가 #22

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public ResponseEntity<Void> deleteMyItem(
return ResponseEntity.ok().build();
}

@Operation(summary = "키워드로 아이템 이름 목록 조회", description = "키워드를 이용하여 아이템 이름 목록 조회 합니다")
@Operation(summary = "아이템 이름 목록 조회", description = "키워드를 이용하여 아이템 이름 목록 조회 합니다")
@GetMapping("/item-names")
public ResponseEntity<ItemGetNamesResponse> getItemNames(@RequestParam final String keyword) {
ItemGetNamesServiceResponse serviceResponse = itemService.getItemNamesByKeyword(keyword);
Expand All @@ -103,17 +103,19 @@ public ResponseEntity<ItemGetNamesResponse> getItemNames(@RequestParam final Str
return ResponseEntity.ok(response);
}

@Operation(summary = "아이템 검색 및 목록조회", description = "키워드를 이용하여 아이템 검색 및 목록조회 합니다.")
@Operation(summary = "아이템 목록조회", description = "키워드, 취미를 이용하여 아이템 목록조회 합니다.")
@GetMapping("/search")
public ResponseEntity<ItemGetByCursorResponse> getItemsByCursor(
@RequestParam final String keyword,
@ModelAttribute("request") @Valid final CursorRequest request,
@RequestParam(required = false) final String itemSortCondition
@RequestParam(required = false) final String itemSortCondition,
@RequestParam(required = false) final String hobbyName
) {
ItemGetByCursorServiceResponse serviceResponse = itemService.getItemsByCursor(
keyword,
request.toParameters(),
itemSortCondition
itemSortCondition,
hobbyName
);
ItemGetByCursorResponse response = ItemGetByCursorResponse.from(serviceResponse);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
public record ItemEnrollRequest(

@Schema(description = "취미", example = "농구")
String hobbyValue,
String hobbyName,

@Schema(description = "아이템 URL", example = "https://www.coupang.com/vp/products/5720604355?itemId=9567481661")
@NotNull(message = "아이템 URL을 입력하지 않았습니다.")
String itemUrl
) {

public ItemEnrollServiceRequest toEnrollItemServiceRequest() {
Hobby hobby = Hobby.from(hobbyValue);
Hobby hobby = Hobby.from(hobbyName);

return new ItemEnrollServiceRequest(hobby, itemUrl);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.programmers.lime.common.cursor.CursorPageParameters;
import com.programmers.lime.common.cursor.CursorSummary;
import com.programmers.lime.common.model.Hobby;
import com.programmers.lime.common.model.ItemRemovalList;
import com.programmers.lime.domains.item.api.dto.response.MemberItemFavoritesGetResponse;
import com.programmers.lime.domains.item.application.dto.MemberItemCreateServiceResponse;
Expand Down Expand Up @@ -136,14 +137,18 @@ public ItemGetNamesServiceResponse getItemNamesByKeyword(final String keyword) {
public ItemGetByCursorServiceResponse getItemsByCursor(
final String keyword,
final CursorPageParameters parameters,
final String itemSortCondition
final String itemSortCondition,
final String hobbyName
) {
Hobby hobby = Hobby.from(hobbyName);

ItemSortCondition sortCondition = ItemSortCondition.from(itemSortCondition);

CursorSummary<ItemCursorSummary> itemCursorSummaryCursorSummary = itemCursorReader.readByCursor(
keyword,
parameters,
sortCondition
sortCondition,
hobby
);

int itemTotalCount = itemReader.getItemTotalCountByKeyword(keyword);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.programmers.lime.common.cursor.CursorPageParameters;
import com.programmers.lime.common.cursor.CursorSummary;
import com.programmers.lime.common.cursor.CursorUtils;
import com.programmers.lime.common.model.Hobby;
import com.programmers.lime.domains.item.model.ItemCursorSummary;
import com.programmers.lime.domains.item.model.ItemSortCondition;
import com.programmers.lime.domains.item.repository.ItemRepository;
Expand All @@ -26,7 +27,8 @@ public class ItemCursorReader {
public CursorSummary<ItemCursorSummary> readByCursor(
final String keyword,
final CursorPageParameters parameters,
final ItemSortCondition itemSortCondition
final ItemSortCondition itemSortCondition,
final Hobby hobby
) {
String trimmedKeyword = keyword.trim();

Expand All @@ -44,7 +46,8 @@ public CursorSummary<ItemCursorSummary> readByCursor(
trimmedKeyword,
parameters.cursorId(),
pageSize,
itemSortCondition
itemSortCondition,
hobby
);

return CursorUtils.getCursorSummaries(itemCursorSummaries);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

public interface ItemRepositoryForCursor {
List<ItemCursorSummary> findAllByCursor(
String keyword,
String cursorId,
int pageSize,
final ItemSortCondition itemSortCondition
final String keyword,
final String cursorId,
final int pageSize,
final ItemSortCondition itemSortCondition,
final Hobby hobby
);

List<InventoryReviewItemSummary> findReviewedItemByCursor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public List<ItemCursorSummary> findAllByCursor(
final String keyword,
final String cursorId,
final int pageSize,
final ItemSortCondition itemSortCondition
final ItemSortCondition itemSortCondition,
final Hobby hobby
) {
return jpaQueryFactory
.select(
Expand All @@ -55,7 +56,8 @@ public List<ItemCursorSummary> findAllByCursor(
).from(item)
.where(
cursorIdCondition(cursorId),
item.name.contains(keyword)
item.name.contains(keyword),
hobbyCondition(hobby)
).orderBy(orderBySortCondition(itemSortCondition), item.id.desc())
.groupBy(item.id)
.leftJoin(review).on(item.id.eq(review.itemId))
Expand Down
Loading