Skip to content
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 @@ -28,8 +28,8 @@ public enum ErrorCode {
INVALID_INPUT(400_002, HttpStatus.BAD_REQUEST, "입력값이 올바르지 않습니다."),
NULL_VALUE(400_003, HttpStatus.BAD_REQUEST, "Null 값이 들어왔습니다."),
TEST_ERROR(400_004, HttpStatus.BAD_REQUEST, "테스트 에러입니다."),
ALREADY_ON(400_005, HttpStatus.BAD_REQUEST, "이미 검색어 저장 기능이 켜져있습니다"),
ALREADY_OFF(400_006, HttpStatus.BAD_REQUEST, "이미 검색어 저장 기능이 꺼져있습니다"),
BAD_PRODUCT_DELETE_CUSTOM(403_004, HttpStatus.FORBIDDEN, "커스텀 내부에 존재하지않는 상품을 삭제할 수 없습니다."),



// ========================
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package site.kikihi.custom.platform.adapter.in.web;

import org.springframework.data.domain.*;
import site.kikihi.custom.global.response.ApiResponse;
import site.kikihi.custom.global.response.ErrorCode;
import site.kikihi.custom.global.response.page.PageRequest;
import site.kikihi.custom.global.response.page.SliceResponse;
import site.kikihi.custom.platform.adapter.in.web.dto.request.custom.CustomCategoryType;
import site.kikihi.custom.platform.adapter.in.web.dto.request.custom.CustomKeyboardRequest;
import site.kikihi.custom.platform.adapter.in.web.dto.response.custom.CustomKeyboardLayoutResponse;
import site.kikihi.custom.platform.adapter.in.web.dto.request.custom.CustomKeyboardUpdateRequest;
import site.kikihi.custom.platform.adapter.in.web.dto.response.custom.CustomKeyboardDetailResponse;
import site.kikihi.custom.platform.adapter.in.web.dto.response.custom.CustomKeyboardListResponse;
import site.kikihi.custom.platform.adapter.in.web.dto.response.product.ProductListResponse;
Expand All @@ -16,10 +18,6 @@
import site.kikihi.custom.security.oauth2.domain.PrincipalDetails;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.SliceImpl;
import org.springframework.data.domain.Sort;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import java.util.List;
Expand Down Expand Up @@ -96,21 +94,6 @@ public ApiResponse<SliceResponse<CustomKeyboardListResponse>> getMyCustoms(
return ApiResponse.ok(SliceResponse.from(dtoSlice));
}

/**
* 키보드 배열 종류 조회
*/
@GetMapping("/layout")
public ApiResponse<List<CustomKeyboardLayoutResponse>> getCustomKeyboardLayout() {

/// 서비스
List<CustomKeyboardLayout> layouts = service.getKeyboardLayouts();

/// DTO
List<CustomKeyboardLayoutResponse> responses = CustomKeyboardLayoutResponse.from(layouts);

return ApiResponse.ok(responses);
}

/**
* 배열에 맞는 상품 조회
*/
Expand All @@ -119,6 +102,9 @@ public ApiResponse<SliceResponse<ProductListResponse>> getCustomKeyboardProducts
@AuthenticationPrincipal PrincipalDetails principalDetails,
@RequestParam CustomCategoryType category,
@RequestParam CustomKeyboardLayout layout,
@RequestParam(required = false) Integer minPrice,
@RequestParam(required = false) Integer maxPrice,
@RequestParam(required = true, defaultValue = "false") boolean bookmark,
PageRequest pageRequest
) {

Expand All @@ -133,22 +119,60 @@ public ApiResponse<SliceResponse<ProductListResponse>> getCustomKeyboardProducts
);

/// 서비스
Slice<ProductListResponse> content = service.getCustomProducts(userId, category.getValue(), layout, pageable);
Slice<ProductListResponse> content;
long counts;

// 파라미터 여부에 따라 분기 처리
if (!bookmark && minPrice == null && maxPrice == null) {
/// 카테고리만 있는 경우
var result = service.getCustomProducts(userId, category.getValue(), layout, pageable);
counts = result.getTotalElements();
content = result;

} else if (bookmark && minPrice == null && maxPrice == null) {
/// 카테고리와 북마크만 있는 경우
var result = service.getProductsByBookmark(userId, category.getValue(), layout, pageable);
counts = result.getTotalElements();
content = result;

} else if (!bookmark && minPrice != null && maxPrice != null) {
/// 카테고리와 가격만 있는 경우
var result = service.getProductsByCategoryIdAndPrice(userId, category.getValue(), layout, minPrice, maxPrice, pageable);
counts = result.getTotalElements();
content = result;

} else if (bookmark && minPrice != null && maxPrice != null) {
/// 카테고리,북마크,가격 모두 있는 경우
var result = service.getProductsByFilterAndBookmark(userId, category.getValue(), layout, minPrice, maxPrice, pageable);
counts = result.getTotalElements();
content = result;
} else {
throw new IllegalArgumentException(ErrorCode.BAD_REQUEST.getMessage());
}

/// 개수 조회
Long counts = service.getCustomProductCounts(category.getValue(), layout);

/// DTO 변경
Slice<ProductListResponse> dtoSlice = new SliceImpl<>(
content.getContent(),
content.getPageable(),
content.hasNext()
);

/// 응답
return ApiResponse.ok(SliceResponse.from(dtoSlice, counts));
return ApiResponse.ok(SliceResponse.from(content, counts));
}


/**
* 커스텀 키보드 내부 상품 추가하기
* @param request 추가 DTO
* @param principalDetails 유저
*/
public ApiResponse<Void> updateCustomKeyboard(
@RequestBody CustomKeyboardUpdateRequest request,
@AuthenticationPrincipal PrincipalDetails principalDetails
){

/// 서비스
service.insertProductInCustomKeyboard(request.getId(), request.getCategory().getValue(), request.getProductId(), principalDetails.getId());

return ApiResponse.updated();
}


/**
* 커스텀 키보드 삭제 API
* @param id 삭제할 커스텀 키보드
Expand All @@ -166,4 +190,25 @@ public ApiResponse<Void> deleteCustomKeyboard(
return ApiResponse.deleted();

}

/**
* 커스텀 키보드 내부 상품 삭제 API
* @param id 수정할 커스텀 키보드
* @param category 카테고리 API
* @param productId 상품 ID
* @param principalDetails 유저
*/
@DeleteMapping()
public ApiResponse<Void> deleteProductInsideCustom(
@RequestParam Long id,
@RequestParam CustomCategoryType category,
@RequestParam String productId,
@AuthenticationPrincipal PrincipalDetails principalDetails
) {

/// 서비스 호출
service.deleteCustomInside(id, category.getValue(), productId, principalDetails.getId());

return ApiResponse.deleted();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,34 +60,41 @@ public ApiResponse<SliceResponse<ProductListResponse>> getProductList(PageReques

/// 공통 객체들 저장
Slice<ProductListResponse> products;
Long totalCounts;

/// 유저가 없다면 null 저장
UUID userId = principalDetails != null ? principalDetails.getId() : null;

// 파라미터 여부에 따라 분기 처리
if (manufacturer == null && minPrice == null && maxPrice == null) {
/// 카테고리만 있는 경우
products = productService.getProductsByCategoryId(userId, category.getValue(), pageable);
var result = productService.getProductsByCategoryId(userId, category.getValue(), pageable);
totalCounts = result.getTotalElements();
products = result;

} else if (manufacturer != null && minPrice == null && maxPrice == null) {
/// 카테고리 + 제조사만 있는 경우
products = productService.getProductsByCategoryIdAndManufacturerId(userId, category.getValue(), manufacturer, pageable);
var result = productService.getProductsByCategoryIdAndManufacturerId(userId, category.getValue(), manufacturer, pageable);
totalCounts = result.getTotalElements();
products = result;

} else if (manufacturer == null && minPrice != null && maxPrice != null) {
/// 카테고리 + 가격만 있는 경우
products = productService.getProductsByCategoryIdAndPrice(userId, category.getValue(), minPrice, maxPrice, pageable);
var result = productService.getProductsByCategoryIdAndPrice(userId, category.getValue(), minPrice, maxPrice, pageable);
totalCounts = result.getTotalElements();
products = result;

} else if (manufacturer != null && minPrice != null && maxPrice != null) {
/// 카테고리 + 제조사 + 가격이 있는 경우
products = productService.getProductsByCategoryIdAndManufacturerIdAndPrice(
var result = productService.getProductsByCategoryIdAndManufacturerIdAndPrice(
userId, category.getValue(), manufacturer, minPrice, maxPrice, pageable);
totalCounts = result.getTotalElements();
products = result;

} else {
throw new IllegalArgumentException(ErrorCode.BAD_REQUEST.getMessage());
}

/// 카테고리에 따른 전체 개수 조회
Long totalCounts = productService.getCountProducts(category.getValue());

return ApiResponse.ok(SliceResponse.from(products, totalCounts));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package site.kikihi.custom.platform.adapter.in.web.dto.request.custom;

import lombok.Data;

@Data
public class CustomKeyboardUpdateRequest {

private Long id;

private CustomCategoryType category;

private String productId;

}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ public static List<ProductListResponse> from(List<Product> products, Set<String>
.toList();
}

/// 북마크한 내용이 있을 때, 북마크한 상품목록만 가져오는 정적 팩토리 메서드
public static List<ProductListResponse> fromBookmark(List<Product> products, Set<String> bookmarkProductIds) {
return products.stream()
.map(product -> ProductListResponse.from(
product,
bookmarkProductIds.contains(product.getId())))
/// true인 것만 가져오게끔
.filter(ProductListResponse::likedByMe)
.toList();
}

/// 북마크한 내용이 있을 때 사용하는, 내부 정적 팩토리 메서드
public static ProductListResponse from(Product product, boolean likedByMe) {
return ProductListResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,6 @@ ApiResponse<CustomKeyboardDetailResponse> getCustomKeyboard(
ApiResponse<SliceResponse<CustomKeyboardListResponse>> getMyCustoms(
@AuthenticationPrincipal PrincipalDetails principalDetails);


/**
* 키보드 배열 종류 조회
*/
@Operation(
summary = "키보드 배열 목록 조회 API",
description = "키보드 배열의 목록을 조회합니다."
)
ApiResponse<List<CustomKeyboardLayoutResponse>> getCustomKeyboardLayout();


/**
*
*/
Expand All @@ -99,6 +88,9 @@ ApiResponse<SliceResponse<ProductListResponse>> getCustomKeyboardProductsByLayou
@AuthenticationPrincipal PrincipalDetails principalDetails,
@RequestParam CustomCategoryType category,
@RequestParam CustomKeyboardLayout layout,
@RequestParam(required = false) Integer minPrice,
@RequestParam(required = false) Integer maxPrice,
@RequestParam(required = true) boolean bookmark,
PageRequest pageRequest
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,40 @@ public boolean existCustomKeyboardByUserIdAndId(UUID userId, Long id) {
return repository.existsByUserIdAndId(userId, id);
}

/**
* 커스텀 키보드를 제작했다면 최신의 것 반영
* @param userId 유저
*/
@Override
public Optional<CustomKeyboard> loadCustomKeyboardByUserId(UUID userId) {
return repository.findByUserId(userId)
return repository.findByUserId(userId).stream()
.findFirst()
.map(CustomKeyboardJpaEntity::toDomain);
}

/**
* 커스텀 키보드 내부에 해당 상품 ID가 존재하는지 체크
*
* @param id 커스텀 ID
* @param productId 상품 ID
*/
@Override
public boolean existProductInsideCustomKeyboard(Long id, String categoryId, String productId) {

switch (categoryId) {
case "housing":
return repository.existsByIdAndFrameId(id, productId);
case "switch":
return repository.existsByIdAndSwitchId(id, productId);
case "keycap":
return repository.existsByIdAndKeyCapId(id, productId);
case "accessory":
return repository.existsByIdAndAccessoryId(id, productId);
default:
return false;
}
}

// =================
// DB 수정
// =================
Expand All @@ -99,4 +127,19 @@ public void updateCustomKeyboard(CustomKeyboard customKeyboard) {
public void deleteCustomKeyboard(Long id) {
repository.deleteById(id);
}

/**
* 삭제할 커스텀 키보드
* @param id 아이디
* @param categoryId 카테고리
* @param productId 상품 ID
*/
@Override
public void deleteProductInsideCustomKeyboard(Long id, String categoryId, String productId) {

/// 삭제가 아닌 수정으로 진행
/// 더티 체킹으로서 수행


}
}
Loading
Loading