Skip to content

Commit

Permalink
[fix] 닉네임 생성 조건 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hysong4u committed Apr 16, 2024
1 parent 9eb7e70 commit 0b4946e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@

import com.example.comma.domain.user.dto.response.LoginResponseDto;
import com.example.comma.domain.user.dto.response.UserInfoResponseDto;
import com.example.comma.domain.user.entity.User;
import com.example.comma.domain.user.repository.UserRepository;
import com.example.comma.domain.user.service.OauthService;
import com.example.comma.domain.user.service.UserService;
import com.example.comma.global.common.SuccessResponse;

import com.example.comma.global.error.ErrorCode;
import com.example.comma.global.error.exception.EntityNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -17,16 +21,22 @@ public class OauthController {

private final OauthService oauthService;
private final UserService userService;
private final UserRepository userRepository;

@GetMapping("/code/{registrationId}")
@PostMapping("/code/{registrationId}")
ResponseEntity<SuccessResponse<?>> googleLogin(@RequestParam (name = "code") String code, @PathVariable (name = "registrationId") String registrationId) {

Long userId = oauthService.socialLogin(code, registrationId);
String accessToken = userService.issueNewAccessToken(userId);
String randomNickname = userService.generateNickname();

LoginResponseDto response = new LoginResponseDto(accessToken, randomNickname);
User user = userRepository.findById(userId).orElseThrow(() -> new EntityNotFoundException(ErrorCode.USER_NOT_FOUND));

String nickname = user.getNickname();
if (nickname == null) {
nickname = userService.generateNickname();
}

LoginResponseDto response = new LoginResponseDto(accessToken, nickname);
return SuccessResponse.ok(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
@RequiredArgsConstructor
public class OauthService {

private final Environment env;
private final UserRepository userRepository;

@Value("${spring.security.oauth2.client.registration.google.client-id}")
Expand Down

0 comments on commit 0b4946e

Please sign in to comment.