-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π :: Api-v0.0.1
- Loading branch information
Showing
203 changed files
with
5,236 additions
and
174 deletions.
There are no files selected for viewing
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
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
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
119 changes: 119 additions & 0 deletions
119
DuDoong-Api/src/main/java/band/gosrock/api/auth/controller/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,119 @@ | ||
package band.gosrock.api.auth.controller; | ||
|
||
|
||
import band.gosrock.api.auth.model.dto.request.RegisterRequest; | ||
import band.gosrock.api.auth.model.dto.response.AvailableRegisterResponse; | ||
import band.gosrock.api.auth.model.dto.response.OauthLoginLinkResponse; | ||
import band.gosrock.api.auth.model.dto.response.OauthUserInfoResponse; | ||
import band.gosrock.api.auth.model.dto.response.TokenAndUserResponse; | ||
import band.gosrock.api.auth.service.LoginUseCase; | ||
import band.gosrock.api.auth.service.LogoutUseCase; | ||
import band.gosrock.api.auth.service.OauthUserInfoUseCase; | ||
import band.gosrock.api.auth.service.RefreshUseCase; | ||
import band.gosrock.api.auth.service.RegisterUseCase; | ||
import band.gosrock.api.auth.service.WithDrawUseCase; | ||
import band.gosrock.common.annotation.DevelopOnlyApi; | ||
import band.gosrock.infrastructure.outer.api.oauth.dto.OauthTokenResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import javax.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/v1/auth") | ||
@RequiredArgsConstructor | ||
@Tag(name = "μΈμ¦ κ΄λ ¨ 컨νΈλ‘€λ¬") | ||
public class AuthController { | ||
|
||
private final RegisterUseCase registerUseCase; | ||
|
||
private final LoginUseCase loginUseCase; | ||
private final RefreshUseCase refreshUseCase; | ||
|
||
private final OauthUserInfoUseCase oauthUserInfoUseCase; | ||
|
||
private final WithDrawUseCase withDrawUseCase; | ||
private final LogoutUseCase logoutUseCase; | ||
|
||
@Operation(summary = "kakao oauth λ§ν¬λ°κΈ", description = "kakao λ§ν¬λ₯Ό λ°μλ³Όμ μμ΅λλ€.") | ||
@Tag(name = "μΉ΄μΉ΄μ€ oauth") | ||
@GetMapping("/oauth/kakao/link") | ||
public OauthLoginLinkResponse getKakaoOauthLink() { | ||
return registerUseCase.getKaKaoOauthLink(); | ||
} | ||
|
||
@Operation(summary = "code μμ²λ°λ νΈλ€λ¬ ν΄λΌμ΄μΈνΈκ° λͺ°λΌλλ©λλ€.", deprecated = true) | ||
@Tag(name = "μΉ΄μΉ΄μ€ oauth") | ||
@GetMapping("/oauth/kakao") | ||
public OauthTokenResponse getCredentialFromKaKao(@RequestParam("code") String code) { | ||
return registerUseCase.getCredentialFromKaKao(code); | ||
} | ||
|
||
@Operation(summary = "κ°λ°μ© νμκ°μ μ λλ€ ν΄λΌμ΄μΈνΈκ° λͺ°λΌλ λ©λλ€.", deprecated = true) | ||
@Tag(name = "μΉ΄μΉ΄μ€ oauth") | ||
@DevelopOnlyApi | ||
@GetMapping("/oauth/kakao/develop") | ||
public TokenAndUserResponse developUserSign(@RequestParam("code") String code) { | ||
return registerUseCase.upsertKakaoOauthUser(code); | ||
} | ||
|
||
@Operation(summary = "νμκ°μ μ΄ κ°λ₯νμ§ id token μΌλ‘ νμΈν©λλ€.") | ||
@Tag(name = "μΉ΄μΉ΄μ€ oauth") | ||
@GetMapping("/oauth/kakao/register/valid") | ||
public AvailableRegisterResponse kakaoAuthCheckRegisterValid( | ||
@RequestParam("id_token") String token) { | ||
return registerUseCase.checkAvailableRegister(token); | ||
} | ||
|
||
@Operation(summary = "id_token μΌλ‘ νμκ°μ μ ν©λλ€.") | ||
@Tag(name = "μΉ΄μΉ΄μ€ oauth") | ||
@PostMapping("/oauth/kakao/register") | ||
public TokenAndUserResponse kakaoAuthCheckRegisterValid( | ||
@RequestParam("id_token") String token, | ||
@Valid @RequestBody RegisterRequest registerRequest) { | ||
return registerUseCase.registerUserByOCIDToken(token, registerRequest); | ||
} | ||
|
||
@Operation(summary = "id_token μΌλ‘ λ‘κ·ΈμΈμ ν©λλ€.") | ||
@Tag(name = "μΉ΄μΉ΄μ€ oauth") | ||
@PostMapping("/oauth/kakao/login") | ||
public TokenAndUserResponse kakaoOauthUserLogin(@RequestParam("id_token") String token) { | ||
return loginUseCase.execute(token); | ||
} | ||
|
||
@Operation(summary = "accessToken μΌλ‘ oauth user μ 보λ₯Ό κ°μ Έμ΅λλ€.") | ||
@Tag(name = "μΉ΄μΉ΄μ€ oauth") | ||
@PostMapping("/oauth/kakao/info") | ||
public OauthUserInfoResponse kakaoOauthUserInfo( | ||
@RequestParam("access_token") String accessToken) { | ||
return oauthUserInfoUseCase.execute(accessToken); | ||
} | ||
|
||
@Operation(summary = "refreshToken μ©μ λλ€.") | ||
@PostMapping("/token/refresh") | ||
public TokenAndUserResponse tokenRefresh(@RequestParam("token") String code) { | ||
return refreshUseCase.execute(code); | ||
} | ||
|
||
@Operation(summary = "νμνν΄λ₯Ό ν©λλ€.") | ||
@SecurityRequirement(name = "access-token") | ||
@DeleteMapping("/me") | ||
public void withDrawUser() { | ||
withDrawUseCase.execute(); | ||
} | ||
|
||
@Operation(summary = "λ‘κ·Έμμμ ν©λλ€.") | ||
@SecurityRequirement(name = "access-token") | ||
@PostMapping("/logout") | ||
public void logoutUser() { | ||
logoutUseCase.execute(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
DuDoong-Api/src/main/java/band/gosrock/api/auth/model/dto/KakaoUserInfoDto.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,37 @@ | ||
package band.gosrock.api.auth.model.dto; | ||
|
||
|
||
import band.gosrock.domain.domains.user.domain.OauthInfo; | ||
import band.gosrock.domain.domains.user.domain.OauthProvider; | ||
import band.gosrock.domain.domains.user.domain.Profile; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class KakaoUserInfoDto { | ||
|
||
// oauthμΈμ¦ν μ¬μ©μ κ³ μ μμ΄λ | ||
private final String oauthId; | ||
|
||
private final String email; | ||
private final String phoneNumber; | ||
private final String profileImage; | ||
private final String name; | ||
// oauth μ 곡μ | ||
private final OauthProvider oauthProvider; | ||
|
||
public Profile toProfile() { | ||
return Profile.builder() | ||
.profileImage(this.profileImage) | ||
.phoneNumber(phoneNumber) | ||
.name(name) | ||
.email(email) | ||
.build(); | ||
} | ||
|
||
public OauthInfo toOauthInfo() { | ||
return OauthInfo.builder().oid(oauthId).provider(oauthProvider).build(); | ||
} | ||
} | ||
; |
25 changes: 25 additions & 0 deletions
25
DuDoong-Api/src/main/java/band/gosrock/api/auth/model/dto/request/RegisterRequest.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,25 @@ | ||
package band.gosrock.api.auth.model.dto.request; | ||
|
||
|
||
import band.gosrock.domain.domains.user.domain.Profile; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class RegisterRequest { | ||
private final String email; | ||
private final String phoneNumber; | ||
private final String profileImage; | ||
private final String name; | ||
// oauth μ 곡μ | ||
|
||
public Profile toProfile() { | ||
return Profile.builder() | ||
.profileImage(this.profileImage) | ||
.phoneNumber(phoneNumber) | ||
.name(name) | ||
.email(email) | ||
.build(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...Api/src/main/java/band/gosrock/api/auth/model/dto/response/AvailableRegisterResponse.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,14 @@ | ||
package band.gosrock.api.auth.model.dto.response; | ||
|
||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class AvailableRegisterResponse { | ||
|
||
@Schema(description = "νμκ°μ μ νλ μ μ μΈμ§μ λν μ¬λΆ , oauth μμ²μ ν΅ν΄ μ²μ νμκ°μ νκ²½μ° falseμ") | ||
private Boolean canRegister; | ||
} |
12 changes: 12 additions & 0 deletions
12
...ng-Api/src/main/java/band/gosrock/api/auth/model/dto/response/OauthLoginLinkResponse.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,12 @@ | ||
package band.gosrock.api.auth.model.dto.response; | ||
|
||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class OauthLoginLinkResponse { | ||
|
||
private String link; | ||
} |
32 changes: 32 additions & 0 deletions
32
...ong-Api/src/main/java/band/gosrock/api/auth/model/dto/response/OauthUserInfoResponse.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,32 @@ | ||
package band.gosrock.api.auth.model.dto.response; | ||
|
||
|
||
import band.gosrock.api.auth.model.dto.KakaoUserInfoDto; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class OauthUserInfoResponse { | ||
private final String email; | ||
private final String phoneNumber; | ||
private final String profileImage; | ||
private final String name; | ||
|
||
@Builder | ||
public OauthUserInfoResponse( | ||
String email, String phoneNumber, String profileImage, String name) { | ||
this.email = email; | ||
this.phoneNumber = phoneNumber; | ||
this.profileImage = profileImage; | ||
this.name = name; | ||
} | ||
|
||
public static OauthUserInfoResponse from(KakaoUserInfoDto kakaoUserInfoDto) { | ||
return OauthUserInfoResponse.builder() | ||
.email(kakaoUserInfoDto.getEmail()) | ||
.phoneNumber(kakaoUserInfoDto.getPhoneNumber()) | ||
.profileImage(kakaoUserInfoDto.getProfileImage()) | ||
.name(kakaoUserInfoDto.getName()) | ||
.build(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
DuDoong-Api/src/main/java/band/gosrock/api/auth/model/dto/response/TokenAndUserResponse.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,19 @@ | ||
package band.gosrock.api.auth.model.dto.response; | ||
|
||
|
||
import band.gosrock.domain.common.dto.ProfileViewDto; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class TokenAndUserResponse { | ||
@Schema(description = "μ΄μΈμ€ ν ν°") | ||
private final String accessToken; | ||
|
||
@Schema(description = "리νλ μ¬ ν ν°") | ||
private final String refreshToken; | ||
|
||
private final ProfileViewDto userProfile; | ||
} |
26 changes: 26 additions & 0 deletions
26
DuDoong-Api/src/main/java/band/gosrock/api/auth/service/LoginUseCase.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,26 @@ | ||
package band.gosrock.api.auth.service; | ||
|
||
|
||
import band.gosrock.api.auth.model.dto.response.TokenAndUserResponse; | ||
import band.gosrock.api.auth.service.helper.KakaoOauthHelper; | ||
import band.gosrock.api.auth.service.helper.TokenGenerateHelper; | ||
import band.gosrock.common.annotation.UseCase; | ||
import band.gosrock.domain.domains.user.domain.OauthInfo; | ||
import band.gosrock.domain.domains.user.domain.User; | ||
import band.gosrock.domain.domains.user.service.UserDomainService; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@UseCase | ||
@RequiredArgsConstructor | ||
public class LoginUseCase { | ||
private final KakaoOauthHelper kakaoOauthHelper; | ||
private final UserDomainService userDomainService; | ||
private final TokenGenerateHelper tokenGenerateHelper; | ||
|
||
public TokenAndUserResponse execute(String idToken) { | ||
OauthInfo oauthInfo = kakaoOauthHelper.getOauthInfoByIdToken(idToken); | ||
|
||
User user = userDomainService.loginUser(oauthInfo); | ||
return tokenGenerateHelper.execute(user); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
DuDoong-Api/src/main/java/band/gosrock/api/auth/service/LogoutUseCase.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,18 @@ | ||
package band.gosrock.api.auth.service; | ||
|
||
|
||
import band.gosrock.api.config.security.SecurityUtils; | ||
import band.gosrock.common.annotation.UseCase; | ||
import band.gosrock.domain.domains.user.adaptor.RefreshTokenAdaptor; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@UseCase | ||
@RequiredArgsConstructor | ||
public class LogoutUseCase { | ||
private final RefreshTokenAdaptor refreshTokenAdaptor; | ||
|
||
public void execute() { | ||
Long currentUserId = SecurityUtils.getCurrentUserId(); | ||
refreshTokenAdaptor.deleteByUserId(currentUserId); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
DuDoong-Api/src/main/java/band/gosrock/api/auth/service/OauthUserInfoUseCase.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,19 @@ | ||
package band.gosrock.api.auth.service; | ||
|
||
|
||
import band.gosrock.api.auth.model.dto.KakaoUserInfoDto; | ||
import band.gosrock.api.auth.model.dto.response.OauthUserInfoResponse; | ||
import band.gosrock.api.auth.service.helper.KakaoOauthHelper; | ||
import band.gosrock.common.annotation.UseCase; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@UseCase | ||
@RequiredArgsConstructor | ||
public class OauthUserInfoUseCase { | ||
private final KakaoOauthHelper kakaoOauthHelper; | ||
|
||
public OauthUserInfoResponse execute(String accessToken) { | ||
KakaoUserInfoDto oauthUserInfo = kakaoOauthHelper.getUserInfo(accessToken); | ||
return OauthUserInfoResponse.from(oauthUserInfo); | ||
} | ||
} |
Oops, something went wrong.