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-33] 아이템 폴더 목록 조회 추가 및 기존 기능 수정 #6

Merged
merged 17 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
fbd51c8
feat: 멤버 아이템 폴더 커서 조회 기능 추가
Curry4182 Jan 15, 2024
86c3aa6
test: 아이템 빌더 폴더 아이디 추가
Curry4182 Jan 15, 2024
1483acf
test: 아이템 관련 도메인 테스트 할 경우 폴더 아이디 추가
Curry4182 Jan 15, 2024
7c1b9e3
feat: 멤버 아이템 폴더 도메인 추가
Curry4182 Jan 15, 2024
b2a3de8
feat: 도메인 모듈에 멤버 아이템 폴더 조회 기능 추가
Curry4182 Jan 15, 2024
70c0043
feat: 아이템 엔티티에 폴더 id 추가
Curry4182 Jan 15, 2024
67641db
feat: 아이템 엔티티에 폴더 id 추가로 인한 기존 api 수정
Curry4182 Jan 15, 2024
8881d58
feat: 아이템 엔티티에 폴더 id 추가로 인한 기존 api 수정
Curry4182 Jan 15, 2024
2dff796
test: hobby 변경으로 인한 기존 테스트 변경
Curry4182 Jan 15, 2024
90e8831
remove: 아이템 등록할 경우 나의 아이템 추가 기능 삭제
Curry4182 Jan 16, 2024
e2c7d6e
feat: folder id를 기존 Item 엔티티에서 MemberItem으로 변경
Curry4182 Jan 16, 2024
ce39907
remove: 아이템 관련 기능에서 folder id 가 있는 기능 삭제
Curry4182 Jan 16, 2024
fcf30c4
feat: 멤버 아이템과 관련된 로직에 folder id 추가
Curry4182 Jan 16, 2024
1edb16f
fixture: 멤버 아이템 폴더 추가 테스트를 위한 fixture 추가
Curry4182 Jan 16, 2024
19b8114
test: 멤버 아이템 폴더 id 변경으로 인한 테스트 수정
Curry4182 Jan 16, 2024
0efbed5
refactor: 작성하지 않아도 되는 sql 쿼리 삭제
Curry4182 Jan 17, 2024
1d29d62
docs: 스웨거 상세 설명 수정
Curry4182 Jan 17, 2024
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 @@ -21,13 +21,15 @@
import com.programmers.lime.domains.item.api.dto.response.ItemGetNamesResponse;
import com.programmers.lime.domains.item.api.dto.response.ItemGetRankingResponse;
import com.programmers.lime.domains.item.api.dto.response.ItemGetResponse;
import com.programmers.lime.domains.item.api.dto.response.MemberItemFolderGetByCursorResponse;
import com.programmers.lime.domains.item.api.dto.response.MemberItemGetByCursorResponse;
import com.programmers.lime.domains.item.application.ItemEnrollService;
import com.programmers.lime.domains.item.application.ItemService;
import com.programmers.lime.domains.item.application.dto.ItemAddServiceResponse;
import com.programmers.lime.domains.item.application.dto.ItemGetByCursorServiceResponse;
import com.programmers.lime.domains.item.application.dto.ItemGetNamesServiceResponse;
import com.programmers.lime.domains.item.application.dto.ItemGetServiceResponse;
import com.programmers.lime.domains.item.application.dto.MemberItemFolderGetServiceResponse;
import com.programmers.lime.domains.item.application.dto.MemberItemGetServiceResponse;
import com.programmers.lime.global.cursor.CursorRequest;

Expand Down Expand Up @@ -107,15 +109,35 @@ public ResponseEntity<ItemGetByCursorResponse> getItemsByCursor(
return ResponseEntity.ok(response);
}

@Operation(summary = "나의 아이템 폴더 조회", description = "나의 아이템 폴더 목록을 조회 합니다.")
@GetMapping("/myitems/folders")
public ResponseEntity<MemberItemFolderGetByCursorResponse> getMemberItemFoldersByCursor(
@RequestParam(required = false) final String hobbyName,
@ModelAttribute("request") @Valid final CursorRequest request
) {
Hobby hobby = Hobby.from(hobbyName);
MemberItemFolderGetServiceResponse memberItemFolderByCursor = itemService.getMemberItemFolderByCursor(
hobby,
request.toParameters()
);

MemberItemFolderGetByCursorResponse response = MemberItemFolderGetByCursorResponse
.from(memberItemFolderByCursor);

return ResponseEntity.ok(response);
}

@Operation(summary = "나의 아이템 목록 조회", description = "나의 아이템 목록을 조회 합니다.")
@GetMapping("/myitems")
@GetMapping("/myitems/folders/{folderId}")
public ResponseEntity<MemberItemGetByCursorResponse> getMemberItemsByCursor(
@PathVariable final Long folderId,
@RequestParam(required = false) final String hobbyName,
@ModelAttribute("request") @Valid final CursorRequest request
) {
Hobby hobby = Hobby.from(hobbyName);
MemberItemGetServiceResponse serviceResponse = itemService.getMemberItemsByCursor(
hobby,
folderId,
request.toParameters()
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

폴더 상세조회로 swagger 설명도 바꿔보면 좋을 것 같아요~

MemberItemGetByCursorResponse response = MemberItemGetByCursorResponse.from(serviceResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ public record ItemEnrollRequest(

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

@Schema(description = "폴더 ID", example = "1")
@NotNull(message = "폴더 ID를 입력하지 않았습니다.")
Long folderId
) {

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

return new ItemEnrollServiceRequest(hobby, itemUrl);
return new ItemEnrollServiceRequest(hobby, itemUrl, folderId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.programmers.lime.domains.item.api.dto.response;

import java.util.List;

import com.programmers.lime.domains.item.application.dto.FolderGetByCursorServiceResponse;
import com.programmers.lime.domains.item.model.MemberItemFolderCursorSummary;

public record FolderGetByCursorResponse(
String nextCursorId,
int totalCount,
List<MemberItemFolderCursorSummary> summaries
) {

public static FolderGetByCursorResponse from(final FolderGetByCursorServiceResponse response) {
return new FolderGetByCursorResponse(
response.cursorSummary().nextCursorId(),
response.folderTotalCount(),
response.cursorSummary().summaries()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.programmers.lime.domains.item.api.dto.response;

import java.util.List;

import com.programmers.lime.common.cursor.CursorSummary;
import com.programmers.lime.domains.item.application.dto.MemberItemFolderGetServiceResponse;
import com.programmers.lime.domains.item.model.MemberItemFolderCursorSummary;

public record MemberItemFolderGetByCursorResponse (

String nextCursorId,

int totalMemberItemFolderCount,

int totalCount,

List<MemberItemFolderCursorSummary> memberItemFolderCursorSummaries
) {

public static MemberItemFolderGetByCursorResponse from(final MemberItemFolderGetServiceResponse serviceResponse) {
CursorSummary<MemberItemFolderCursorSummary> cursorSummary = serviceResponse.memberItemFolderSummarySummary();

return new MemberItemFolderGetByCursorResponse(
cursorSummary.nextCursorId(),
serviceResponse.totalMemberItemFolderCount(),
cursorSummary.summaryCount(),
cursorSummary.summaries()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public Long enrollItem(final ItemEnrollServiceRequest request) {
ItemCrawlerInfo itemCrawlerInfo = itemCrawlerResultToInfo(itemCrawlerResult);

// 아이템 등록
Long enrolledItemId = itemAppender.append(request.hobby(), itemCrawlerInfo);
Long enrolledItemId = itemAppender.append(request.hobby(), request.folderId(), itemCrawlerInfo);

// 아이텥 랭킹 등록
itemRanking.addRanking(itemCrawlerInfo.itemName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.programmers.lime.domains.item.application.dto.ItemGetByCursorServiceResponse;
import com.programmers.lime.domains.item.application.dto.ItemGetNamesServiceResponse;
import com.programmers.lime.domains.item.application.dto.ItemGetServiceResponse;
import com.programmers.lime.domains.item.application.dto.MemberItemFolderGetServiceResponse;
import com.programmers.lime.domains.item.application.dto.MemberItemGetServiceResponse;
import com.programmers.lime.domains.item.domain.Item;
import com.programmers.lime.domains.item.domain.MemberItem;
Expand All @@ -21,10 +22,12 @@
import com.programmers.lime.domains.item.implementation.ItemReader;
import com.programmers.lime.domains.item.implementation.MemberItemAppender;
import com.programmers.lime.domains.item.implementation.MemberItemChecker;
import com.programmers.lime.domains.item.implementation.MemberItemFolderReader;
import com.programmers.lime.domains.item.implementation.MemberItemReader;
import com.programmers.lime.domains.item.implementation.MemberItemRemover;
import com.programmers.lime.domains.item.model.ItemCursorSummary;
import com.programmers.lime.domains.item.model.ItemInfo;
import com.programmers.lime.domains.item.model.MemberItemFolderCursorSummary;
import com.programmers.lime.domains.item.model.MemberItemSummary;
import com.programmers.lime.domains.review.implementation.ReviewReader;
import com.programmers.lime.domains.review.implementation.ReviewStatistics;
Expand Down Expand Up @@ -60,6 +63,8 @@ public class ItemService {

private final ReviewReader reviewReader;

private final MemberItemFolderReader memberItemFolderReader;

public ItemAddServiceResponse addItem(final ItemIdRegistry itemIdRegistry) {
List<String> items = itemIdRegistry.itemIds().stream()
.map(itemReader::read)
Expand Down Expand Up @@ -131,20 +136,39 @@ public ItemGetByCursorServiceResponse getItemsByCursor(

public MemberItemGetServiceResponse getMemberItemsByCursor(
final Hobby hobby,
final Long folderId,
final CursorPageParameters parameters
) {
Long memberId = memberUtils.getCurrentMemberId();
int totalMemberItemCount = memberItemReader.countByMemberIdAndHobby(memberId, hobby);

CursorSummary<MemberItemSummary> cursorSummary = memberItemReader.readMemberItem(
hobby,
folderId,
memberId,
parameters
);

return new MemberItemGetServiceResponse(cursorSummary, totalMemberItemCount);
}

public MemberItemFolderGetServiceResponse getMemberItemFolderByCursor(
final Hobby hobby,
final CursorPageParameters parameters
) {
Long memberId = memberUtils.getCurrentMemberId();
int totalMemberItemFolderCount = memberItemFolderReader.countByMemberIdAndHobby(memberId, hobby);

CursorSummary<MemberItemFolderCursorSummary> cursorSummary = memberItemFolderReader.readMemberItemFolderByCursor(
hobby,
memberId,
parameters
);

return new MemberItemFolderGetServiceResponse(cursorSummary, totalMemberItemFolderCount);
}


public List<ItemRankingServiceResponse> getRanking() {
return itemRanking.viewRanking();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.programmers.lime.domains.item.application.dto;

import com.programmers.lime.common.cursor.CursorSummary;
import com.programmers.lime.domains.item.model.MemberItemFolderCursorSummary;

public record FolderGetByCursorServiceResponse(
int folderTotalCount,
CursorSummary<MemberItemFolderCursorSummary> cursorSummary
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public record ItemEnrollServiceRequest(
Hobby hobby,
String itemUrl
String itemUrl,
Long folderId
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.programmers.lime.domains.item.application.dto;

import com.programmers.lime.common.cursor.CursorSummary;
import com.programmers.lime.domains.item.model.MemberItemFolderCursorSummary;
import com.programmers.lime.domains.item.model.MemberItemFolderSummary;

public record MemberItemFolderGetServiceResponse(

CursorSummary<MemberItemFolderCursorSummary> memberItemFolderSummarySummary,
int totalMemberItemFolderCount

) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,23 @@ public class Item extends BaseEntity {
@Column(name = "image", nullable = false)
private String image;

@Column(name = "folder_id", nullable = false)
private Long folderId;

@Builder
public Item(
final Hobby hobby,
final String name,
final Integer price,
final String url,
final String image
final String image,
final Long folderId
) {
this.hobby = Objects.requireNonNull(hobby);
this.name = Objects.requireNonNull(name);
this.price = Objects.requireNonNull(price);
this.url = Objects.requireNonNull(url);
this.image = Objects.requireNonNull(image);
this.folderId = Objects.requireNonNull(folderId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.programmers.lime.domains.item.domain;

import java.util.Objects;

import com.programmers.lime.common.model.Hobby;
import com.programmers.lime.domains.BaseEntity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Table(name = "member_item_folders")
public class MemberItemFolder extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;

@Column(name = "name", nullable = false)
private String name;

@Column(name = "member_id", nullable = false)
private Long memberId;

@Column(name = "hobby", nullable = false)
@Enumerated(EnumType.STRING)
private Hobby hobby;

public MemberItemFolder(final String name, final Long memberId, final Hobby hobby) {
this.name = Objects.requireNonNull(name);
this.memberId = Objects.requireNonNull(memberId);
this.hobby = Objects.requireNonNull(hobby);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ public class ItemAppender {

public Long append(
final Hobby hobby,
final Long folderId,
final ItemCrawlerInfo itemInfo
) {
Item item = Item.builder().
hobby(hobby).
folderId(folderId).
image(itemInfo.imageUrl()).
url(itemInfo.url()).
price(itemInfo.price()).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.programmers.lime.domains.item.implementation;

import java.util.List;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

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.MemberItemFolderCursorSummary;
import com.programmers.lime.domains.item.repository.MemberItemFolderRepository;

import lombok.RequiredArgsConstructor;

@Component
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class MemberItemFolderReader {

private final MemberItemFolderRepository memberItemFolderRepository;
private static final int DEFAULT_PAGE_SIZE = 20;

public int countByMemberIdAndHobby(
final Long memberId,
final Hobby hobby
) {
return memberItemFolderRepository.countByHobbyAndMemberId(hobby, memberId);
}

public CursorSummary<MemberItemFolderCursorSummary> readMemberItemFolderByCursor(
final Hobby hobby,
final Long memberId,
final CursorPageParameters parameters
) {
int size = getPageSize(parameters);
List<MemberItemFolderCursorSummary> memberItemFoldersByCursor =
memberItemFolderRepository.findMemberItemFoldersByCursor(
memberId,
hobby,
parameters.cursorId(),
size
);

return CursorUtils.getCursorSummaries(memberItemFoldersByCursor);
}

private int getPageSize(final CursorPageParameters parameters) {
Integer parameterSize = parameters.size();

if (parameterSize == null) {
return DEFAULT_PAGE_SIZE;
}

return parameterSize;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ public List<BucketMemberItemSummary> readBucketMemberItem(

public CursorSummary<MemberItemSummary> readMemberItem(
final Hobby hobby,
final Long folderId,
final Long memberId,
final CursorPageParameters parameters
) {
int size = getPageSize(parameters);
List<MemberItemSummary> memberItemsByCursor = memberItemRepository.findMemberItemsByCursor(
hobby,
folderId,
memberId,
parameters.cursorId(),
size
Expand Down
Loading