From 59afc45d0b02708ab4a5a073322dad031d572319 Mon Sep 17 00:00:00 2001 From: ahma0 Date: Tue, 28 Nov 2023 17:08:06 +0900 Subject: [PATCH 1/4] =?UTF-8?q?Feat:=20menu=20=ED=95=9C=EB=B2=88=EC=97=90?= =?UTF-8?q?=20=EB=B3=B4=EB=82=B4=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../likeknu/controller/MenuController.java | 6 +- .../controller/dto/menu/MealListDto.java | 17 +++-- .../controller/dto/menu/MenuResponse.java | 18 +++-- .../ac/knu/likeknu/service/MenuService.java | 25 +++---- .../controller/MenuControllerTest.java | 71 ++++++++++++------- .../knu/likeknu/service/MenuServiceTest.java | 8 +-- 6 files changed, 88 insertions(+), 57 deletions(-) diff --git a/src/main/java/ac/knu/likeknu/controller/MenuController.java b/src/main/java/ac/knu/likeknu/controller/MenuController.java index 26cc8f47..022d7470 100644 --- a/src/main/java/ac/knu/likeknu/controller/MenuController.java +++ b/src/main/java/ac/knu/likeknu/controller/MenuController.java @@ -1,6 +1,6 @@ package ac.knu.likeknu.controller; -import ac.knu.likeknu.controller.dto.base.MenuResponseDto; +import ac.knu.likeknu.controller.dto.base.ResponseDto; import ac.knu.likeknu.controller.dto.menu.MenuResponse; import ac.knu.likeknu.domain.value.Campus; import ac.knu.likeknu.exception.BusinessException; @@ -22,7 +22,7 @@ public class MenuController { private final MenuService menuService; @GetMapping - public MenuResponseDto> getMenuByCampus( + public ResponseDto> getMenuByCampus( @RequestParam(name = "campus") Campus campus, @RequestParam(name = "date", defaultValue = "#{T(java.time.LocalDate).now()}") LocalDate date ) { @@ -31,6 +31,6 @@ public MenuResponseDto> getMenuByCampus( } List menuResponsesByCampus = menuService.getMenuResponsesByCampus(campus, date); - return MenuResponseDto.of(menuResponsesByCampus, date); + return ResponseDto.of(menuResponsesByCampus); } } diff --git a/src/main/java/ac/knu/likeknu/controller/dto/menu/MealListDto.java b/src/main/java/ac/knu/likeknu/controller/dto/menu/MealListDto.java index 0b92c00d..7bfe755f 100644 --- a/src/main/java/ac/knu/likeknu/controller/dto/menu/MealListDto.java +++ b/src/main/java/ac/knu/likeknu/controller/dto/menu/MealListDto.java @@ -1,10 +1,13 @@ package ac.knu.likeknu.controller.dto.menu; import ac.knu.likeknu.domain.Cafeteria; +import ac.knu.likeknu.domain.Menu; import ac.knu.likeknu.domain.value.MealType; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Builder; import lombok.Getter; +import java.time.LocalDate; import java.util.ArrayList; import java.util.List; @@ -15,17 +18,21 @@ public class MealListDto { private String operatingTime; private List menus; + @JsonIgnore + private LocalDate date; + @Builder - public MealListDto(String mealType, String operatingTime, List menus) { + public MealListDto(String mealType, String operatingTime, List menus, LocalDate date) { this.mealType = mealType; this.operatingTime = operatingTime; this.menus = menus; + this.date = date; } - public static MealListDto of(MealType mealType, Cafeteria cafeteria, String menu) { + public static MealListDto of(MealType mealType, Cafeteria cafeteria, Menu menu) { List menuList = new ArrayList<>(); if (menu != null) { - String[] menus = menu.split(" "); + String[] menus = menu.getMenus().split(" "); for (int i = 0; i < menus.length; i++) { menuList.add(MenuListDto.of(i + 1, menus[i])); } @@ -35,13 +42,15 @@ public static MealListDto of(MealType mealType, Cafeteria cafeteria, String menu .mealType(mealType.getMealTypeKr()) .operatingTime(cafeteria.getTime(mealType)) .menus(menuList) + .date(menu.getMenuDate()) .build(); } - public static MealListDto empty(MealType mealType) { + public static MealListDto empty(MealType mealType, LocalDate date) { return MealListDto.builder() .mealType(mealType.getMealTypeKr()) .menus(new ArrayList<>()) + .date(date) .build(); } diff --git a/src/main/java/ac/knu/likeknu/controller/dto/menu/MenuResponse.java b/src/main/java/ac/knu/likeknu/controller/dto/menu/MenuResponse.java index 05141dd7..4a022601 100644 --- a/src/main/java/ac/knu/likeknu/controller/dto/menu/MenuResponse.java +++ b/src/main/java/ac/knu/likeknu/controller/dto/menu/MenuResponse.java @@ -1,32 +1,36 @@ package ac.knu.likeknu.controller.dto.menu; import ac.knu.likeknu.domain.Cafeteria; -import ac.knu.likeknu.domain.value.CafeteriaName; import lombok.Builder; import lombok.Getter; -import java.util.ArrayList; +import java.time.LocalDate; import java.util.List; +import java.util.Map; @Getter public class MenuResponse { private String cafeteriaId; private String cafeteriaName; - private List meal; + private List today; + private List tomorrow; @Builder - public MenuResponse(String cafeteriaId, String cafeteriaName, List meal) { + public MenuResponse(String cafeteriaId, String cafeteriaName, List today, List tomorrow) { this.cafeteriaId = cafeteriaId; this.cafeteriaName = cafeteriaName; - this.meal = meal; + this.today = today; + this.tomorrow = tomorrow; } - public static MenuResponse of(Cafeteria cafeteria, List mealList) { + public static MenuResponse of(Cafeteria cafeteria, Map> mealList) { + LocalDate now = LocalDate.now(); return MenuResponse.builder() .cafeteriaId(cafeteria.getId()) .cafeteriaName(cafeteria.getCafeteriaName().getCafeteriaName()) - .meal(mealList) + .today(mealList.get(now)) + .tomorrow(mealList.get(now.plusDays(1))) .build(); } diff --git a/src/main/java/ac/knu/likeknu/service/MenuService.java b/src/main/java/ac/knu/likeknu/service/MenuService.java index 7bbe5812..5c8b8edc 100644 --- a/src/main/java/ac/knu/likeknu/service/MenuService.java +++ b/src/main/java/ac/knu/likeknu/service/MenuService.java @@ -16,7 +16,9 @@ import java.util.Arrays; import java.util.Comparator; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; +import java.util.stream.Stream; @Slf4j @Transactional(readOnly = true) @@ -36,18 +38,14 @@ public List getMenuResponsesByCampus(Campus campus, LocalDate date .collect(Collectors.toList()); } - /** - * MealType의 요소들을 이용해 밤이나 새벽이 아닐 경우 MealListDto 리스트를 만듭니다. - * - * @param cafeteria - * @param date - * - * @return - */ - private List filterMealtypeAndCreateList(Cafeteria cafeteria, LocalDate date) { + private Map> filterMealtypeAndCreateList(Cafeteria cafeteria, LocalDate date) { return Arrays.stream(MealType.values()) - .map(mealType -> findRepositoryAndMapDto(mealType, cafeteria, date)) - .collect(Collectors.toList()); + .flatMap(mealType -> Stream.of(date, date.plusDays(1)) + .map(day -> findRepositoryAndMapDto(mealType, cafeteria, day))) + .collect( + Collectors.groupingBy(MealListDto::getDate, + Collectors.mapping(mealListDto -> mealListDto, Collectors.toList()) + )); } /** @@ -56,13 +54,12 @@ private List filterMealtypeAndCreateList(Cafeteria cafeteria, Local * @param mealType * @param cafeteria * @param date - * * @return */ private MealListDto findRepositoryAndMapDto(MealType mealType, Cafeteria cafeteria, LocalDate date) { return menuRepository.findByMenuDateAndCafeteriaAndMealType(date, cafeteria, mealType) - .map(menu -> MealListDto.of(mealType, cafeteria, menu.getMenus())) - .orElse(MealListDto.empty(mealType)); + .map(menu -> MealListDto.of(mealType, cafeteria, menu)) + .orElse(MealListDto.empty(mealType, date)); } } diff --git a/src/test/java/ac/knu/likeknu/controller/MenuControllerTest.java b/src/test/java/ac/knu/likeknu/controller/MenuControllerTest.java index 9501e0bf..45b5338d 100644 --- a/src/test/java/ac/knu/likeknu/controller/MenuControllerTest.java +++ b/src/test/java/ac/knu/likeknu/controller/MenuControllerTest.java @@ -40,6 +40,10 @@ public class MenuControllerTest { @Test void getMenuResponsesAndSuccess() throws Exception { //given + LocalDate localDate = LocalDate.of(2023, 12, 11); + LocalDate localDate2 = LocalDate.of(2023, 12, 12); + + List menuListDtos = List.of( new MenuListDto(1, "TestMenu1"), new MenuListDto(2, "TestMenu2"), @@ -50,9 +54,14 @@ void getMenuResponsesAndSuccess() throws Exception { "Test1", "TestName1", List.of( - MealListDto.empty(MealType.BREAKFAST), - new MealListDto("점심", "TestTime1", menuListDtos), - new MealListDto("저녁", "TestTime2", menuListDtos) + MealListDto.empty(MealType.BREAKFAST, localDate), + new MealListDto("점심", "TestTime1", menuListDtos, localDate), + new MealListDto("저녁", "TestTime2", menuListDtos, localDate) + ), + List.of( + MealListDto.empty(MealType.BREAKFAST, localDate2), + new MealListDto("점심", "TestTime1", menuListDtos, localDate2), + new MealListDto("저녁", "TestTime2", menuListDtos, localDate2) ) ); @@ -60,9 +69,14 @@ void getMenuResponsesAndSuccess() throws Exception { "Test2", "TestName2", List.of( - MealListDto.empty(MealType.BREAKFAST), - MealListDto.empty(MealType.LUNCH), - MealListDto.empty(MealType.DINNER) + MealListDto.empty(MealType.BREAKFAST, localDate), + MealListDto.empty(MealType.LUNCH, localDate), + MealListDto.empty(MealType.DINNER, localDate) + ), + List.of( + MealListDto.empty(MealType.BREAKFAST, localDate2), + MealListDto.empty(MealType.LUNCH, localDate2), + MealListDto.empty(MealType.DINNER, localDate2) ) ); @@ -70,9 +84,14 @@ void getMenuResponsesAndSuccess() throws Exception { "Test3", "TestName3", List.of( - new MealListDto("아침", "TestTime3", menuListDtos), - new MealListDto("점심", "TestTime4", menuListDtos), - new MealListDto("저녁", "TestTime5", menuListDtos) + new MealListDto("아침", "TestTime3", menuListDtos, localDate), + new MealListDto("점심", "TestTime4", menuListDtos, localDate), + new MealListDto("저녁", "TestTime5", menuListDtos, localDate) + ), + List.of( + new MealListDto("아침", "TestTime3", menuListDtos, localDate2), + new MealListDto("점심", "TestTime4", menuListDtos, localDate2), + new MealListDto("저녁", "TestTime5", menuListDtos, localDate2) ) ); @@ -80,18 +99,20 @@ void getMenuResponsesAndSuccess() throws Exception { "Test3", "TestName3", List.of( - new MealListDto("아침", "TestTime6", menuListDtos), - new MealListDto("점심", "TestTime7", menuListDtos), - new MealListDto("저녁", "TestTime8", menuListDtos) + new MealListDto("아침", "TestTime6", menuListDtos, localDate), + new MealListDto("점심", "TestTime7", menuListDtos, localDate), + new MealListDto("저녁", "TestTime8", menuListDtos, localDate) + ), + List.of( + new MealListDto("아침", "TestTime6", menuListDtos, localDate2), + new MealListDto("점심", "TestTime7", menuListDtos, localDate2), + new MealListDto("저녁", "TestTime8", menuListDtos, localDate2) ) ); List menuResponseList1 = List.of(menuResponse1, menuResponse2, menuResponse4); List menuResponseList2 = List.of(menuResponse1, menuResponse3, menuResponse4); - LocalDate localDate = LocalDate.of(2023, 12, 11); - LocalDate localDate2 = LocalDate.of(2023, 12, 12); - //when when(menuService.getMenuResponsesByCampus(eq(Campus.CHEONAN), eq(localDate))) .thenReturn(menuResponseList1); @@ -114,22 +135,22 @@ void getMenuResponsesAndSuccess() throws Exception { status().isOk(), jsonPath("$.data.body.[0].cafeteriaId").value(menuResponse1.getCafeteriaId()), jsonPath("$.data.body.[1].cafeteriaName").value(menuResponse2.getCafeteriaName()), - jsonPath("$.data.body.[2].meal.[0].mealType").value(menuResponse4.getMeal().get(0).getMealType()), - jsonPath("$.data.body.[2].meal.[1].operatingTime").value(menuResponse4.getMeal().get(1).getOperatingTime()), - jsonPath("$.data.body.[1].meal.[2].menus").value(menuResponse2.getMeal().get(2).getMenus()), - jsonPath("$.data.body.[2].meal.[2].menus.[1].menuId").value(menuResponse4.getMeal().get(2).getMenus().get(1).getMenuId()), - jsonPath("$.data.body.[2].meal.[2].menus.[2].menuName").value(menuResponse4.getMeal().get(2).getMenus().get(2).getMenuName()) + jsonPath("$.data.body.[2].today.[0].mealType").value(menuResponse4.getToday().get(0).getMealType()), + jsonPath("$.data.body.[2].today.[1].operatingTime").value(menuResponse4.getToday().get(1).getOperatingTime()), + jsonPath("$.data.body.[1].today.[2].menus").value(menuResponse2.getToday().get(2).getMenus()), + jsonPath("$.data.body.[2].today.[2].menus.[1].menuId").value(menuResponse4.getToday().get(2).getMenus().get(1).getMenuId()), + jsonPath("$.data.body.[2].tomorrow.[2].menus.[2].menuName").value(menuResponse4.getTomorrow().get(2).getMenus().get(2).getMenuName()) ).andDo(print()); resultActions2.andExpectAll( status().isOk(), jsonPath("$.data.body.[0].cafeteriaId").value(menuResponse1.getCafeteriaId()), jsonPath("$.data.body.[1].cafeteriaName").value(menuResponse3.getCafeteriaName()), - jsonPath("$.data.body.[2].meal.[0].mealType").value(menuResponse4.getMeal().get(0).getMealType()), - jsonPath("$.data.body.[2].meal.[1].operatingTime").value(menuResponse4.getMeal().get(1).getOperatingTime()), - jsonPath("$.data.body.[1].meal.[2].menus.[0].menuName").value(menuResponse3.getMeal().get(2).getMenus().get(0).getMenuName()), - jsonPath("$.data.body.[2].meal.[2].menus.[1].menuId").value(menuResponse4.getMeal().get(2).getMenus().get(1).getMenuId()), - jsonPath("$.data.body.[2].meal.[2].menus.[2].menuName").value(menuResponse4.getMeal().get(2).getMenus().get(2).getMenuName()) + jsonPath("$.data.body.[2].today.[0].mealType").value(menuResponse4.getToday().get(0).getMealType()), + jsonPath("$.data.body.[2].tomorrow.[1].operatingTime").value(menuResponse4.getTomorrow().get(1).getOperatingTime()), + jsonPath("$.data.body.[1].today.[2].menus.[0].menuName").value(menuResponse3.getToday().get(2).getMenus().get(0).getMenuName()), + jsonPath("$.data.body.[2].tomorrow.[2].menus.[1].menuId").value(menuResponse4.getTomorrow().get(2).getMenus().get(1).getMenuId()), + jsonPath("$.data.body.[2].today.[2].menus.[2].menuName").value(menuResponse4.getToday().get(2).getMenus().get(2).getMenuName()) ).andDo(print()); } } diff --git a/src/test/java/ac/knu/likeknu/service/MenuServiceTest.java b/src/test/java/ac/knu/likeknu/service/MenuServiceTest.java index 4f016e28..ffaaaea7 100644 --- a/src/test/java/ac/knu/likeknu/service/MenuServiceTest.java +++ b/src/test/java/ac/knu/likeknu/service/MenuServiceTest.java @@ -70,14 +70,14 @@ void getMenuDataAndSuccess() { //then assertAll( () -> assertThat(menuResponsesByCheonan.get(0).getCafeteriaName()).isEqualTo(menu1.getCafeteria().getCafeteriaName().getCafeteriaName()), - () -> assertThat(menuResponsesByCheonan.get(1).getMeal().get(0).getMenus()).isEqualTo(new ArrayList<>()), + () -> assertThat(menuResponsesByCheonan.get(1).getToday().get(0).getMenus()).isEqualTo(new ArrayList<>()), () -> assertThat(menuResponsesByCheonan.get(1).getCafeteriaName()).isEqualTo(menu2.getCafeteria().getCafeteriaName().getCafeteriaName()), - () -> assertThat(menuResponsesByCheonan.get(1).getMeal().get(1).getMenus().get(0).getMenuName()).isEqualTo("menu4"), + () -> assertThat(menuResponsesByCheonan.get(1).getToday().get(1).getMenus().get(0).getMenuName()).isEqualTo("menu4"), () -> assertThat(menuResponsesBySingwan.get(0).getCafeteriaName()).isEqualTo(menu3.getCafeteria().getCafeteriaName().getCafeteriaName()), - () -> assertThat(menuResponsesBySingwan.get(0).getMeal().get(0).getMenus()).isEqualTo(new ArrayList<>()), + () -> assertThat(menuResponsesBySingwan.get(0).getToday().get(0).getMenus()).isEqualTo(new ArrayList<>()), () -> assertThat(menuResponsesBySingwan.get(1).getCafeteriaName()).isEqualTo(menu4.getCafeteria().getCafeteriaName().getCafeteriaName()), - () -> assertThat(menuResponsesBySingwan.get(1).getMeal().get(1).getMenus().get(0).getMenuName()).isEqualTo("menu15") + () -> assertThat(menuResponsesBySingwan.get(1).getToday().get(1).getMenus().get(0).getMenuName()).isEqualTo("menu15") ); From fd92333db050f159d9e0e3f7c1e501b5699fa8b8 Mon Sep 17 00:00:00 2001 From: ahma0 Date: Tue, 28 Nov 2023 20:33:27 +0900 Subject: [PATCH 2/4] =?UTF-8?q?Fix:=20=EC=98=A4=EB=8A=98=EC=9D=B4=20?= =?UTF-8?q?=EC=95=84=EB=8B=88=EB=A9=B4=20=EB=8D=B0=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=EA=B0=80=20=EC=98=A4=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ac/knu/likeknu/controller/dto/menu/MenuResponse.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/ac/knu/likeknu/controller/dto/menu/MenuResponse.java b/src/main/java/ac/knu/likeknu/controller/dto/menu/MenuResponse.java index 4a022601..c2994ba2 100644 --- a/src/main/java/ac/knu/likeknu/controller/dto/menu/MenuResponse.java +++ b/src/main/java/ac/knu/likeknu/controller/dto/menu/MenuResponse.java @@ -25,12 +25,13 @@ public MenuResponse(String cafeteriaId, String cafeteriaName, List } public static MenuResponse of(Cafeteria cafeteria, Map> mealList) { - LocalDate now = LocalDate.now(); + List keys = mealList.keySet().stream().sorted().toList(); + return MenuResponse.builder() .cafeteriaId(cafeteria.getId()) .cafeteriaName(cafeteria.getCafeteriaName().getCafeteriaName()) - .today(mealList.get(now)) - .tomorrow(mealList.get(now.plusDays(1))) + .today(mealList.get(keys.get(0))) + .tomorrow(mealList.get(keys.get(1))) .build(); } From ca2515ca214116a026bd6d29f10e22a3079bf9c3 Mon Sep 17 00:00:00 2001 From: ahma0 Date: Wed, 29 Nov 2023 01:59:06 +0900 Subject: [PATCH 3/4] =?UTF-8?q?Rename:=20=ED=95=A8=EC=88=98=EB=AA=85=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/ac/knu/likeknu/service/MenuService.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/main/java/ac/knu/likeknu/service/MenuService.java b/src/main/java/ac/knu/likeknu/service/MenuService.java index 5c8b8edc..82a00417 100644 --- a/src/main/java/ac/knu/likeknu/service/MenuService.java +++ b/src/main/java/ac/knu/likeknu/service/MenuService.java @@ -34,11 +34,11 @@ public List getMenuResponsesByCampus(Campus campus, LocalDate date return cafeterias.stream() .sorted(Comparator.comparing(cafeteria -> cafeteria.getCafeteriaName().getSequence())) - .map(cafeteria -> MenuResponse.of(cafeteria, filterMealtypeAndCreateList(cafeteria, date))) + .map(cafeteria -> MenuResponse.of(cafeteria, createMapContainingMealListDto(cafeteria, date))) .collect(Collectors.toList()); } - private Map> filterMealtypeAndCreateList(Cafeteria cafeteria, LocalDate date) { + private Map> createMapContainingMealListDto(Cafeteria cafeteria, LocalDate date) { return Arrays.stream(MealType.values()) .flatMap(mealType -> Stream.of(date, date.plusDays(1)) .map(day -> findRepositoryAndMapDto(mealType, cafeteria, day))) @@ -48,14 +48,6 @@ private Map> filterMealtypeAndCreateList(Cafeteria )); } - /** - * 레포지토리에서 현재 시간과 cafeteria, mealType을 이용해 데이터를 가져온 후 MealListDto로 매핑합니다. - * - * @param mealType - * @param cafeteria - * @param date - * @return - */ private MealListDto findRepositoryAndMapDto(MealType mealType, Cafeteria cafeteria, LocalDate date) { return menuRepository.findByMenuDateAndCafeteriaAndMealType(date, cafeteria, mealType) .map(menu -> MealListDto.of(mealType, cafeteria, menu)) From 891e61b2ae91ae8ea3ae8fd87025d15d4f2ddc62 Mon Sep 17 00:00:00 2001 From: ahma0 Date: Wed, 29 Nov 2023 03:02:33 +0900 Subject: [PATCH 4/4] =?UTF-8?q?Feat:=20workFlow=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cicd.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 01d5b376..7bae0528 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -4,9 +4,9 @@ on: push: branches: - main - pull_request: - branches: - - main +# pull_request: +# branches: +# - main jobs: deploy: