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

[NO-JIRA] 취미 요구사항 변경 #1

Merged
merged 3 commits into from
Jan 11, 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 @@ -65,7 +65,7 @@ public ResponseEntity<BucketGetMemberItemResponse> getMemberItemsForModify(
BucketGetMemberItemResponse response = BucketGetMemberItemResponse.from(
bucketService.getMemberItemsForModify(
bucketId,
Hobby.fromName(hobbyName),
Hobby.from(hobbyName),
cursorRequest.toParameters()
)
);
Expand Down Expand Up @@ -102,7 +102,7 @@ public ResponseEntity<BucketGetByCursorResponse> getBucketsByCursor(
BucketGetByCursorResponse response = BucketGetByCursorResponse.from(
bucketService.getBucketsByCursor(
nickname,
Hobby.fromName(hobby),
Hobby.from(hobby),
request.toParameters()
));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public record BucketCreateRequest(
) {

public BucketInfo toInfo() {
Hobby hobby = Hobby.fromHobbyValue(hobbyValue);
Hobby hobby = Hobby.from(hobbyValue);

return new BucketInfo(hobby, name, budget);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public record BucketUpdateRequest(
) {

public BucketInfo toInfo() {
Hobby hobby = Hobby.fromHobbyValue(hobbyValue);
Hobby hobby = Hobby.from(hobbyValue);

return new BucketInfo(hobby, name, budget);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public record BucketGetResponse(
) {
public static BucketGetResponse from(final BucketGetServiceResponse response) {
return BucketGetResponse.builder()
.hobby(response.hobby().getHobbyValue())
.hobby(response.hobby().getName())
.name(response.name())
.budget(response.budget())
.totalPrice(response.totalPrice())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public ResponseEntity<FeedGetByCursorResponse> getFeedByCursor(
@RequestParam(required = false) final String sortCondition,
@ModelAttribute @Valid final CursorRequest request
) {
Hobby hobby = Hobby.fromName(hobbyName);
Hobby hobby = Hobby.from(hobbyName);

CursorSummary<FeedCursorSummaryLike> cursorSummary = feedService.getFeedByCursor(
hobby,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class HobbyController {
@Operation(summary = "취미 목록 조회", description = "취미 목록 조회 결과를 반환 합니다.")
@GetMapping
public ResponseEntity<HobbyGetResponse> getHobby() {
HobbyGetResponse response = hobbyService.getHobbies();
final HobbyGetResponse response = hobbyService.getHobbies();

return ResponseEntity.ok(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

import java.util.List;

public record HobbyGetResponse(
List<HobbyItem> hobbies
) {
public record HobbyGetResponse(List<String> hobbies) {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
package com.programmers.lime.domains.hobby.application;

import java.util.List;

import org.springframework.stereotype.Service;

import com.programmers.lime.common.model.Hobby;
import com.programmers.lime.domains.hobby.api.dto.response.HobbyGetResponse;
import com.programmers.lime.domains.hobby.api.dto.response.HobbyItem;

@Service
public class HobbyService {

public HobbyGetResponse getHobbies() {
List<Hobby> hobbies = List.of(Hobby.values());

List<HobbyItem> hobbyItems = hobbies.stream().map(
hobby -> new HobbyItem(
hobby.getName(),
hobby.getHobbyValue()
)
).toList();

return new HobbyGetResponse(
hobbyItems
);
return new HobbyGetResponse(Hobby.getHobbies());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class InventoryController {
@PostMapping("/inventories")
public ResponseEntity<InventoryCreateResponse> createInventory(
@RequestBody @Valid final InventoryCreateRequest request) {
Hobby hobby = Hobby.fromHobbyValue(request.hobbyValue());
Hobby hobby = Hobby.from(request.hobbyValue());
Long inventoryId = inventoryService.createInventory(hobby, request.toRegistry());

return ResponseEntity.ok(new InventoryCreateResponse(inventoryId));
Expand Down Expand Up @@ -90,7 +90,7 @@ public ResponseEntity<InventoryGetReviewedItemResponse> getReviewedItemsForModif
InventoryGetReviewedItemResponse response = InventoryGetReviewedItemResponse.from(
inventoryService.getReviewedItemsForModify(
inventoryId,
Hobby.fromName(hobbyName),
Hobby.from(hobbyName),
cursorRequest.toParameters()
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public record InventoryGetResponse(
public static InventoryGetResponse from(final InventoryGetServiceResponse serviceResponse) {
return InventoryGetResponse.builder()
.memberId(serviceResponse.memberId())
.hobby(serviceResponse.hobby().getHobbyValue())
.hobby(serviceResponse.hobby().getName())
.itemCount(serviceResponse.itemCount())
.inventoryItemInfos(serviceResponse.inventoryItemInfos())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public ResponseEntity<MemberItemGetByCursorResponse> getMemberItemsByCursor(
@RequestParam(required = false) final String hobbyName,
@ModelAttribute("request") @Valid final CursorRequest request
) {
Hobby hobby = Hobby.fromName(hobbyName);
Hobby hobby = Hobby.from(hobbyName);
MemberItemGetServiceResponse serviceResponse = itemService.getMemberItemsByCursor(
hobby,
request.toParameters()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public record ItemEnrollRequest(
) {

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

return new ItemEnrollServiceRequest(hobby, itemUrl);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public ResponseEntity<VoteGetByCursorResponse> getVotesByCursor(
@ModelAttribute @Valid final CursorRequest request
) {
final CursorSummary<VoteSummary> cursorSummary = voteService.getVotesByCursor(
Hobby.fromName(hobby),
Hobby.from(hobby),
VoteStatusCondition.from(statusCondition),
VoteSortCondition.from(sortCondition),
request.toParameters()
Expand All @@ -114,7 +114,8 @@ public ResponseEntity<VoteGetByKeywordResponse> getVotesByKeyword(
@RequestParam final String keyword,
@ModelAttribute @Valid final CursorRequest request
) {
final VoteGetByKeywordServiceResponse serviceResponse = voteService.getVotesByKeyword(keyword, request.toParameters());
final VoteGetByKeywordServiceResponse serviceResponse = voteService.getVotesByKeyword(keyword,
request.toParameters());
final VoteGetByKeywordResponse response = VoteGetByKeywordResponse.from(serviceResponse);

return ResponseEntity.ok(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public record VoteCreateRequest(
) {
public VoteCreateServiceRequest toCreateVoteServiceRequest() {
return VoteCreateServiceRequest.builder()
.hobby(Hobby.fromHobbyValue(hobby))
.hobby(Hobby.from(hobby))
.content(content)
.item1Id(item1Id)
.item2Id(item2Id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.programmers.lime.common.model;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
Expand All @@ -16,48 +17,46 @@
@Getter
@RequiredArgsConstructor
public enum Hobby {

BASKETBALL("농구", "basketball"),
BASEBALL("야구", "baseball"),
SOCCER("축구", "soccer"),
CYCLE("사이클", "cycle"),
KEYBOARD("키보드", "keyboard"),
SWIMMING("수영", "swimming");
// Sports
BASKETBALL("농구"),
BADMINTON("배드민턴"),
CLIMBING("클라이밍"),
WORK_OUT("헬스"),
BASEBALL("야구"),

// Lifestyle
COOKING("요리"),
GAME("게임"),
DESKTERIOR("데스크테리어"),
PAINTING("그림"),
MUSIC("음악"),
;

private static final Map<String, Hobby> HOBBY_NAME_MAP;

private static final Map<String, Hobby> HOBBY_VALUE_MAP;

static {
HOBBY_NAME_MAP = Collections.unmodifiableMap(Stream.of(values())
.collect(Collectors.toMap(Hobby::getName, Function.identity())));

HOBBY_VALUE_MAP = Collections.unmodifiableMap(Stream.of(values())
.collect(Collectors.toMap(Hobby::getHobbyValue, Function.identity())));
}

private final String hobbyValue;
private final String name;

public static Hobby fromName(final String name) {

public static Hobby from(final String name) {
if (Objects.isNull(name)) {
return null;
}

String nameLowerCase = name.toLowerCase();
if (HOBBY_NAME_MAP.containsKey(nameLowerCase)) {
return HOBBY_NAME_MAP.get(nameLowerCase);
if (HOBBY_NAME_MAP.containsKey(name)) {
return HOBBY_NAME_MAP.get(name);
}

throw new BusinessException(ErrorCode.HOBBY_BAD_PARAMETER);
}

public static Hobby fromHobbyValue(final String hobbyValue) {
if (HOBBY_VALUE_MAP.containsKey(hobbyValue)) {
return HOBBY_VALUE_MAP.get(hobbyValue);
}

throw new BusinessException(ErrorCode.HOBBY_BAD_PARAMETER);
public static List<String> getHobbies() {
return HOBBY_NAME_MAP.values()
.stream()
.map(Hobby::getName)
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static BucketProfile of(
) {
return new BucketProfile(
bucket.getId(),
bucket.getHobby().getHobbyValue(),
bucket.getHobby().getName(),
itemImages);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static FeedInfo of(
) {
return FeedInfo.builder()
.id(feed.getId())
.hobby(feed.getHobby().getHobbyValue())
.hobby(feed.getHobby().getName())
.content(feed.getFeedContent())
.bucketName(feed.getName())
.bucketBudget(feed.getBudget())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public InventoryInfoSummary(
int inventoryTotalPrice,
List<ItemImage> itemImages
) {
this.hobby = hobby.getHobbyValue();
this.hobby = hobby.getName();
this.inventoryId = inventoryId;
this.inventoryTotalPrice = inventoryTotalPrice;
this.itemImages = itemImages;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static InventoryProfile of(
) {
return new InventoryProfile(
inventory.getId(),
inventory.getHobby().getHobbyValue(),
inventory.getHobby().getName(),
itemImages
);
}
Expand Down
Loading