Skip to content

Commit

Permalink
πŸš€ :: Api-v0.0.1
Browse files Browse the repository at this point in the history
πŸš€ :: Api-v0.0.1
  • Loading branch information
ImNM authored Jan 8, 2023
2 parents 0284c46 + 470c4d2 commit c8dfd7d
Show file tree
Hide file tree
Showing 203 changed files with 5,236 additions and 174 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,14 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew

- name: Run build
run: ./gradlew build -x test
- name: spotless check
run: ./gradlew spotlessCheck

- name: Start containers
run: docker-compose up -d

- name: test and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew test sonar --info
1 change: 1 addition & 0 deletions DuDoong-Api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springdoc:springdoc-openapi-ui:1.6.12'
implementation 'org.springframework.boot:spring-boot-starter-security'

implementation project(':DuDoong-Domain')
implementation project(':DuDoong-Common')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.Environment;

@SpringBootApplication
@RequiredArgsConstructor
@SpringBootApplication
@Slf4j
public class DuDoongApiServerApplication implements ApplicationListener<ApplicationReadyEvent> {

Expand Down
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();
}
}
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();
}
}
;
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();
}
}
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;
}
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;
}
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();
}
}
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;
}
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);
}
}
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);
}
}
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);
}
}
Loading

0 comments on commit c8dfd7d

Please sign in to comment.