Skip to content

Commit

Permalink
[feat] add AlcoholDisplayOrder
Browse files Browse the repository at this point in the history
  • Loading branch information
dongseoki committed Dec 24, 2023
1 parent 101c480 commit 1cd08f1
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 7 deletions.
2 changes: 2 additions & 0 deletions server/sql/231224_1450.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE alcohol_type
ADD `display_order` bigint DEFAULT NULL
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -31,4 +32,6 @@ public class AlcoholType extends BaseEntity {

@Column(unique = true)
private String name;
@ColumnDefault("1")
private Long displayOrder;
}
22 changes: 18 additions & 4 deletions server/src/main/java/com/bside/bside_311/init/Initializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AlcoholType, Long> {
Optional<AlcoholType> findByIdAndDelYnIs(Long alcoholTypeNo, YesOrNo yesOrNo);

List<AlcoholType> findByDelYnIsOrderByDisplayOrderAsc(YesOrNo yesOrNo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ public Page<AlcoholResponseDto> getAlcoholV2(Pageable pageable, String searchKey
}

public GetAlcoholTypesResponseDto getAlcoholTypes() {
List<AlcoholType> alcoholTypes = alcoholTypeRepository.findAll();
List<AlcoholType> alcoholTypes =
alcoholTypeRepository.findByDelYnIsOrderByDisplayOrderAsc(YesOrNo.N);
return GetAlcoholTypesResponseDto.of(alcoholTypes);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 1cd08f1

Please sign in to comment.