From 00df7c78c81df5c7822398bb1e41a8959d645acd Mon Sep 17 00:00:00 2001 From: ksj000625 Date: Sat, 7 Dec 2024 11:49:44 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=EB=94=94=EB=B0=94=EC=9D=B4=EC=8A=A4?= =?UTF-8?q?=20=EC=A0=95=EB=B3=B4=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20?= =?UTF-8?q?API?= 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); + } }