From f036055ddc70945e5a64866583c5fdd30abb656e Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Thu, 7 Nov 2024 15:00:17 +0900 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20=EC=A4=91=EB=B3=B5=EC=9C=BC=EB=A1=9C?= =?UTF-8?q?=20=EC=9D=B8=ED=95=9C=20=EC=97=90=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/presentation/AuthController.java | 7 ------- .../application/service/MemberService.java | 20 +------------------ 2 files changed, 1 insertion(+), 26 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/auth/presentation/AuthController.java b/src/main/java/com/ordertogether/team14_be/auth/presentation/AuthController.java index dd8e21be..b7b580e9 100644 --- a/src/main/java/com/ordertogether/team14_be/auth/presentation/AuthController.java +++ b/src/main/java/com/ordertogether/team14_be/auth/presentation/AuthController.java @@ -94,11 +94,4 @@ public ResponseEntity> signUpMember( .headers(headers) .body(ApiResponse.with(HttpStatus.OK, "회원가입 성공", serviceToken)); } - - @PostMapping("/signup") - public ResponseEntity> signUpMember( - @RequestParam String email, @RequestBody MemberInfoRequest memberInfoRequest) { - return authService.register( - email, memberInfoRequest.deliveryName(), memberInfoRequest.phoneNumber()); - } } diff --git a/src/main/java/com/ordertogether/team14_be/member/application/service/MemberService.java b/src/main/java/com/ordertogether/team14_be/member/application/service/MemberService.java index 638cf1d7..50d47f5c 100644 --- a/src/main/java/com/ordertogether/team14_be/member/application/service/MemberService.java +++ b/src/main/java/com/ordertogether/team14_be/member/application/service/MemberService.java @@ -1,5 +1,6 @@ package com.ordertogether.team14_be.member.application.service; +import com.ordertogether.team14_be.auth.JwtUtil; import com.ordertogether.team14_be.member.application.dto.MemberInfoResponse; import com.ordertogether.team14_be.member.application.exception.NotFoundMember; import com.ordertogether.team14_be.member.persistence.MemberRepository; @@ -36,25 +37,6 @@ public MemberInfoResponse findMemberInfo(Long memberId) { .build(); } - @Transactional(readOnly = true) - public Long getMemberId(String email) { - return memberRepository - .findByEmail(email) - .map(Member::getId) - .orElseThrow(() -> new NoSuchElementException("Member with email " + email + " not found")); - } - - @Transactional(readOnly = true) - public MemberInfoResponse findMemberInfo(Long memberId) { - Member member = findMember(memberId); - - return MemberInfoResponse.builder() - .deliveryName(member.getDeliveryName()) - .phoneNumber(member.getPhoneNumber()) - .point(member.getPoint()) - .build(); - } - @Transactional public MemberInfoResponse modifyMember(Long memberId, String deliveryName, String phoneNumber) { Member member = findMember(memberId); From 09ca54fc5807fd03f65ba85d5ca7503e36d61006 Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Thu, 7 Nov 2024 15:01:03 +0900 Subject: [PATCH 2/5] =?UTF-8?q?fix:=20category=EB=A5=BC=20=EC=A0=9C?= =?UTF-8?q?=EC=99=B8=ED=95=9C=20=EB=8B=A4=EB=A5=B8=20=ED=95=84=EB=93=9C?= =?UTF-8?q?=EB=93=A4=EB=8F=84=20=EB=A7=A4=ED=95=91=EB=90=98=EB=8F=84?= =?UTF-8?q?=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 --- .../com/ordertogether/team14_be/spot/mapper/SpotMapper.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/ordertogether/team14_be/spot/mapper/SpotMapper.java b/src/main/java/com/ordertogether/team14_be/spot/mapper/SpotMapper.java index 301724b6..495c1f69 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/mapper/SpotMapper.java +++ b/src/main/java/com/ordertogether/team14_be/spot/mapper/SpotMapper.java @@ -21,12 +21,15 @@ public interface SpotMapper { Spot toEntity(SpotDto spotDto, @MappingTarget Spot spot); // 생성 또는 수정할 때 사용 + @BeanMapping(ignoreByDefault = false) // 자동 매핑 활성화 @Mapping(target = "category", expression = "java(spotDto.getCategory().getCode())") SpotCreationResponse toSpotCreationResponse(SpotDto spotDto); + @BeanMapping(ignoreByDefault = false) // 자동 매핑 활성화 @Mapping(target = "category", expression = "java(spotDto.getCategory().getCode())") SpotDetailResponse toSpotDetailResponse(SpotDto spotDto); + @BeanMapping(ignoreByDefault = false) // 자동 매핑 활성화 @Mapping(target = "category", expression = "java(spotDto.getCategory().getCode())") SpotViewedResponse toSpotViewedResponse(SpotDto spotDto); From 05463c5f076f4b4f4f3d0bfa91dfecb494279b9a Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Thu, 7 Nov 2024 15:01:44 +0900 Subject: [PATCH 3/5] =?UTF-8?q?refactor:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spot/unit/SpotRepositoryTest.java | 40 +++++++++++++++++-- .../team14_be/spot/unit/SpotServiceTest.java | 18 ++++----- 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/src/test/java/com/ordertogether/team14_be/spot/unit/SpotRepositoryTest.java b/src/test/java/com/ordertogether/team14_be/spot/unit/SpotRepositoryTest.java index 1928434c..73490d23 100644 --- a/src/test/java/com/ordertogether/team14_be/spot/unit/SpotRepositoryTest.java +++ b/src/test/java/com/ordertogether/team14_be/spot/unit/SpotRepositoryTest.java @@ -8,16 +8,19 @@ import com.ordertogether.team14_be.spot.entity.Spot; import com.ordertogether.team14_be.spot.enums.Category; import com.ordertogether.team14_be.spot.exception.SpotNotFoundException; +import com.ordertogether.team14_be.spot.mapper.SpotMapper; import com.ordertogether.team14_be.spot.repository.SimpleSpotRepository; import com.ordertogether.team14_be.spot.repository.SpotRepository; import java.math.BigDecimal; import java.time.LocalTime; +import java.util.List; import java.util.Optional; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) @@ -27,6 +30,8 @@ class SpotRepositoryTest { @Mock private SimpleSpotRepository simpleSpotRepository; + @Spy private SpotMapper spotMapper; + private BigDecimal lat; private BigDecimal lng; private Spot spot; @@ -87,10 +92,39 @@ void findByIdAndIsDeletedFalse_success() { @Test void findByIdAndIsDeletedFalse_exception() { when(simpleSpotRepository.findByIdAndIsDeletedFalse(1L)).thenReturn(Optional.empty()); - // todo: 테스트 추가 - assertThat(spotRepository.findByIdAndIsDeletedFalse(1L)).isNull(); + assertThrows(SpotNotFoundException.class, () -> spotRepository.findByIdAndIsDeletedFalse(1L)); } - // todo : 테스트 추가 + @Test + void findByLatAndLngAndIsDeletedFalse_success() { + when(simpleSpotRepository.findByLatAndLngAndIsDeletedFalse(lat, lng)).thenReturn(List.of(spot)); + + List spotDto = spotRepository.findByLatAndLngAndIsDeletedFalse(lat, lng); + assertThat(spotDto.getFirst().getId()).isEqualTo(1L); + assertThat(spotDto.getFirst().getLat()).isEqualTo(lat); + assertThat(spotDto.getFirst().getLng()).isEqualTo(lng); + assertThat(spotDto.getFirst().getCategory()).isEqualTo(Category.BURGER); + assertThat(spotDto.getFirst().getStoreName()).isEqualTo("맥도날드"); + assertThat(spotDto.getFirst().getMinimumOrderAmount()).isEqualTo(12000); + assertThat(spotDto.getFirst().getDeadlineTime()).isEqualTo(LocalTime.of(12, 0, 0)); + assertThat(spotDto.getFirst().getPickUpLocation()).isEqualTo("픽업위치"); + assertThat(spotDto.getFirst().getCreatedBy()).isEqualTo(1L); + } + + @Test + void findBygeoHash_success() { + when(simpleSpotRepository.findByGeoHash("9q8yyz")).thenReturn(List.of(spot)); + + List spotDto = spotRepository.findBygeoHash("9q8yyz"); + assertThat(spotDto.getFirst().getId()).isEqualTo(1L); + assertThat(spotDto.getFirst().getLat()).isEqualTo(lat); + assertThat(spotDto.getFirst().getLng()).isEqualTo(lng); + assertThat(spotDto.getFirst().getCategory()).isEqualTo(Category.BURGER); + assertThat(spotDto.getFirst().getStoreName()).isEqualTo("맥도날드"); + assertThat(spotDto.getFirst().getMinimumOrderAmount()).isEqualTo(12000); + assertThat(spotDto.getFirst().getDeadlineTime()).isEqualTo(LocalTime.of(12, 0, 0)); + assertThat(spotDto.getFirst().getPickUpLocation()).isEqualTo("픽업위치"); + assertThat(spotDto.getFirst().getCreatedBy()).isEqualTo(1L); + } } diff --git a/src/test/java/com/ordertogether/team14_be/spot/unit/SpotServiceTest.java b/src/test/java/com/ordertogether/team14_be/spot/unit/SpotServiceTest.java index ea2234d2..d22936e4 100644 --- a/src/test/java/com/ordertogether/team14_be/spot/unit/SpotServiceTest.java +++ b/src/test/java/com/ordertogether/team14_be/spot/unit/SpotServiceTest.java @@ -11,7 +11,6 @@ import com.ordertogether.team14_be.spot.entity.Spot; import com.ordertogether.team14_be.spot.enums.Category; import com.ordertogether.team14_be.spot.exception.NotSpotMasterException; -import com.ordertogether.team14_be.spot.mapper.SpotMapper; import com.ordertogether.team14_be.spot.repository.SpotRepository; import com.ordertogether.team14_be.spot.service.SpotService; import java.math.BigDecimal; @@ -22,7 +21,6 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) @@ -30,8 +28,6 @@ class SpotServiceTest { @Mock private SpotRepository spotRepository; - @Spy private SpotMapper spotMapper; - @InjectMocks private SpotService spotService; private BigDecimal lat; @@ -65,6 +61,7 @@ void getSpot_success() { List result = spotService.getSpot(lat, lng); assertNotNull(result); + assertEquals(1, result.size()); assertEquals("패스트푸드", result.getFirst().category()); assertEquals("맥도날드", result.getFirst().storeName()); assertEquals(12000, result.getFirst().minimumOrderAmount()); @@ -74,16 +71,19 @@ void getSpot_success() { @Test void createSpot_success() { - SpotCreationResponse expectedResponse = - new SpotCreationResponse(1L, "패스트푸드", "맥도날드", 12000, "픽업위치", LocalTime.of(12, 0, 0)); - - // Mocking the repository and mapper responses when(spotRepository.save(any(Spot.class))).thenReturn(spotDto); SpotCreationResponse response = spotService.createSpot(spotDto); assertNotNull(response); - assertEquals(expectedResponse, response); + System.out.println(response); + assertEquals(spotDto.getId(), response.id()); + assertEquals(spotDto.getCategory().getCode(), response.category()); + assertEquals(spotDto.getStoreName(), response.storeName()); + assertEquals(spotDto.getMinimumOrderAmount(), response.minimumOrderAmount()); + assertEquals(spotDto.getPickUpLocation(), response.pickUpLocation()); + assertEquals(spotDto.getDeadlineTime(), response.deadlineTime()); + verify(spotRepository).save(any(Spot.class)); } From 3bfc4d489cc95e0eafc99457826827119e93925e Mon Sep 17 00:00:00 2001 From: rbm0524 Date: Fri, 8 Nov 2024 01:52:21 +0900 Subject: [PATCH 4/5] =?UTF-8?q?refactor:=20dialect=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 249b0064..b2603de4 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -13,6 +13,7 @@ spring: properties: hibernate: format_sql: true + dialect: org.hibernate.dialect.MySQL8Dialect defer-datasource-initialization: true sql: From 0e13e5f5e101c180a5bbb275e6a6a4a21ca3c659 Mon Sep 17 00:00:00 2001 From: rbm0524 Date: Fri, 8 Nov 2024 01:53:16 +0900 Subject: [PATCH 5/5] =?UTF-8?q?feat:=20Category.class=EB=A5=BC=20AbstractC?= =?UTF-8?q?odedEnumConverter=EC=97=90=20=EC=A0=84=EB=8B=AC=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spot/converter/CategoryConverter.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/spot/converter/CategoryConverter.java diff --git a/src/main/java/com/ordertogether/team14_be/spot/converter/CategoryConverter.java b/src/main/java/com/ordertogether/team14_be/spot/converter/CategoryConverter.java new file mode 100644 index 00000000..4d233bc2 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/spot/converter/CategoryConverter.java @@ -0,0 +1,14 @@ +package com.ordertogether.team14_be.spot.converter; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import com.ordertogether.team14_be.spot.enums.Category; + +@Component +public class CategoryConverter extends AbstractCodedEnumConverter { + + @Autowired + public CategoryConverter(Class clazz) { + super(clazz); // Category.class를 부모 클래스에 전달 + } +}