-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/main/java/com/dnd/accompany/domain/auth/api/AuthController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/dnd/accompany/domain/auth/oauth/dto/OAuthUserInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
|