Skip to content

Commit

Permalink
Merge pull request #74 from billbill-project/feature/auth
Browse files Browse the repository at this point in the history
Feature/auth
  • Loading branch information
ksj000625 authored Dec 7, 2024
2 parents abf6f1f + 00df7c7 commit 74a822c
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down Expand Up @@ -64,4 +67,14 @@ public BaseResponse<JwtDto> kakaoCallback(@RequestParam("code") String code) {
public BaseResponse<JwtDto> identity(@RequestBody IdentityVerificationRequest request) {
return null;
}

@Operation(summary = "닉네임 중복검사", description = "닉네임 중복검사")
@ResponseStatus(HttpStatus.OK)
@GetMapping("/nickname")
public BaseResponse<NicknameResponse> getNicknameValidity(@RequestParam String nickname) {
return new BaseResponse<>(NicknameResponse.builder()
.valid(authService.getNicknameValidity(nickname))
.build());
}

}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface AuthService {
JwtDto reissue(String refreshToken);

boolean identifyUser(IdentityRequest request);

boolean getNicknameValidity(String nickname);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
public interface UserRepository extends JpaRepository<UserJpaEntity, String>, UserDslRepository {
Optional<UserJpaEntity> findByUserIdAndWithdrawStatus(String userId, boolean withdrawStatus);
Optional<UserJpaEntity> findByProviderId(String providerId);
boolean existsByNickname(String nickname);
}

0 comments on commit 74a822c

Please sign in to comment.