diff --git a/src/main/java/com/flab/doorrush/domain/authentication/aspect/CheckLoginAspect.java b/src/main/java/com/flab/doorrush/domain/authentication/aspect/CheckLoginAspect.java index 3826b6e..2975b25 100644 --- a/src/main/java/com/flab/doorrush/domain/authentication/aspect/CheckLoginAspect.java +++ b/src/main/java/com/flab/doorrush/domain/authentication/aspect/CheckLoginAspect.java @@ -17,7 +17,7 @@ public class CheckLoginAspect { private final HttpSession httpSession; @Before("@annotation(com.flab.doorrush.domain.authentication.annotation.CheckLogin)") - public void checkLogin() throws AuthenticationCredentialsNotFoundException { + public void checkLogin(){ String currentId = (String) httpSession.getAttribute(AuthenticationService.LOGIN_SESSION); if (!StringUtils.hasLength(currentId)) { throw new AuthenticationCredentialsNotFoundException("로그인이 필요합니다."); diff --git a/src/main/java/com/flab/doorrush/domain/restaurant/api/RestaurantController.java b/src/main/java/com/flab/doorrush/domain/restaurant/api/RestaurantController.java index fc461d4..5790f5b 100644 --- a/src/main/java/com/flab/doorrush/domain/restaurant/api/RestaurantController.java +++ b/src/main/java/com/flab/doorrush/domain/restaurant/api/RestaurantController.java @@ -27,7 +27,6 @@ public ResponseEntity> addRestaurant(@PathVariable Long owne restaurantService.addRestaurant(addRestaurantRequest, ownerSeq); return ResponseEntity.status(HttpStatus.OK).build(); } - } diff --git a/src/main/java/com/flab/doorrush/domain/restaurant/dao/RestaurantMapper.java b/src/main/java/com/flab/doorrush/domain/restaurant/dao/RestaurantMapper.java index 894f74b..3971423 100644 --- a/src/main/java/com/flab/doorrush/domain/restaurant/dao/RestaurantMapper.java +++ b/src/main/java/com/flab/doorrush/domain/restaurant/dao/RestaurantMapper.java @@ -6,11 +6,8 @@ @Mapper public interface RestaurantMapper { - Restaurant selectRestaurantBySeq(long restaurantSeq); - int insertRestaurant(Restaurant restaurant); Restaurant selectRestaurantByRestaurantSeq(Long restaurantSeq); - Long selectRestaurantSeq(Restaurant restaurant); } diff --git a/src/main/java/com/flab/doorrush/domain/restaurant/domain/Restaurant.java b/src/main/java/com/flab/doorrush/domain/restaurant/domain/Restaurant.java index 59770ba..0a37252 100644 --- a/src/main/java/com/flab/doorrush/domain/restaurant/domain/Restaurant.java +++ b/src/main/java/com/flab/doorrush/domain/restaurant/domain/Restaurant.java @@ -20,4 +20,5 @@ public class Restaurant { private String introduction; private Long minimumOrderAmount; private Long addressSeq; + } diff --git a/src/main/java/com/flab/doorrush/domain/restaurant/dto/request/AddRestaurantRequest.java b/src/main/java/com/flab/doorrush/domain/restaurant/dto/request/AddRestaurantRequest.java index 9fffe85..619eddf 100644 --- a/src/main/java/com/flab/doorrush/domain/restaurant/dto/request/AddRestaurantRequest.java +++ b/src/main/java/com/flab/doorrush/domain/restaurant/dto/request/AddRestaurantRequest.java @@ -1,6 +1,7 @@ package com.flab.doorrush.domain.restaurant.dto.request; import com.flab.doorrush.domain.restaurant.domain.Restaurant; +import com.flab.doorrush.domain.restaurant.restaurantEnum.RestaurantCategory; import com.flab.doorrush.domain.user.domain.YnStatus; import javax.validation.constraints.NotNull; import lombok.AllArgsConstructor; @@ -16,7 +17,7 @@ public class AddRestaurantRequest { private RestaurantAddressRequest restaurantAddressRequest; @NotNull - private String category; + private RestaurantCategory category; @NotNull private YnStatus openYn; @@ -34,7 +35,7 @@ public class AddRestaurantRequest { public Restaurant toEntity(Long addressSeq, Long ownerSeq) { return Restaurant.builder() .ownerSeq(ownerSeq) - .category(this.category) + .category(this.category.categoryValue) .openYn(this.openYn) .restaurantName(this.restaurantName) .introduction(this.introduction) diff --git a/src/main/java/com/flab/doorrush/domain/restaurant/dto/request/RestaurantAddressRequest.java b/src/main/java/com/flab/doorrush/domain/restaurant/dto/request/RestaurantAddressRequest.java index d1b675f..e9e3e17 100644 --- a/src/main/java/com/flab/doorrush/domain/restaurant/dto/request/RestaurantAddressRequest.java +++ b/src/main/java/com/flab/doorrush/domain/restaurant/dto/request/RestaurantAddressRequest.java @@ -2,11 +2,13 @@ import com.flab.doorrush.domain.user.domain.Address; import javax.validation.constraints.NotNull; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @Getter @Builder +@AllArgsConstructor public class RestaurantAddressRequest { @NotNull diff --git a/src/main/java/com/flab/doorrush/domain/restaurant/dto/response/AddRestaurantResponse.java b/src/main/java/com/flab/doorrush/domain/restaurant/dto/response/AddRestaurantResponse.java new file mode 100644 index 0000000..031002f --- /dev/null +++ b/src/main/java/com/flab/doorrush/domain/restaurant/dto/response/AddRestaurantResponse.java @@ -0,0 +1,21 @@ +package com.flab.doorrush.domain.restaurant.dto.response; + +import com.flab.doorrush.domain.restaurant.domain.Restaurant; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +@AllArgsConstructor +public class AddRestaurantResponse { + + private Restaurant restaurant; + + public static AddRestaurantResponse from(Restaurant restaurant) { + + return AddRestaurantResponse.builder() + .restaurant(restaurant) + .build(); + } +} diff --git a/src/main/java/com/flab/doorrush/domain/restaurant/restaurantEnum/RestaurantCategory.java b/src/main/java/com/flab/doorrush/domain/restaurant/restaurantEnum/RestaurantCategory.java index cee3742..025916d 100644 --- a/src/main/java/com/flab/doorrush/domain/restaurant/restaurantEnum/RestaurantCategory.java +++ b/src/main/java/com/flab/doorrush/domain/restaurant/restaurantEnum/RestaurantCategory.java @@ -1,9 +1,6 @@ package com.flab.doorrush.domain.restaurant.restaurantEnum; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - public enum RestaurantCategory { WESTERN("양식"), @@ -12,16 +9,12 @@ public enum RestaurantCategory { SOUTHEAST_ASIAN("동남아"), SNACK("분식"); - public final String category; + public final String categoryValue; - RestaurantCategory(String category) { - this.category = category; + RestaurantCategory(String categoryValue) { + this.categoryValue = categoryValue; } - @JsonCreator - public static RestaurantCategory from(@JsonProperty("category") String category) { - return valueOf(category); - } } diff --git a/src/main/java/com/flab/doorrush/domain/restaurant/service/RestaurantService.java b/src/main/java/com/flab/doorrush/domain/restaurant/service/RestaurantService.java index 1c65e31..f917b6e 100644 --- a/src/main/java/com/flab/doorrush/domain/restaurant/service/RestaurantService.java +++ b/src/main/java/com/flab/doorrush/domain/restaurant/service/RestaurantService.java @@ -3,6 +3,7 @@ import com.flab.doorrush.domain.restaurant.dao.RestaurantMapper; import com.flab.doorrush.domain.restaurant.domain.Restaurant; import com.flab.doorrush.domain.restaurant.dto.request.AddRestaurantRequest; +import com.flab.doorrush.domain.restaurant.dto.response.AddRestaurantResponse; import com.flab.doorrush.domain.restaurant.exception.AddRestaurantException; import com.flab.doorrush.domain.user.dao.UserAddressMapper; import com.flab.doorrush.domain.user.domain.Address; @@ -19,15 +20,19 @@ public class RestaurantService { @Transactional - public void addRestaurant(AddRestaurantRequest addRestaurantRequest, Long ownerSeq) { + public AddRestaurantResponse addRestaurant(AddRestaurantRequest addRestaurantRequest, + Long ownerSeq) { Address address = addRestaurantRequest.getRestaurantAddressRequest().toEntity(); try { userAddressMapper.insertAddress(address); - Long addressSeq = userAddressMapper.selectAddressSeq(address); + Long addressSeq = address.getAddressSeq(); Restaurant restaurant = addRestaurantRequest.toEntity(addressSeq, ownerSeq); restaurantMapper.insertRestaurant(restaurant); + return AddRestaurantResponse.from(restaurant); + } catch (Exception e) { throw new AddRestaurantException(e, "식당 insert 처리 중 예외 발생"); } } + } diff --git a/src/main/java/com/flab/doorrush/domain/user/dao/UserAddressMapper.java b/src/main/java/com/flab/doorrush/domain/user/dao/UserAddressMapper.java index b055164..304d38b 100644 --- a/src/main/java/com/flab/doorrush/domain/user/dao/UserAddressMapper.java +++ b/src/main/java/com/flab/doorrush/domain/user/dao/UserAddressMapper.java @@ -25,5 +25,4 @@ public interface UserAddressMapper { Optional
selectAddressBySeq(Long addressSeq); - Long selectAddressSeq(Address address); } diff --git a/src/main/resources/mybatis/mapper/RestaurantMapper.xml b/src/main/resources/mybatis/mapper/RestaurantMapper.xml index 5b09fc8..23fdd94 100644 --- a/src/main/resources/mybatis/mapper/RestaurantMapper.xml +++ b/src/main/resources/mybatis/mapper/RestaurantMapper.xml @@ -39,14 +39,4 @@ WHERE RESTAURANT_SEQ = #{restaurantSeq} - \ No newline at end of file diff --git a/src/main/resources/mybatis/mapper/UserAddressMapper.xml b/src/main/resources/mybatis/mapper/UserAddressMapper.xml index abf3231..62ca600 100644 --- a/src/main/resources/mybatis/mapper/UserAddressMapper.xml +++ b/src/main/resources/mybatis/mapper/UserAddressMapper.xml @@ -77,14 +77,4 @@ WHERE ADDRESS_SEQ = #{addressSeq} - \ No newline at end of file diff --git a/src/test/java/com/flab/doorrush/domain/authentication/service/AuthenticationServiceTest.java b/src/test/java/com/flab/doorrush/domain/authentication/service/AuthenticationServiceTest.java index a610bd8..c39b852 100644 --- a/src/test/java/com/flab/doorrush/domain/authentication/service/AuthenticationServiceTest.java +++ b/src/test/java/com/flab/doorrush/domain/authentication/service/AuthenticationServiceTest.java @@ -27,7 +27,7 @@ class AuthenticationServiceTest { @Test - @DisplayName("로그인 성공 테스트 login메소드 실행 후 세션의 loginId 속성 값을 아이디 값과 비교한다.") + @DisplayName("로그인 성공 테스트 login 메소드 실행 후 세션의 loginId 속성 값을 아이디 값과 비교한다.") public void loginSuccessTest() { // Given MockHttpSession session = new MockHttpSession(); diff --git a/src/test/java/com/flab/doorrush/domain/restaurant/api/RestaurantControllerTest.java b/src/test/java/com/flab/doorrush/domain/restaurant/api/RestaurantControllerTest.java index 7b7fc08..aa7ed87 100644 --- a/src/test/java/com/flab/doorrush/domain/restaurant/api/RestaurantControllerTest.java +++ b/src/test/java/com/flab/doorrush/domain/restaurant/api/RestaurantControllerTest.java @@ -43,7 +43,7 @@ public void addRestaurantSuccessTest() throws Exception { AddRestaurantRequest addRestaurantRequest = AddRestaurantRequest.builder() .restaurantAddressRequest(restaurantAddressRequest) - .category(RestaurantCategory.CHINESE.category) + .category(RestaurantCategory.CHINESE) .openYn(YnStatus.N) .restaurantName("맛맛집") .introduction("아주 맛있습니다") @@ -60,7 +60,7 @@ public void addRestaurantSuccessTest() throws Exception { } @Test - @DisplayName("addRestaurant 실패 테스트 기존에 저장된 address 정보로 요청 시 AddRestaurantException 발생, HttpStatus.BAD_REQUEST 를 반환한다.") + @DisplayName("addRestaurant 실패 테스트 존재하지 않는 사장님 정보로 요청 시 AddRestaurantException 발생, HttpStatus.BAD_REQUEST 를 반환한다.") public void addRestaurantFailTest() throws Exception { // Given RestaurantAddressRequest restaurantAddressRequest = RestaurantAddressRequest.builder() @@ -71,7 +71,7 @@ public void addRestaurantFailTest() throws Exception { AddRestaurantRequest addRestaurantRequest = AddRestaurantRequest.builder() .restaurantAddressRequest(restaurantAddressRequest) - .category(RestaurantCategory.CHINESE.category) + .category(RestaurantCategory.CHINESE) .openYn(YnStatus.N) .restaurantName("맛맛집") .introduction("아주 맛있습니다") @@ -80,7 +80,7 @@ public void addRestaurantFailTest() throws Exception { String content = objectMapper.writeValueAsString(addRestaurantRequest); // When - mockMvc.perform(post("/restaurants/1/addRestaurant").content(content) + mockMvc.perform(post("/restaurants/0/addRestaurant").content(content) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andDo(print()) diff --git a/src/test/java/com/flab/doorrush/domain/restaurant/dao/RestaurantMapperTest.java b/src/test/java/com/flab/doorrush/domain/restaurant/dao/RestaurantMapperTest.java index 59f6eaf..b104616 100644 --- a/src/test/java/com/flab/doorrush/domain/restaurant/dao/RestaurantMapperTest.java +++ b/src/test/java/com/flab/doorrush/domain/restaurant/dao/RestaurantMapperTest.java @@ -3,6 +3,7 @@ import static org.junit.jupiter.api.Assertions.*; import com.flab.doorrush.domain.restaurant.domain.Restaurant; +import com.flab.doorrush.domain.restaurant.restaurantEnum.RestaurantCategory; import com.flab.doorrush.domain.user.domain.YnStatus; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -23,7 +24,7 @@ public void insertRestaurantSuccessTest() { // Given Restaurant restaurant = Restaurant.builder() .ownerSeq(5L) - .category("중식") + .category(RestaurantCategory.CHINESE.categoryValue) .openYn(YnStatus.Y) .restaurantName("냠냠식당") .introduction("맛좋습니다.") @@ -53,23 +54,4 @@ public void selectRestaurantByRestaurantSeqTest() { assertEquals(5, restaurant.getAddressSeq()); } - - @Test - @DisplayName("selectRestaurantSeq 성공 테스트 select 결과 restaurantSeq 값 반환 한다.") - public void selectRestaurantSeqTest() { - // Given - Restaurant restaurant = Restaurant.builder() - .ownerSeq(1L) - .category("중식") - .openYn(YnStatus.Y) - .restaurantName("중식중 최고집") - .introduction("증식집 중 최고를 자랑합니다.") - .minimumOrderAmount(12000L) - .addressSeq(5L) - .build(); - - // Then When - Long restaurantSeq = restaurantMapper.selectRestaurantSeq(restaurant); - assertEquals(1, restaurantSeq); - } } \ No newline at end of file diff --git a/src/test/java/com/flab/doorrush/domain/restaurant/restaurantEnum/RestaurantCategoryTest.java b/src/test/java/com/flab/doorrush/domain/restaurant/restaurantEnum/RestaurantCategoryTest.java index ca40af1..1ab6cab 100644 --- a/src/test/java/com/flab/doorrush/domain/restaurant/restaurantEnum/RestaurantCategoryTest.java +++ b/src/test/java/com/flab/doorrush/domain/restaurant/restaurantEnum/RestaurantCategoryTest.java @@ -11,11 +11,11 @@ class RestaurantCategoryTest { @Test public void confirmRestaurantCategoryTest() { - assertEquals("양식", RestaurantCategory.WESTERN.category); - assertEquals("중식", RestaurantCategory.CHINESE.category); - assertEquals("일식", RestaurantCategory.JAPANESE.category); - assertEquals("동남아", RestaurantCategory.SOUTHEAST_ASIAN.category); - assertEquals("분식", RestaurantCategory.SNACK.category); + assertEquals("양식", RestaurantCategory.WESTERN.categoryValue); + assertEquals("중식", RestaurantCategory.CHINESE.categoryValue); + assertEquals("일식", RestaurantCategory.JAPANESE.categoryValue); + assertEquals("동남아", RestaurantCategory.SOUTHEAST_ASIAN.categoryValue); + assertEquals("분식", RestaurantCategory.SNACK.categoryValue); } } \ No newline at end of file diff --git a/src/test/java/com/flab/doorrush/domain/restaurant/service/RestaurantServiceTest.java b/src/test/java/com/flab/doorrush/domain/restaurant/service/RestaurantServiceTest.java index d84e6ad..1426699 100644 --- a/src/test/java/com/flab/doorrush/domain/restaurant/service/RestaurantServiceTest.java +++ b/src/test/java/com/flab/doorrush/domain/restaurant/service/RestaurantServiceTest.java @@ -4,13 +4,11 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertEquals; -import com.flab.doorrush.domain.restaurant.dao.RestaurantMapper; -import com.flab.doorrush.domain.restaurant.domain.Restaurant; import com.flab.doorrush.domain.restaurant.dto.request.AddRestaurantRequest; import com.flab.doorrush.domain.restaurant.dto.request.RestaurantAddressRequest; +import com.flab.doorrush.domain.restaurant.dto.response.AddRestaurantResponse; import com.flab.doorrush.domain.restaurant.exception.AddRestaurantException; import com.flab.doorrush.domain.restaurant.restaurantEnum.RestaurantCategory; -import com.flab.doorrush.domain.user.dao.UserAddressMapper; import com.flab.doorrush.domain.user.domain.YnStatus; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -25,13 +23,8 @@ class RestaurantServiceTest { @Autowired private RestaurantService restaurantService; - @Autowired - private RestaurantMapper restaurantMapper; - - @Autowired - private UserAddressMapper userAddressMapper; - @Test + @DisplayName("addRestaurant 성공 테스트 식당 정보 insert 결과 확인") public void addRestaurantSuccessTest() { // Given RestaurantAddressRequest restaurantAddressRequest = RestaurantAddressRequest.builder() @@ -42,7 +35,7 @@ public void addRestaurantSuccessTest() { AddRestaurantRequest addRestaurantRequest = AddRestaurantRequest.builder() .restaurantAddressRequest(restaurantAddressRequest) - .category(RestaurantCategory.CHINESE.category) + .category(RestaurantCategory.CHINESE) .openYn(YnStatus.N) .restaurantName("맛맛집") .introduction("아주 맛있습니다") @@ -50,25 +43,21 @@ public void addRestaurantSuccessTest() { Long ownerSeq = 1L; // When - restaurantService.addRestaurant(addRestaurantRequest, ownerSeq); + AddRestaurantResponse restaurantResponse = restaurantService.addRestaurant(addRestaurantRequest, + ownerSeq); // Then - Long addressSeq = userAddressMapper.selectAddressSeq(restaurantAddressRequest.toEntity()); - Long restaurantSeq = restaurantMapper.selectRestaurantSeq( - addRestaurantRequest.toEntity(addressSeq, ownerSeq)); - Restaurant restaurant = restaurantMapper.selectRestaurantByRestaurantSeq(restaurantSeq); - assertEquals(restaurantSeq, restaurant.getRestaurantSeq()); - assertEquals(1L, restaurant.getOwnerSeq()); - assertEquals(RestaurantCategory.CHINESE.category, restaurant.getCategory()); - assertEquals(YnStatus.N, restaurant.getOpenYn()); - assertEquals("맛맛집", restaurant.getRestaurantName()); - assertEquals("아주 맛있습니다", restaurant.getIntroduction()); - assertEquals(0L, restaurant.getMinimumOrderAmount()); - assertEquals(addressSeq, restaurant.getAddressSeq()); + assertEquals(1L, restaurantResponse.getRestaurant().getOwnerSeq()); + assertEquals(RestaurantCategory.CHINESE.categoryValue, + restaurantResponse.getRestaurant().getCategory()); + assertEquals(YnStatus.N, restaurantResponse.getRestaurant().getOpenYn()); + assertEquals("맛맛집", restaurantResponse.getRestaurant().getRestaurantName()); + assertEquals("아주 맛있습니다", restaurantResponse.getRestaurant().getIntroduction()); + } @Test - @DisplayName("기존에 저장된 address 정보로 식당 insert 시 AddRestaurantException 발생") + @DisplayName("addRestaurant 실패 테스트 존재하지 않는 사장님 정보로 식당 insert 시 AddRestaurantException 발생") public void addRestaurantFailTest() { // Given RestaurantAddressRequest restaurantAddressRequest = RestaurantAddressRequest.builder() @@ -79,12 +68,12 @@ public void addRestaurantFailTest() { AddRestaurantRequest addRestaurantRequest = AddRestaurantRequest.builder() .restaurantAddressRequest(restaurantAddressRequest) - .category(RestaurantCategory.CHINESE.category) + .category(RestaurantCategory.CHINESE) .openYn(YnStatus.N) .restaurantName("맛맛집") .introduction("아주 맛있습니다") .minimumOrderAmount(0L).build(); - Long ownerSeq = 1L; + Long ownerSeq = 0L; // Then assertThrows(AddRestaurantException.class, () -> diff --git a/src/test/java/com/flab/doorrush/domain/user/dao/UserAddressMapperTest.java b/src/test/java/com/flab/doorrush/domain/user/dao/UserAddressMapperTest.java index 99c8ce1..a227d10 100644 --- a/src/test/java/com/flab/doorrush/domain/user/dao/UserAddressMapperTest.java +++ b/src/test/java/com/flab/doorrush/domain/user/dao/UserAddressMapperTest.java @@ -14,15 +14,5 @@ class UserAddressMapperTest { @Autowired UserAddressMapper userAddressMapper; - @Test - @DisplayName("selectAddressSeq 테스트 select 결과 addressSeq 값을 반환한다.") - void selectAddressSeq() { - // Given - RestaurantAddressRequest restaurantAddressRequest = RestaurantAddressRequest.builder() - .post("13561") - .spotY(37.3595121962).spotX(127.1052208166).addressDetail("301호").build(); - // Then When - assertEquals(1L, userAddressMapper.selectAddressSeq(restaurantAddressRequest.toEntity())); - } } \ No newline at end of file diff --git a/src/test/java/com/flab/doorrush/global/api/KakaoAddressApiTest.java b/src/test/java/com/flab/doorrush/global/api/KakaoAddressApiTest.java index c9bba1b..0d9fc6c 100644 --- a/src/test/java/com/flab/doorrush/global/api/KakaoAddressApiTest.java +++ b/src/test/java/com/flab/doorrush/global/api/KakaoAddressApiTest.java @@ -30,7 +30,7 @@ @ActiveProfiles("test") -@SpringBootTest(webEnvironment = WebEnvironment.NONE) +@SpringBootTest @AutoConfigureWireMock(port = 0) class KakaoAddressApiTest {