-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Room 엔티티내 외래키 제거 * feat: 예외 타입 추가, 동적 메시지 추가 * feat: RoomResponse 생성 부분 TODO 해결 * feat: RoomController RequestMapping 으로 그룹화 * feat: 방에 참가하는 기능 구현 * feat: 인증 기능 구현 * feat: 방에 참가하는 기능 요청-응답 기능 구현 * feat: 문서 관련 변수 설정 * feat: LoginMemberArgumentResolver WebConfig 에 추가 * feat: Logging 레벨 수정, 명세 추가 * style: 개행 수정
- Loading branch information
1 parent
759ebf2
commit 7ff48c9
Showing
23 changed files
with
468 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package corea.auth; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class RequestHandler { | ||
|
||
private static final String AUTHORIZATION_HEADER = "Authorization"; | ||
|
||
public String extract(HttpServletRequest request) { | ||
return request.getHeader(AUTHORIZATION_HEADER); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
backend/src/main/java/corea/auth/annotation/LoginUser.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 corea.auth.annotation; | ||
|
||
import io.swagger.v3.oas.annotations.Hidden; | ||
|
||
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) | ||
@Hidden() | ||
public @interface LoginUser { | ||
} |
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,34 @@ | ||
package corea.auth.domain; | ||
|
||
import corea.member.domain.Member; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.Objects; | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public class AuthInfo { | ||
|
||
private final Long id; | ||
|
||
private final String name; | ||
|
||
private final String email; | ||
|
||
public static AuthInfo from(Member member){ | ||
return new AuthInfo(member.getId(), member.getUserName(), member.getEmail()); | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof AuthInfo authInfo)) return false; | ||
return Objects.equals(id, authInfo.id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(id); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
backend/src/main/java/corea/auth/resolver/LoginMemberArgumentResolver.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,41 @@ | ||
package corea.auth.resolver; | ||
|
||
import corea.auth.RequestHandler; | ||
import corea.auth.annotation.LoginUser; | ||
import corea.auth.domain.AuthInfo; | ||
import corea.exception.CoreaException; | ||
import corea.exception.ExceptionType; | ||
import corea.member.domain.Member; | ||
import corea.member.repository.MemberRepository; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.core.MethodParameter; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.bind.support.WebDataBinderFactory; | ||
import org.springframework.web.context.request.NativeWebRequest; | ||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
import org.springframework.web.method.support.ModelAndViewContainer; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class LoginMemberArgumentResolver implements HandlerMethodArgumentResolver { | ||
|
||
private final RequestHandler requestHandler; | ||
private final MemberRepository memberRepository; | ||
|
||
@Override | ||
public boolean supportsParameter(MethodParameter parameter) { | ||
return parameter.hasParameterAnnotation(LoginUser.class); | ||
} | ||
|
||
@Override | ||
public AuthInfo resolveArgument(MethodParameter parameter, | ||
ModelAndViewContainer mavContainer, | ||
NativeWebRequest webRequest, | ||
WebDataBinderFactory binderFactory) { | ||
HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest(); | ||
Member member = memberRepository.findByEmail(requestHandler.extract(request)) | ||
.orElseThrow(()-> new CoreaException(ExceptionType.AUTHORIZATION_ERROR)); | ||
return AuthInfo.from(member); | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
backend/src/main/java/corea/exception/ExceptionResponseHandler.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 corea.exception; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
|
||
@Slf4j | ||
@ControllerAdvice | ||
public class ExceptionResponseHandler { | ||
|
||
@ExceptionHandler(CoreaException.class) | ||
public ResponseEntity<ErrorResponse> handleCoreaException(final CoreaException e) { | ||
log.debug("Corea exception [statusCode = {}, errorMessage = {}, cause = {}]", e.getHttpStatus(), e.getMessage(), e.getCause()); | ||
return ResponseEntity.status(e.getHttpStatus()) | ||
.body(new ErrorResponse(e.getMessage())); | ||
} | ||
|
||
@ExceptionHandler(Exception.class) | ||
public ResponseEntity<ErrorResponse> handleException(final Exception e) { | ||
log.debug("Server exception [errorMessage = {}, cause = {}]", e.getMessage(), e.getCause()); | ||
return ResponseEntity.internalServerError() | ||
.body(new ErrorResponse(e.getMessage())); | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
backend/src/main/java/corea/matching/controller/ParticipateController.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,27 @@ | ||
package corea.matching.controller; | ||
|
||
import corea.auth.annotation.LoginUser; | ||
import corea.auth.domain.AuthInfo; | ||
import corea.matching.dto.ParticipationRequest; | ||
import corea.matching.service.ParticipationService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/participate") | ||
@RequiredArgsConstructor | ||
public class ParticipateController implements ParticipationControllerSpecification { | ||
|
||
private final ParticipationService participationService; | ||
|
||
@PostMapping("/{id}") | ||
public ResponseEntity<Void> participate(@PathVariable long id, @LoginUser AuthInfo authInfo) { | ||
participationService.participate(new ParticipationRequest(id, authInfo.getId())); | ||
return ResponseEntity.ok() | ||
.build(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
backend/src/main/java/corea/matching/controller/ParticipationControllerSpecification.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,24 @@ | ||
package corea.matching.controller; | ||
|
||
import corea.auth.domain.AuthInfo; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.ExampleObject; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
public interface ParticipationControllerSpecification { | ||
|
||
@ApiResponses( | ||
value = { | ||
@ApiResponse(responseCode = "404", content = @Content(mediaType = "application/json", examples = { | ||
@ExampleObject(name = "해당하는 방이 없는 경우", value = """ | ||
{ | ||
"message": "1에 해당하는 방 없습니다." | ||
} | ||
""") | ||
})), | ||
} | ||
) | ||
ResponseEntity<Void> participate(long id, AuthInfo authInfo); | ||
} |
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
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
Oops, something went wrong.