From 533c3b6bbd0f07cd7913b119d361b0112fda9ade Mon Sep 17 00:00:00 2001 From: HyunWoo9930 Date: Fri, 6 Dec 2024 14:19:06 +0900 Subject: [PATCH] =?UTF-8?q?fix=20:=20category=20=ED=95=9C=EA=B8=80?= =?UTF-8?q?=EB=A1=9C=20=EC=9E=85=EB=A0=A5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/controller/StoreController.java | 15 +++++++-------- .../domain/store/domain/Category.java | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/jangburich/domain/store/controller/StoreController.java b/src/main/java/com/jangburich/domain/store/controller/StoreController.java index edeac24..ce46853 100644 --- a/src/main/java/com/jangburich/domain/store/controller/StoreController.java +++ b/src/main/java/com/jangburich/domain/store/controller/StoreController.java @@ -57,13 +57,12 @@ public class StoreController { public ResponseCustom> searchByCategory( Authentication authentication, @RequestParam(required = false, defaultValue = "3") Integer searchRadius, - @RequestParam(required = false, defaultValue = "ALL") Category category, - Double lat, - Double lon, Pageable pageable) { + @RequestParam(required = false, defaultValue = "전체") String category, + Double lat, Double lon, Pageable pageable) { + Category categoryEnum = Category.fromDisplayName(category); return ResponseCustom.OK( - storeService.searchByCategory(AuthenticationParser.parseUserId(authentication), searchRadius, category, lat, - lon, - pageable)); + storeService.searchByCategory(AuthenticationParser.parseUserId(authentication), searchRadius, categoryEnum, + lat, lon, pageable)); } @Operation(summary = "매장 찾기(검색)", description = "검색어와 매장 유형에 맞는 매장을 검색합니다.") @@ -159,10 +158,10 @@ public ResponseCustom getOrders(Authentication authenticat @Operation(summary = "가게 엑셀 다운로드", description = "가게 장부 세부 내역을 엑셀로 제공합니다.") @GetMapping("/excel") public ResponseEntity getExcel( - Authentication authentication, + // Authentication authentication, @RequestParam(defaultValue = "1") Integer period ) { - byte[] excel = storeService.createExcel(AuthenticationParser.parseUserId(authentication), period); + byte[] excel = storeService.createExcel("test-owner", period); String today = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); String fileName = "장부_세부내역_" + period + "개월_" + today + ".xlsx"; diff --git a/src/main/java/com/jangburich/domain/store/domain/Category.java b/src/main/java/com/jangburich/domain/store/domain/Category.java index 1c3416d..14d4614 100644 --- a/src/main/java/com/jangburich/domain/store/domain/Category.java +++ b/src/main/java/com/jangburich/domain/store/domain/Category.java @@ -1,5 +1,7 @@ package com.jangburich.domain.store.domain; +import java.util.Arrays; + public enum Category { ALL("전체"), KOREAN("한식"), @@ -24,4 +26,19 @@ public enum Category { public String getDisplayName() { return displayName; } + + public static Category fromDisplayName(String displayName) { + return Arrays.stream(Category.values()) + .filter(category -> category.getDisplayName().equals(displayName)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException("Invalid category: " + displayName + ". Please use one of: " + getValidCategories())); + } + + private static String getValidCategories() { + return Arrays.stream(Category.values()) + .map(Category::getDisplayName) + .reduce((a, b) -> a + ", " + b) + .orElse(""); + } + }