From 2cb7b6ab84f2d1220c03273f36d92966104803c2 Mon Sep 17 00:00:00 2001 From: ksj000625 Date: Sat, 7 Dec 2024 11:14:37 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[feat]=20=EB=8B=89=EB=84=A4=EC=9E=84=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=EA=B2=80=EC=82=AC=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/auth/controller/AuthController.java | 13 +++++++++++++ .../api/auth/dto/response/NicknameResponse.java | 10 ++++++++++ .../apiserver/api/auth/service/AuthService.java | 2 ++ .../apiserver/api/auth/service/AuthServiceImpl.java | 5 +++++ .../apiserver/repository/user/UserRepository.java | 1 + 5 files changed, 31 insertions(+) create mode 100644 src/main/java/site/billbill/apiserver/api/auth/dto/response/NicknameResponse.java diff --git a/src/main/java/site/billbill/apiserver/api/auth/controller/AuthController.java b/src/main/java/site/billbill/apiserver/api/auth/controller/AuthController.java index dfd927c..bfac926 100644 --- a/src/main/java/site/billbill/apiserver/api/auth/controller/AuthController.java +++ b/src/main/java/site/billbill/apiserver/api/auth/controller/AuthController.java @@ -11,8 +11,10 @@ import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import site.billbill.apiserver.api.auth.dto.request.*; +import site.billbill.apiserver.api.auth.dto.response.NicknameResponse; import site.billbill.apiserver.api.auth.service.AuthService; import site.billbill.apiserver.api.auth.service.OAuthService; +import site.billbill.apiserver.api.users.service.UserService; import site.billbill.apiserver.common.response.BaseResponse; import site.billbill.apiserver.common.utils.jwt.dto.JwtDto; @@ -30,6 +32,7 @@ public class AuthController { private final AuthService authService; private final OAuthService oAuthService; + private final UserService userService; @Operation(summary = "회원 가입(일반)", description = "일반 회원 가입 API") @ResponseStatus(HttpStatus.CREATED) @@ -64,4 +67,14 @@ public BaseResponse kakaoCallback(@RequestParam("code") String code) { public BaseResponse identity(@RequestBody IdentityVerificationRequest request) { return null; } + + @Operation(summary = "닉네임 중복검사", description = "닉네임 중복검사") + @ResponseStatus(HttpStatus.OK) + @GetMapping("/nickname") + public BaseResponse getNicknameValidity(@RequestParam String nickname) { + return new BaseResponse<>(NicknameResponse.builder() + .valid(authService.getNicknameValidity(nickname)) + .build()); + } + } diff --git a/src/main/java/site/billbill/apiserver/api/auth/dto/response/NicknameResponse.java b/src/main/java/site/billbill/apiserver/api/auth/dto/response/NicknameResponse.java new file mode 100644 index 0000000..38d8087 --- /dev/null +++ b/src/main/java/site/billbill/apiserver/api/auth/dto/response/NicknameResponse.java @@ -0,0 +1,10 @@ +package site.billbill.apiserver.api.auth.dto.response; + +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class NicknameResponse { + private boolean valid; +} diff --git a/src/main/java/site/billbill/apiserver/api/auth/service/AuthService.java b/src/main/java/site/billbill/apiserver/api/auth/service/AuthService.java index 14667f6..54060ef 100644 --- a/src/main/java/site/billbill/apiserver/api/auth/service/AuthService.java +++ b/src/main/java/site/billbill/apiserver/api/auth/service/AuthService.java @@ -13,4 +13,6 @@ public interface AuthService { JwtDto reissue(String refreshToken); boolean identifyUser(IdentityRequest request); + + boolean getNicknameValidity(String nickname); } diff --git a/src/main/java/site/billbill/apiserver/api/auth/service/AuthServiceImpl.java b/src/main/java/site/billbill/apiserver/api/auth/service/AuthServiceImpl.java index b234eff..960b724 100644 --- a/src/main/java/site/billbill/apiserver/api/auth/service/AuthServiceImpl.java +++ b/src/main/java/site/billbill/apiserver/api/auth/service/AuthServiceImpl.java @@ -118,6 +118,11 @@ public boolean identifyUser(IdentityRequest request) { return false; } + @Override + public boolean getNicknameValidity(String nickname) { + return !userRepository.existsByNickname(nickname); + } + /** * Method that if user is withdrawn * diff --git a/src/main/java/site/billbill/apiserver/repository/user/UserRepository.java b/src/main/java/site/billbill/apiserver/repository/user/UserRepository.java index 9e56503..c5c0d37 100644 --- a/src/main/java/site/billbill/apiserver/repository/user/UserRepository.java +++ b/src/main/java/site/billbill/apiserver/repository/user/UserRepository.java @@ -10,4 +10,5 @@ public interface UserRepository extends JpaRepository, UserDslRepository { Optional findByUserIdAndWithdrawStatus(String userId, boolean withdrawStatus); Optional findByProviderId(String providerId); + boolean existsByNickname(String nickname); } From 00df7c78c81df5c7822398bb1e41a8959d645acd Mon Sep 17 00:00:00 2001 From: ksj000625 Date: Sat, 7 Dec 2024 11:49:44 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[feat]=20=EB=94=94=EB=B0=94=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=20=EC=A0=95=EB=B3=B4=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/users/controller/UserController.java | 9 +++++++++ .../api/users/service/UserService.java | 3 +++ .../api/users/service/UserServiceImpl.java | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/main/java/site/billbill/apiserver/api/users/controller/UserController.java b/src/main/java/site/billbill/apiserver/api/users/controller/UserController.java index 5bdb533..5164c53 100644 --- a/src/main/java/site/billbill/apiserver/api/users/controller/UserController.java +++ b/src/main/java/site/billbill/apiserver/api/users/controller/UserController.java @@ -12,6 +12,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; +import site.billbill.apiserver.api.auth.dto.request.DeviceRequest; import site.billbill.apiserver.api.users.dto.request.BlacklistRequest; import site.billbill.apiserver.api.users.dto.response.*; import site.billbill.apiserver.api.users.service.UserService; @@ -116,4 +117,12 @@ public BaseResponse> getWishlists( Pageable pageable = PageRequest.of((page < 1 ? 0 : page - 1), size); return new BaseResponse<>(userService.getWishlists(pageable)); } + + @Operation(summary = "내 디바이스 업데이트", description = "내 디바이스 정보를 업데이트하는 API") + @ResponseStatus(HttpStatus.OK) + @PostMapping("/device") + public BaseResponse updateDevice(@RequestBody DeviceRequest request) { + userService.updateDevice(request); + return new BaseResponse<>(null); + } } diff --git a/src/main/java/site/billbill/apiserver/api/users/service/UserService.java b/src/main/java/site/billbill/apiserver/api/users/service/UserService.java index 83d6f11..6f5c93f 100644 --- a/src/main/java/site/billbill/apiserver/api/users/service/UserService.java +++ b/src/main/java/site/billbill/apiserver/api/users/service/UserService.java @@ -1,6 +1,7 @@ package site.billbill.apiserver.api.users.service; import org.springframework.data.domain.Pageable; +import site.billbill.apiserver.api.auth.dto.request.DeviceRequest; import site.billbill.apiserver.api.users.dto.response.*; import site.billbill.apiserver.common.utils.posts.ItemHistoryType; @@ -24,4 +25,6 @@ public interface UserService { List getPostHistory(Pageable pageable, ItemHistoryType type); List getWishlists(Pageable pageable); + + void updateDevice(DeviceRequest request); } diff --git a/src/main/java/site/billbill/apiserver/api/users/service/UserServiceImpl.java b/src/main/java/site/billbill/apiserver/api/users/service/UserServiceImpl.java index 974c199..b0b2b04 100644 --- a/src/main/java/site/billbill/apiserver/api/users/service/UserServiceImpl.java +++ b/src/main/java/site/billbill/apiserver/api/users/service/UserServiceImpl.java @@ -7,16 +7,19 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import site.billbill.apiserver.api.auth.dto.request.DeviceRequest; import site.billbill.apiserver.api.users.dto.response.*; import site.billbill.apiserver.common.enums.exception.ErrorCode; import site.billbill.apiserver.common.utils.jwt.JWTUtil; import site.billbill.apiserver.common.utils.posts.ItemHistoryType; import site.billbill.apiserver.exception.CustomException; import site.billbill.apiserver.model.user.UserBlacklistJpaEntity; +import site.billbill.apiserver.model.user.UserDeviceJpaEntity; import site.billbill.apiserver.model.user.UserIdentityJpaEntity; import site.billbill.apiserver.model.user.UserJpaEntity; import site.billbill.apiserver.repository.borrowPosts.ItemsRepository; import site.billbill.apiserver.repository.user.UserBlacklistRepository; +import site.billbill.apiserver.repository.user.UserDeviceRepository; import site.billbill.apiserver.repository.user.UserIdentityRepository; import site.billbill.apiserver.repository.user.UserRepository; @@ -32,6 +35,7 @@ public class UserServiceImpl implements UserService { private final UserBlacklistRepository userBlacklistRepository; private final ItemsRepository itemsRepository; private final JWTUtil jWTUtil; + private final UserDeviceRepository userDeviceRepository; @Override public ProfileResponse getProfileInfo() { @@ -122,4 +126,19 @@ public List getWishlists(Pageable pageable) { return itemsRepository.getWishlists(userId, pageable); } + + @Override + public void updateDevice(DeviceRequest request) { + String userId = MDC.get(JWTUtil.MDC_USER_ID); + Optional userDeviceOptional = userDeviceRepository.findById(userId); + + if(userDeviceOptional.isEmpty()) throw new CustomException(ErrorCode.NotFound, "디바이스 정보가 존재하지 않습니다.", HttpStatus.NOT_FOUND); + + UserDeviceJpaEntity userDevice = userDeviceOptional.get(); + + userDevice.setDeviceToken(request.getDeviceToken()); + userDevice.setDeviceType(request.getDeviceType()); + userDevice.setAppVersion(request.getAppVersion()); + userDeviceRepository.save(userDevice); + } }