From 1cd08f1a514aca3ec5e11d21a2bc11eed282847c Mon Sep 17 00:00:00 2001 From: Dong Seok Lee Date: Sun, 24 Dec 2023 15:27:57 +0900 Subject: [PATCH] [feat] add AlcoholDisplayOrder --- server/sql/231224_1450.sql | 2 ++ .../controller/AlcoholController.java | 2 +- .../bside_311/dto/AlcoholTypeResponseDto.java | 3 +- .../bside/bside_311/entity/AlcoholType.java | 3 ++ .../com/bside/bside_311/init/Initializer.java | 22 +++++++++++--- .../repository/AlcoholTypeRepository.java | 3 ++ .../bside_311/service/AlcoholService.java | 3 +- .../controller/AlcoholControllerTest.java | 30 +++++++++++++++++++ 8 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 server/sql/231224_1450.sql create mode 100644 server/src/test/java/com/bside/bside_311/controller/AlcoholControllerTest.java diff --git a/server/sql/231224_1450.sql b/server/sql/231224_1450.sql new file mode 100644 index 0000000..1e46604 --- /dev/null +++ b/server/sql/231224_1450.sql @@ -0,0 +1,2 @@ +ALTER TABLE alcohol_type + ADD `display_order` bigint DEFAULT NULL \ No newline at end of file diff --git a/server/src/main/java/com/bside/bside_311/controller/AlcoholController.java b/server/src/main/java/com/bside/bside_311/controller/AlcoholController.java index eb71daf..b9ed0de 100644 --- a/server/src/main/java/com/bside/bside_311/controller/AlcoholController.java +++ b/server/src/main/java/com/bside/bside_311/controller/AlcoholController.java @@ -44,7 +44,7 @@ public class AlcoholController { @Operation(summary = "[o]술 종류 조회 ", description = "술 종류 조회 API") @GetMapping("/types") - @ResponseStatus(HttpStatus.CREATED) + @ResponseStatus(HttpStatus.OK) public GetAlcoholTypesResponseDto getAlcoholTypes() { log.info(">>> AlcoholController.getAlcoholTypes"); return alcoholService.getAlcoholTypes(); diff --git a/server/src/main/java/com/bside/bside_311/dto/AlcoholTypeResponseDto.java b/server/src/main/java/com/bside/bside_311/dto/AlcoholTypeResponseDto.java index 33c69d1..ac881da 100644 --- a/server/src/main/java/com/bside/bside_311/dto/AlcoholTypeResponseDto.java +++ b/server/src/main/java/com/bside/bside_311/dto/AlcoholTypeResponseDto.java @@ -13,9 +13,10 @@ public class AlcoholTypeResponseDto { private Long alcoholTypeNo; private String name; private String description; + private Long displayOrder; public static AlcoholTypeResponseDto of(AlcoholType alcoholType) { return new AlcoholTypeResponseDto(alcoholType.getId(), alcoholType.getName(), - alcoholType.getDescription()); + alcoholType.getDescription(), alcoholType.getDisplayOrder()); } } diff --git a/server/src/main/java/com/bside/bside_311/entity/AlcoholType.java b/server/src/main/java/com/bside/bside_311/entity/AlcoholType.java index e013259..79700c4 100644 --- a/server/src/main/java/com/bside/bside_311/entity/AlcoholType.java +++ b/server/src/main/java/com/bside/bside_311/entity/AlcoholType.java @@ -10,6 +10,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicUpdate; @@ -31,4 +32,6 @@ public class AlcoholType extends BaseEntity { @Column(unique = true) private String name; + @ColumnDefault("1") + private Long displayOrder; } diff --git a/server/src/main/java/com/bside/bside_311/init/Initializer.java b/server/src/main/java/com/bside/bside_311/init/Initializer.java index 1437e5d..18536d0 100644 --- a/server/src/main/java/com/bside/bside_311/init/Initializer.java +++ b/server/src/main/java/com/bside/bside_311/init/Initializer.java @@ -257,10 +257,24 @@ private void initSignUpUsers() throws JsonProcessingException { } private void initAlcoholType() { - alcoholTypeRepository.save(AlcoholType.builder().name("소주").description("소주다.").build()); - alcoholTypeRepository.save(AlcoholType.builder().name("맥주").description("맥주다.").build()); - alcoholTypeRepository.save(AlcoholType.builder().name("와인").description("와인이다.").build()); - alcoholTypeRepository.save(AlcoholType.builder().name("막걸리").description("와인이다.").build()); + alcoholTypeRepository.save( + AlcoholType.builder().name("포도주").description("포도주다.").displayOrder(1L).build()); + alcoholTypeRepository.save( + AlcoholType.builder().name("브랜디").description("브랜디다.").displayOrder(2L).build()); + alcoholTypeRepository.save( + AlcoholType.builder().name("위스키").description("위스키다.").displayOrder(3L).build()); + alcoholTypeRepository.save( + AlcoholType.builder().name("리큐르").description("리큐르다.").displayOrder(4L).build()); + alcoholTypeRepository.save( + AlcoholType.builder().name("맥주").description("맥주다.").displayOrder(5L).build()); + alcoholTypeRepository.save( + AlcoholType.builder().name("우리술").description("우리술이다.").displayOrder(6L).build()); + alcoholTypeRepository.save( + AlcoholType.builder().name("사케").description("사케다.").displayOrder(7L).build()); + alcoholTypeRepository.save( + AlcoholType.builder().name("럼").description("럼이다.").displayOrder(8L).build()); + alcoholTypeRepository.save( + AlcoholType.builder().name("미분류").description("미분류다.").displayOrder(9L).build()); } private void attachPhoto() { diff --git a/server/src/main/java/com/bside/bside_311/repository/AlcoholTypeRepository.java b/server/src/main/java/com/bside/bside_311/repository/AlcoholTypeRepository.java index 7770981..28c7a37 100644 --- a/server/src/main/java/com/bside/bside_311/repository/AlcoholTypeRepository.java +++ b/server/src/main/java/com/bside/bside_311/repository/AlcoholTypeRepository.java @@ -4,8 +4,11 @@ import com.bside.bside_311.entity.YesOrNo; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; import java.util.Optional; public interface AlcoholTypeRepository extends JpaRepository { Optional findByIdAndDelYnIs(Long alcoholTypeNo, YesOrNo yesOrNo); + + List findByDelYnIsOrderByDisplayOrderAsc(YesOrNo yesOrNo); } diff --git a/server/src/main/java/com/bside/bside_311/service/AlcoholService.java b/server/src/main/java/com/bside/bside_311/service/AlcoholService.java index 5b52125..cfbdfc4 100644 --- a/server/src/main/java/com/bside/bside_311/service/AlcoholService.java +++ b/server/src/main/java/com/bside/bside_311/service/AlcoholService.java @@ -215,7 +215,8 @@ public Page getAlcoholV2(Pageable pageable, String searchKey } public GetAlcoholTypesResponseDto getAlcoholTypes() { - List alcoholTypes = alcoholTypeRepository.findAll(); + List alcoholTypes = + alcoholTypeRepository.findByDelYnIsOrderByDisplayOrderAsc(YesOrNo.N); return GetAlcoholTypesResponseDto.of(alcoholTypes); } diff --git a/server/src/test/java/com/bside/bside_311/controller/AlcoholControllerTest.java b/server/src/test/java/com/bside/bside_311/controller/AlcoholControllerTest.java new file mode 100644 index 0000000..e0bfffc --- /dev/null +++ b/server/src/test/java/com/bside/bside_311/controller/AlcoholControllerTest.java @@ -0,0 +1,30 @@ +package com.bside.bside_311.controller; + +import com.bside.bside_311.service.AlcoholService; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.web.servlet.MockMvc; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@WebMvcTest(AlcoholController.class) +class AlcoholControllerTest extends ControllerTest { + @Autowired + private MockMvc mockMvc; + + @MockBean + private AlcoholService alcoholService; + + @Test + void getAlcoholTypeList() throws Exception { + //given + //when + mockMvc.perform(get("/alcohols/types")) + .andExpect(status().isOk()); + + //then + } +} \ No newline at end of file