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 all 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 @@ -58,7 +60,9 @@ public ResponseEntity<ItemEnrollResponse> enrollItem(@Valid @RequestBody final I
@Operation(summary = "아이템 담기", description = "MemberItemAddRequest을 이용하여 사용자에 아이템을 담기 합니다.")
@PostMapping("/myitems")
public ResponseEntity<ItemAddResponse> addItems(@Valid @RequestBody final MemberItemAddRequest request) {
ItemAddServiceResponse serviceResponse = itemService.addItem(request.toAddMemberItemServiceRequest());
ItemAddServiceResponse serviceResponse = itemService.addItem(
request.toMemberItemIdRegistry()
);
ItemAddResponse response = ItemAddResponse.from(serviceResponse);

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

@Operation(summary = "나의 아이템 목록 조회", description = "나의 아이템 목록을 조회 합니다.")
@GetMapping("/myitems")
@Operation(summary = "나의 아이템 폴더 조회", description = "나의 아이템 폴더 목록을 조회 합니다.")
@GetMapping("/myitems/folders")
public ResponseEntity<MemberItemFolderGetByCursorResponse> getMemberItemFoldersByCursor(
@RequestParam 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/folders/{folderId}")
public ResponseEntity<MemberItemGetByCursorResponse> getMemberItemsByCursor(
@RequestParam(required = false) final String hobbyName,
@PathVariable final Long folderId,
@RequestParam final String hobbyName,
@ModelAttribute("request") @Valid final CursorRequest request
) {
Hobby hobby = Hobby.from(hobbyName);
MemberItemGetServiceResponse serviceResponse = itemService.getMemberItemsByCursor(
hobby,
folderId,
request.toParameters()
);
MemberItemGetByCursorResponse response = MemberItemGetByCursorResponse.from(serviceResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;

import com.programmers.lime.common.model.ItemIdRegistry;
import com.programmers.lime.domains.item.model.MemberItemIdRegistry;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
Expand All @@ -11,9 +11,13 @@ public record MemberItemAddRequest(

@Schema(description = "여러 아이템 id", example = "[1, 2, 3]")
@NotNull(message = "아이템 목록은 필수 값 입니다.")
List<Long> itemIds
List<Long> itemIds,

@Schema(description = "아이템 폴더 id", example = "1")
@NotNull(message = "아이템 폴더 id는 필수 값 입니다.")
Long folderId
) {
public ItemIdRegistry toAddMemberItemServiceRequest() {
return new ItemIdRegistry(itemIds);
public MemberItemIdRegistry toMemberItemIdRegistry() {
return new MemberItemIdRegistry(itemIds, 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 @@ -21,8 +21,6 @@ public class ItemEnrollService {

private final ItemAppender itemAppender;

private final ItemService itemService;

private final ItemEnrollValidator itemEnrollValidator;

private final ItemRanking itemRanking;
Expand All @@ -42,11 +40,6 @@ public Long enrollItem(final ItemEnrollServiceRequest request) {
// 아이텥 랭킹 등록
itemRanking.addRanking(itemCrawlerInfo.itemName());

// 아이템 담기
ItemIdRegistry itemIdRegistry = getItemIdRegistry(enrolledItemId);
itemService.addItem(itemIdRegistry);
itemRanking.increasePoint(itemCrawlerInfo.itemName(), 1);

return enrolledItemId;
}

Expand All @@ -59,10 +52,4 @@ private ItemCrawlerInfo itemCrawlerResultToInfo(final ItemCrawlerResult itemCraw
.url(itemCrawlerResult.url())
.build();
}

private ItemIdRegistry getItemIdRegistry(final Long enrolledItemId) {
List<Long> ids = List.of(enrolledItemId);

return new ItemIdRegistry(ids);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
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.ItemIdRegistry;
import com.programmers.lime.common.model.ItemRemovalList;
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.domains.item.domain.Item;
import com.programmers.lime.domains.item.domain.MemberItem;
Expand All @@ -21,10 +21,13 @@
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.MemberItemIdRegistry;
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,8 +63,12 @@ public class ItemService {

private final ReviewReader reviewReader;

public ItemAddServiceResponse addItem(final ItemIdRegistry itemIdRegistry) {
List<String> items = itemIdRegistry.itemIds().stream()
private final MemberItemFolderReader memberItemFolderReader;

public ItemAddServiceResponse addItem(
final MemberItemIdRegistry memberItemIdRegistry
) {
List<String> items = memberItemIdRegistry.itemIds().stream()
.map(itemReader::read)
.map(Item::getName)
.toList();
Expand All @@ -71,7 +78,11 @@ public ItemAddServiceResponse addItem(final ItemIdRegistry itemIdRegistry) {
}

Long memberId = memberUtils.getCurrentMemberId();
List<Long> memberItemIds = memberItemAppender.addMemberItems(itemIdRegistry.itemIds(), memberId);
List<Long> memberItemIds = memberItemAppender.addMemberItems(
memberItemIdRegistry.itemIds(),
memberItemIdRegistry.folderId(),
memberId
);

return new ItemAddServiceResponse(memberItemIds);
}
Expand Down Expand Up @@ -131,20 +142,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
@@ -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 @@ -9,11 +9,11 @@
import org.springframework.boot.test.mock.mockito.MockBean;

import com.programmers.lime.IntegrationTest;
import com.programmers.lime.common.model.ItemIdRegistry;
import com.programmers.lime.common.model.ItemIdRegistryBuilder;
import com.programmers.lime.domains.item.application.dto.ItemAddServiceResponse;
import com.programmers.lime.domains.item.domain.setup.ItemSetup;
import com.programmers.lime.domains.item.implementation.MemberItemValidator;
import com.programmers.lime.domains.item.model.MemberItemIdRegistry;
import com.programmers.lime.domains.item.model.MemberItemIdRegistryBuilder;
import com.programmers.lime.global.util.MemberUtils;

class ItemServiceTest extends IntegrationTest {
Expand All @@ -39,14 +39,14 @@ public void addItemTest() {
// memberSetup이 만들어지면 변경할 예정
doNothing().when(memberItemValidator).validateExistMemberItem(any(), any());

ItemIdRegistry itemIdRegistry = ItemIdRegistryBuilder.build();
ItemAddServiceResponse expectedResponse = new ItemAddServiceResponse(itemIdRegistry.itemIds());
MemberItemIdRegistry memberItemIdRegistryBuilder = MemberItemIdRegistryBuilder.build();
ItemAddServiceResponse expectedResponse = new ItemAddServiceResponse(memberItemIdRegistryBuilder.itemIds());

itemIdRegistry.itemIds()
memberItemIdRegistryBuilder.itemIds()
.forEach(itemId -> itemSetup.saveOne(itemId));

// when
ItemAddServiceResponse actualResponse = itemService.addItem(itemIdRegistry);
ItemAddServiceResponse actualResponse = itemService.addItem(memberItemIdRegistryBuilder);

// then
assertThat(actualResponse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ public class MemberItem extends BaseEntity {
@JoinColumn(name = "item_id", nullable = false)
private Item item;

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

public MemberItem(
final Long memberId,
final Item item
final Item item,
final Long folderId
) {
this.memberId = Objects.requireNonNull(memberId);
this.item = Objects.requireNonNull(item);
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);
}
}
Loading
Loading