Skip to content

Commit

Permalink
[feat] 디바이스 정보 업데이트 API
Browse files Browse the repository at this point in the history
  • Loading branch information
ksj000625 committed Dec 7, 2024
1 parent 2cb7b6a commit 00df7c7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -116,4 +117,12 @@ public BaseResponse<List<WishlistResponse>> 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<String> updateDevice(@RequestBody DeviceRequest request) {
userService.updateDevice(request);
return new BaseResponse<>(null);
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -24,4 +25,6 @@ public interface UserService {
List<BorrowHistoryResponse> getPostHistory(Pageable pageable, ItemHistoryType type);

List<WishlistResponse> getWishlists(Pageable pageable);

void updateDevice(DeviceRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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() {
Expand Down Expand Up @@ -122,4 +126,19 @@ public List<WishlistResponse> getWishlists(Pageable pageable) {

return itemsRepository.getWishlists(userId, pageable);
}

@Override
public void updateDevice(DeviceRequest request) {
String userId = MDC.get(JWTUtil.MDC_USER_ID);
Optional<UserDeviceJpaEntity> 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);
}
}

0 comments on commit 00df7c7

Please sign in to comment.