diff --git a/src/main/java/com/bit/lotte/flower/user/common/exception/GlobalExceptionHandler.java b/src/main/java/com/bit/lotte/flower/user/common/exception/GlobalExceptionHandler.java new file mode 100644 index 0000000..a09c50b --- /dev/null +++ b/src/main/java/com/bit/lotte/flower/user/common/exception/GlobalExceptionHandler.java @@ -0,0 +1,68 @@ +package com.bit.lotte.flower.user.common.exception; + +import com.bit.lotte.flower.user.social.exception.SocialUserDomainException; +import com.bit.lotte.flower.user.store.exception.StoreUserDomainException; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.FieldError; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@RestControllerAdvice +public class GlobalExceptionHandler { + + @ExceptionHandler(MethodArgumentNotValidException.class) + public ResponseEntity>> handleValidationErrors( + MethodArgumentNotValidException ex) { + List errors = ex.getBindingResult().getFieldErrors() + .stream().map(FieldError::getDefaultMessage).collect(Collectors.toList()); + return new ResponseEntity<>(getErrorsMap(errors), new HttpHeaders(), HttpStatus.BAD_REQUEST); + } + + private Map> getErrorsMap(List errors) { + Map> errorResponse = new HashMap<>(); + errorResponse.put("errors", errors); + return errorResponse; + } + + + + @ExceptionHandler(SocialUserDomainException.class) + public ResponseEntity>> emailCodeException( + SocialUserDomainException ex) { + List errors = Collections.singletonList(ex.getMessage()); + return new ResponseEntity<>(getErrorsMap(errors), new HttpHeaders(), HttpStatus.BAD_REQUEST); + } + @ExceptionHandler(StoreUserDomainException.class) + public ResponseEntity>> storeManagerException( + StoreUserDomainException ex) { + List errors = Collections.singletonList(ex.getMessage()); + return new ResponseEntity<>(getErrorsMap(errors), new HttpHeaders(), HttpStatus.BAD_REQUEST); + } + + + + @ExceptionHandler(Exception.class) + public final ResponseEntity>> handleGeneralExceptions(Exception ex) { + List errors = Collections.singletonList(ex.getMessage()); + return new ResponseEntity<>(getErrorsMap(errors), new HttpHeaders(), + HttpStatus.INTERNAL_SERVER_ERROR); + } + + @ExceptionHandler(RuntimeException.class) + public final ResponseEntity>> handleRuntimeExceptions( + RuntimeException ex) { + List errors = Collections.singletonList(ex.getMessage()); + return new ResponseEntity<>(getErrorsMap(errors), new HttpHeaders(), + HttpStatus.INTERNAL_SERVER_ERROR); + } + + +} \ No newline at end of file diff --git a/src/main/java/com/bit/lotte/flower/user/social/dto/response/UserDataDto.java b/src/main/java/com/bit/lotte/flower/user/social/dto/response/UserDataDto.java index 34f60bf..5e86e06 100644 --- a/src/main/java/com/bit/lotte/flower/user/social/dto/response/UserDataDto.java +++ b/src/main/java/com/bit/lotte/flower/user/social/dto/response/UserDataDto.java @@ -14,6 +14,8 @@ public class UserDataDto { private String nickname; private String phoneNumber; private String email; + private String profileImage; + } diff --git a/src/main/java/com/bit/lotte/flower/user/social/http/feign/UserLikesFeignRequest.java b/src/main/java/com/bit/lotte/flower/user/social/http/feign/UserLikesFeignRequest.java index a55295a..3a9b26f 100644 --- a/src/main/java/com/bit/lotte/flower/user/social/http/feign/UserLikesFeignRequest.java +++ b/src/main/java/com/bit/lotte/flower/user/social/http/feign/UserLikesFeignRequest.java @@ -5,8 +5,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestHeader; - -@FeignClient(name = "get-user-likes-cnt", value = "${service.likes.domain}") +@FeignClient(name = "get-user-likes-cnt", url = "${service.likes.domain}") public interface UserLikesFeignRequest { @GetMapping("/likes-cnt") diff --git a/src/main/java/com/bit/lotte/flower/user/social/http/feign/UserUsableCouponCntFeignRequest.java b/src/main/java/com/bit/lotte/flower/user/social/http/feign/UserUsableCouponCntFeignRequest.java index a8c8eb4..ea59977 100644 --- a/src/main/java/com/bit/lotte/flower/user/social/http/feign/UserUsableCouponCntFeignRequest.java +++ b/src/main/java/com/bit/lotte/flower/user/social/http/feign/UserUsableCouponCntFeignRequest.java @@ -5,7 +5,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestHeader; -@FeignClient(name = "get-user-usable-coupon-cnt", value = "${service.coupon.domain}") +@FeignClient(name = "get-user-usable-coupon-cnt", url = "${service.coupon.domain}") public interface UserUsableCouponCntFeignRequest { @GetMapping("/coupons/count") ResponseEntity getUsableUserCouponCnt(@RequestHeader Long userId); diff --git a/src/main/java/com/bit/lotte/flower/user/social/mapper/SocialUserMapper.java b/src/main/java/com/bit/lotte/flower/user/social/mapper/SocialUserMapper.java index 444b21c..c3b0508 100644 --- a/src/main/java/com/bit/lotte/flower/user/social/mapper/SocialUserMapper.java +++ b/src/main/java/com/bit/lotte/flower/user/social/mapper/SocialUserMapper.java @@ -40,7 +40,7 @@ public static UserLoginDataResponse createUserLoginCommandBySocialUser(String pr public static UserDataDto socialUserToUserMyPageDataResponse(SocialUser socialUser) { return UserDataDto.builder() - .email(socialUser.getEmail()).nickname(socialUser.getNickname()) + .email(socialUser.getEmail()).nickname(socialUser.getNickname()).profileImage(socialUser.getProfileImage()) .phoneNumber(socialUser.getPhoneNumber()).build(); } diff --git a/src/main/java/com/bit/lotte/flower/user/store/http/feign/InitStoreManagerStatusPendingFeignRequest.java b/src/main/java/com/bit/lotte/flower/user/store/http/feign/InitStoreManagerStatusPendingFeignRequest.java index 9ed7d15..c49c772 100644 --- a/src/main/java/com/bit/lotte/flower/user/store/http/feign/InitStoreManagerStatusPendingFeignRequest.java +++ b/src/main/java/com/bit/lotte/flower/user/store/http/feign/InitStoreManagerStatusPendingFeignRequest.java @@ -1,10 +1,12 @@ package com.bit.lotte.flower.user.store.http.feign; -import com.bit.lotte.flower.user.common.valueobject.BaseId; +import com.bit.lotte.flower.user.store.http.feign.dto.UpdateStoreManagerPendingStausDto; import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.RequestBody; -@FeignClient(name = "init-storemanager-status",value = "${service.auth.domain}") -public interface InitStoreManagerStatusPendingFeignRequest { - public void publish(@RequestHeader ID userId); +@FeignClient(name = "init-storemanager-status",url = "${service.auth.domain}") +public interface InitStoreManagerStatusPendingFeignRequest { + @PatchMapping("/admin/store-manager") + public void publish(@RequestBody UpdateStoreManagerPendingStausDto dto); } diff --git a/src/main/java/com/bit/lotte/flower/user/store/http/feign/dto/UpdateStoreManagerPendingStausDto.java b/src/main/java/com/bit/lotte/flower/user/store/http/feign/dto/UpdateStoreManagerPendingStausDto.java new file mode 100644 index 0000000..2bd96c2 --- /dev/null +++ b/src/main/java/com/bit/lotte/flower/user/store/http/feign/dto/UpdateStoreManagerPendingStausDto.java @@ -0,0 +1,19 @@ +package com.bit.lotte.flower.user.store.http.feign.dto; + +import javax.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Getter +public class UpdateStoreManagerPendingStausDto { + + @NotNull + private final String status = "ROLE_STORE_MANAGER_PENDING"; + @NotNull + private Long storeManagerId; +} diff --git a/src/main/java/com/bit/lotte/flower/user/store/http/message/InitStoreManagerAuthorizationPublisherImpl.java b/src/main/java/com/bit/lotte/flower/user/store/http/message/InitStoreManagerAuthorizationPublisherImpl.java index 2df595a..dca5c70 100644 --- a/src/main/java/com/bit/lotte/flower/user/store/http/message/InitStoreManagerAuthorizationPublisherImpl.java +++ b/src/main/java/com/bit/lotte/flower/user/store/http/message/InitStoreManagerAuthorizationPublisherImpl.java @@ -2,6 +2,7 @@ import com.bit.lotte.flower.user.common.valueobject.UserId; import com.bit.lotte.flower.user.store.http.feign.InitStoreManagerStatusPendingFeignRequest; +import com.bit.lotte.flower.user.store.http.feign.dto.UpdateStoreManagerPendingStausDto; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -10,11 +11,10 @@ public class InitStoreManagerAuthorizationPublisherImpl implements InitStoreManagerAuthorizationPublisher { - private final InitStoreManagerStatusPendingFeignRequest request; - + private final InitStoreManagerStatusPendingFeignRequest request; @Override public void publish(UserId storeManagerId) { - request.publish(storeManagerId); + request.publish(new UpdateStoreManagerPendingStausDto(storeManagerId.getValue())); } } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 4a4a372..49c4038 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -6,23 +6,12 @@ spring: config: activate: on-profile: dev - import: optional:configserver:http://localhost:8888 + import: optional:configserver:http://config-service:8888 - jpa: - show-sql: true - hibernate: - ddl-auto: update - -feign: - client: - config: - default: - connectTimeout: 5000 - readTimeout: 5000 - loggerLevel: basic - -service: - coupon: - domain : ${service.coupon.domain} - likes: - domain : ${servive.likes.domain} \ No newline at end of file +management: + endpoints: + web: + exposure: + include: + - "refresh" + - "bus-refresh" diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 5eeb0e3..0820760 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -1,30 +1,26 @@ +server: + port: 8600 + spring: config: activate: on-profile: local datasource: - url: jdbc:mysql://localhost:3306/bb-user-service?serverTimezone=Asia/Seoul + url: jdbc:mysql://localhost:3306/develop?serverTimezone=Asia/Seoul&useUnicode=true&characterEncoding=utf8 username: root - password: k1651227 + password: 123456 driver-class-name: com.mysql.cj.jdbc.Driver jpa: hibernate: ddl-auto: update show-sql: true -feign: - client: - default: - url: http://localhost:8082 - config: - default: - connectTimeout: 5000 - readTimeout: 5000 - loggerLevel: basic service: coupon: - domain : ${service.coupon.domain} + domain : http://localhost:9999 likes: - domain : ${servive.likes.domain} \ No newline at end of file + domain : http://localhost:8888 + auth: + domain : http://localhost:9000 \ No newline at end of file diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 1f73b66..0ac027e 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -11,7 +11,7 @@ spring: jpa: show-sql: true hibernate: - ddl-auto: update + ddl-auto: none feign: client: diff --git a/src/test/java/com/bit/lotte/flower/user/store/service/auth/StoreManagerLoginResponseTest.java b/src/test/java/com/bit/lotte/flower/user/store/service/auth/StoreManagerLoginResponseTest.java index a2047d1..d921f37 100644 --- a/src/test/java/com/bit/lotte/flower/user/store/service/auth/StoreManagerLoginResponseTest.java +++ b/src/test/java/com/bit/lotte/flower/user/store/service/auth/StoreManagerLoginResponseTest.java @@ -12,6 +12,7 @@ import com.bit.lotte.flower.user.store.entity.StoreManager; import com.bit.lotte.flower.user.store.exception.StoreUserDomainException; import com.bit.lotte.flower.user.store.repository.StoreManagerJpaRepository; +import com.bit.lotte.flower.user.store.service.FindStoreMangerByLongIdService; import com.bit.lotte.flower.user.store.service.StoreManagerLoginResponseService; import java.util.Optional; import org.junit.jupiter.api.DisplayName; @@ -25,10 +26,13 @@ @ExtendWith(MockitoExtension.class) class StoreManagerLoginResponseTest { - @InjectMocks - StoreManagerLoginResponseService loginResponseService; @Mock StoreManagerJpaRepository repository; + @Mock + FindStoreMangerByLongIdService findStoreMangerByLongIdService; + @InjectMocks + StoreManagerLoginResponseService loginResponseService; + private final Long validStoreManagerId = 1L; @@ -40,7 +44,7 @@ private StoreManager initUser() { @DisplayName("스토어 매니저 로그인시 유저가 존재할 때 유저 네임 반환") @Test void UserNameResponse_WhenUserIsExist_GetUserName() { - when(repository.findById(validStoreManagerId)).thenReturn(Optional.of(initUser())); + when(findStoreMangerByLongIdService.findByLongId(validStoreManagerId)).thenReturn(initUser()); StoreManagerLoginResponse response = loginResponseService.getStoreManagerResponse( validStoreManagerId); @@ -51,8 +55,7 @@ void UserNameResponse_WhenUserIsExist_GetUserName() { @Test void UserNameResponse_WhenUserIsExist_ThrowStoreUserDomainException() { - when(repository.findById(anyLong())).thenReturn(Optional.empty()); - +when(findStoreMangerByLongIdService.findByLongId(validStoreManagerId)).thenThrow(StoreUserDomainException.class); assertThrows(StoreUserDomainException.class, () -> { loginResponseService.getStoreManagerResponse(validStoreManagerId); }); diff --git a/src/test/java/com/bit/lotte/flower/user/store/service/FindStoreMangerByLongIdServiceTest.java b/src/test/java/com/bit/lotte/flower/user/store/service/mypage/FindStoreMangerByLongIdServiceTest.java similarity index 92% rename from src/test/java/com/bit/lotte/flower/user/store/service/FindStoreMangerByLongIdServiceTest.java rename to src/test/java/com/bit/lotte/flower/user/store/service/mypage/FindStoreMangerByLongIdServiceTest.java index aaf9a02..ec9ee6e 100644 --- a/src/test/java/com/bit/lotte/flower/user/store/service/FindStoreMangerByLongIdServiceTest.java +++ b/src/test/java/com/bit/lotte/flower/user/store/service/mypage/FindStoreMangerByLongIdServiceTest.java @@ -1,4 +1,4 @@ -package com.bit.lotte.flower.user.store.service; +package com.bit.lotte.flower.user.store.service.mypage; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -11,6 +11,7 @@ import com.bit.lotte.flower.user.store.entity.StoreManager; import com.bit.lotte.flower.user.store.exception.StoreUserDomainException; import com.bit.lotte.flower.user.store.repository.StoreManagerJpaRepository; +import com.bit.lotte.flower.user.store.service.FindStoreMangerByLongIdService; import java.util.Optional; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; diff --git a/src/test/java/com/bit/lotte/flower/user/store/service/StoreManagerServiceImplTest.java b/src/test/java/com/bit/lotte/flower/user/store/service/mypage/StoreManagerServiceImplTest.java similarity index 90% rename from src/test/java/com/bit/lotte/flower/user/store/service/StoreManagerServiceImplTest.java rename to src/test/java/com/bit/lotte/flower/user/store/service/mypage/StoreManagerServiceImplTest.java index be7fd12..aecbbb0 100644 --- a/src/test/java/com/bit/lotte/flower/user/store/service/StoreManagerServiceImplTest.java +++ b/src/test/java/com/bit/lotte/flower/user/store/service/mypage/StoreManagerServiceImplTest.java @@ -1,4 +1,4 @@ -package com.bit.lotte.flower.user.store.service; +package com.bit.lotte.flower.user.store.service.mypage; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; @@ -14,6 +14,8 @@ import com.bit.lotte.flower.user.store.entity.StoreManager; import com.bit.lotte.flower.user.store.exception.StoreUserDomainException; import com.bit.lotte.flower.user.store.repository.StoreManagerJpaRepository; +import com.bit.lotte.flower.user.store.service.FindStoreMangerByLongIdService; +import com.bit.lotte.flower.user.store.service.StoreManagerServiceImpl; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks;