-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/LS-6' into develop
- Loading branch information
Showing
54 changed files
with
1,030 additions
and
110 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
Empty file.
18 changes: 0 additions & 18 deletions
18
layer-api/src/main/java/org/layer/api/controller/HelloController.java
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
layer-api/src/main/java/org/layer/auth/api/AuthController.java
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
layer-api/src/main/java/org/layer/auth/exception/TokenException.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
layer-api/src/main/java/org/layer/common/annotation/MemberId.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,11 @@ | ||
package org.layer.common.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.PARAMETER) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface MemberId { | ||
} |
2 changes: 0 additions & 2 deletions
2
layer-api/src/main/java/org/layer/common/exception/GlobalExceptionHandler.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
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
60 changes: 60 additions & 0 deletions
60
layer-api/src/main/java/org/layer/config/SwaggerConfig.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,60 @@ | ||
package org.layer.config; | ||
|
||
import io.swagger.v3.oas.models.Components; | ||
import io.swagger.v3.oas.models.OpenAPI; | ||
import io.swagger.v3.oas.models.info.Contact; | ||
import io.swagger.v3.oas.models.info.Info; | ||
import io.swagger.v3.oas.models.info.License; | ||
import io.swagger.v3.oas.models.security.SecurityRequirement; | ||
import io.swagger.v3.oas.models.security.SecurityScheme; | ||
import org.layer.common.annotation.MemberId; | ||
import org.springdoc.core.customizers.OperationCustomizer; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.method.HandlerMethod; | ||
|
||
import java.util.Arrays; | ||
|
||
@Configuration | ||
public class SwaggerConfig { | ||
|
||
SecurityScheme apiAuth = new SecurityScheme() | ||
.type(SecurityScheme.Type.APIKEY) | ||
.in(SecurityScheme.In.HEADER) | ||
.name("authorization-token"); | ||
|
||
SecurityRequirement addSecurityItem = new SecurityRequirement() | ||
.addList("authorization-token"); | ||
|
||
@Bean | ||
public OpenAPI openAPI(){ | ||
var info = new Info(); | ||
info.title("Layer API"); | ||
info.description("Layer API 문서에요."); | ||
info.contact( | ||
new Contact() | ||
.email("[email protected]") | ||
.name("떡잎마을방범대") | ||
); | ||
info.license(new License().name("MIT")); | ||
return new OpenAPI() | ||
.components(new Components() | ||
.addSecuritySchemes("authorization-token", apiAuth) | ||
) | ||
.addSecurityItem(addSecurityItem) | ||
.info(info); | ||
} | ||
|
||
@Bean | ||
public OperationCustomizer customizeOperation() { | ||
return (operation, handlerMethod) -> { | ||
HandlerMethod method = (HandlerMethod) handlerMethod; | ||
method.getMethodParameters(); | ||
method.getMethodParameters(); | ||
if (Arrays.stream(method.getMethodParameters()).anyMatch(param -> param.hasParameterAnnotation(MemberId.class))) { | ||
operation.getParameters().removeIf(param -> "memberId".equals(param.getName())); | ||
} | ||
return operation; | ||
}; | ||
} | ||
} |
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,41 @@ | ||
package org.layer.config; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.layer.resolver.MemberIdResolver; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
import java.util.List; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class WebConfig implements WebMvcConfigurer { | ||
|
||
@Value("${webmvc.cors.allowedOrigins}") | ||
private String allowedOrigins; | ||
|
||
private final MemberIdResolver memberIdResolver; | ||
|
||
|
||
@Bean | ||
public WebMvcConfigurer corsConfigurer(){ | ||
return new WebMvcConfigurer() { | ||
@Override | ||
public void addCorsMappings(CorsRegistry registry) { | ||
registry.addMapping("/**") | ||
.allowedOrigins(allowedOrigins.split(",")) | ||
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") | ||
.allowedHeaders("*") | ||
.allowCredentials(true); | ||
} | ||
}; | ||
} | ||
@Override | ||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) { | ||
resolvers.add(memberIdResolver); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
layer-api/src/main/java/org/layer/domain/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,74 @@ | ||
package org.layer.domain.auth.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.layer.domain.auth.controller.dto.*; | ||
import org.layer.domain.auth.service.dto.SignInServiceResponse; | ||
import org.layer.domain.auth.service.dto.SignUpServiceResponse; | ||
import org.layer.oauth.service.GoogleService; | ||
import org.layer.oauth.service.KakaoService; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.layer.domain.auth.service.AuthService; | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/auth") | ||
@RestController | ||
public class AuthController { | ||
private final AuthService authService; | ||
private final GoogleService googleService; | ||
private final KakaoService kakaoService; | ||
|
||
// 로그인 | ||
@PostMapping("/sign-in") | ||
public ResponseEntity<SignInResponse> signIn(@RequestHeader("Authorization") final String socialAccessToken, @RequestBody final SignInRequest signInRequest) { | ||
SignInServiceResponse signInServiceResponse = authService.signIn(socialAccessToken, signInRequest.socialType()); | ||
return new ResponseEntity<>(SignInResponse.of(signInServiceResponse), HttpStatus.OK); | ||
} | ||
|
||
// 회원가입 => 소셜로그인 했는데 유효한 유저가 없을 때 이름 입력하고 회원가입하는 과정 | ||
@PostMapping("/sign-up") | ||
public ResponseEntity<SignUpResponse> signUp(@RequestHeader("Authorization") final String socialAccessToken, @RequestBody final SignUpRequest signUpRequest) { | ||
SignUpServiceResponse signUpServiceResponse = authService.signUp(socialAccessToken, signUpRequest); | ||
return new ResponseEntity<>(SignUpResponse.of(signUpServiceResponse), HttpStatus.CREATED); | ||
} | ||
|
||
|
||
// 로그아웃 | ||
@PostMapping("/sign-out") | ||
public ResponseEntity<?> signOut(@RequestBody Long memberId) { | ||
authService.signOut(memberId); | ||
return new ResponseEntity<>(HttpStatus.OK); | ||
} | ||
|
||
// 회원 탈퇴 | ||
@PostMapping("/withdraw") | ||
public ResponseEntity<?> withdraw(@RequestBody Long memberId) { | ||
authService.withdraw(memberId); | ||
return new ResponseEntity<>(HttpStatus.OK); // TODO: 리턴 객체 수정 필요 | ||
} | ||
|
||
// 토큰 재발급 | ||
@PostMapping("/reissue-token") | ||
public ResponseEntity<ReissueTokenResponse> reissueToken(@RequestBody Long memberId) { | ||
return new ResponseEntity<>( | ||
ReissueTokenResponse.of(authService.reissueToken(memberId)), | ||
HttpStatus.CREATED); | ||
} | ||
|
||
//== google OAuth2 test용 API 액세스 토큰 발급 ==// | ||
@GetMapping("oauth2/google") | ||
public String googleTest(@RequestParam("code") String code) { | ||
return googleService.getToken(code); | ||
} | ||
|
||
//== kakao OAuth2 test용 API 액세스 토큰 발급 ==// | ||
@GetMapping("oauth2/kakao") | ||
public Object kakaoLogin(@RequestParam(value = "code", required = false) String code) { | ||
return kakaoService.getToken(code); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
layer-api/src/main/java/org/layer/domain/auth/controller/dto/ReissueTokenResponse.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,11 @@ | ||
package org.layer.domain.auth.controller.dto; | ||
|
||
import org.layer.domain.auth.service.dto.ReissueTokenServiceResponse; | ||
|
||
public record ReissueTokenResponse(Long memberId, String accessToken, String refreshToken){ | ||
public static ReissueTokenResponse of(ReissueTokenServiceResponse rtsr) { | ||
return new ReissueTokenResponse(rtsr.memberId(), | ||
rtsr.jwtToken().getAccessToken(), | ||
rtsr.jwtToken().getRefreshToken()); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
layer-api/src/main/java/org/layer/domain/auth/controller/dto/SignInRequest.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,7 @@ | ||
package org.layer.domain.auth.controller.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import org.layer.domain.member.entity.SocialType; | ||
|
||
public record SignInRequest(@JsonProperty("social_type") SocialType socialType) { | ||
} |
Oops, something went wrong.