Skip to content

Commit

Permalink
feat: Sign-in api를 추가한다.
Browse files Browse the repository at this point in the history
  • Loading branch information
rlarltj committed Aug 3, 2024
1 parent 6002ccf commit a1ee06e
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.dnd.accompany.domain.auth.api;

import com.dnd.accompany.domain.auth.dto.AuthUserInfo;
import com.dnd.accompany.domain.auth.dto.Tokens;
import com.dnd.accompany.domain.auth.oauth.dto.LoginRequest;
import com.dnd.accompany.domain.auth.oauth.dto.OAuthUserDataResponse;
import com.dnd.accompany.domain.auth.oauth.dto.OAuthUserInfo;
import com.dnd.accompany.domain.auth.oauth.service.OAuthService;
import com.dnd.accompany.domain.auth.service.TokenService;
import com.dnd.accompany.domain.user.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/auth")
@RequiredArgsConstructor
public class AuthController {

private final TokenService tokenService;
private final OAuthService oAuthService;
private final UserService userService;


@GetMapping("/sign-in")
public ResponseEntity<Tokens> signIn(LoginRequest loginRequest) {
OAuthUserDataResponse oAuthUserData = oAuthService.login(loginRequest);

OAuthUserInfo oAuthUserInfo = OAuthUserInfo.from(oAuthUserData);

AuthUserInfo authUserInfo = userService.getOrRegister(oAuthUserInfo);

Tokens tokens = tokenService.createTokens(authUserInfo);

return ResponseEntity.ok(tokens);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.dnd.accompany.domain.auth.oauth.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class OAuthUserInfo {
private String provider;
private String oauthId;
private String nickname;
private String email;
private String appleRefreshToken;

public static OAuthUserInfo from(OAuthUserDataResponse oAuthUserDataResponse) {
return OAuthUserInfo.builder()
.provider(oAuthUserDataResponse.getProvider())
.oauthId(oAuthUserDataResponse.getOauthId())
.nickname(oAuthUserDataResponse.getNickname())
.email(oAuthUserDataResponse.getEmail())
.build();
}
}

0 comments on commit a1ee06e

Please sign in to comment.