Skip to content

Commit

Permalink
백엔드 main 병합 v1.1 (#578)
Browse files Browse the repository at this point in the history
Merge dev/BE
  • Loading branch information
cookienc authored Sep 20, 2023
1 parent 108e138 commit d040704
Show file tree
Hide file tree
Showing 182 changed files with 6,264 additions and 1,163 deletions.
5 changes: 5 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Frontend
/frontend/ @tkdrb12 @gyeongza @guridaek

# Backend
/backend/ @shb03323 @hyena0608 @cookienc @eunbii0213
2 changes: 1 addition & 1 deletion .github/workflows/dev-be-ci-cd-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
run: docker push 2023baton/2023baton

deploy:
runs-on: [self-hosted, Linux, ARM64]
runs-on: [ self-hosted, Linux, ARM64, dev ]
needs: build

steps:
Expand Down
29 changes: 29 additions & 0 deletions backend/baton/src/docs/asciidoc/GithubBranchCreateApi.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
ifndef::snippets[]
:snippets: ../../../build/generated-snippets
endif::[]
:doctype: book
:icons: font
:source-highlighter: highlight.js
:toc: left
:toclevels: 3
:sectlinks:
:operation-http-request-title: Example Request
:operation-http-response-title: Example Response

==== *사용자 이름으로 레포 브랜치 생성 API*

===== *Http Request*

include::{snippets}/../../build/generated-snippets/github-branch-api-test/create-member-branch/http-request.adoc[]

===== *Http Request Headers*

include::{snippets}/../../build/generated-snippets/github-branch-api-test/create-member-branch/request-headers.adoc[]

===== *Http Response*

include::{snippets}/../../build/generated-snippets/github-branch-api-test/create-member-branch/http-response.adoc[]

===== *Http Response Headers*

include::{snippets}/../../build/generated-snippets/github-branch-api-test/create-member-branch/response-headers.adoc[]
37 changes: 37 additions & 0 deletions backend/baton/src/docs/asciidoc/GithubOauthApi.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
ifndef::snippets[]
:snippets: ../../../build/generated-snippets
endif::[]
:doctype: book
:icons: font
:source-highlighter: highlight.js
:toc: left
:toclevels: 3
:sectlinks:
:operation-http-request-title: Example Request
:operation-http-response-title: Example Response

==== *깃허브 소셜 로그인 redirect API*

===== *Http Request*

include::{snippets}/../../build/generated-snippets/github-oauth-api-test/github_login/http-request.adoc[]

===== *Http Request Path Paramemters*

include::{snippets}/../../build/generated-snippets/github-oauth-api-test/github_login/path-parameters.adoc[]

===== *Http Request Query Paramemters*

include::{snippets}/../../build/generated-snippets/github-oauth-api-test/github_login/query-parameters.adoc[]

===== *Http Response*

include::{snippets}/../../build/generated-snippets/github-oauth-api-test/github_login/http-response.adoc[]

===== *Http Response Headers*

include::{snippets}/../../build/generated-snippets/github-oauth-api-test/github_login/response-headers.adoc[]

===== *Http Response Cookies*

include::{snippets}/../../build/generated-snippets/github-oauth-api-test/github_login/response-cookies.adoc[]
37 changes: 37 additions & 0 deletions backend/baton/src/docs/asciidoc/RefreshTokenApi.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
ifndef::snippets[]
:snippets: ../../../build/generated-snippets
endif::[]
:doctype: book
:icons: font
:source-highlighter: highlight.js
:toc: left
:toclevels: 3
:sectlinks:
:operation-http-request-title: Example Request
:operation-http-response-title: Example Response

==== *리프레시 토큰 재발급 API*

===== *Http Request*

include::{snippets}/../../build/generated-snippets/refresh-token-api-test/refresh/http-request.adoc[]

===== *Http Request Headers*

include::{snippets}/../../build/generated-snippets/refresh-token-api-test/refresh/request-headers.adoc[]

===== *Http Request Cookies*

include::{snippets}/../../build/generated-snippets/refresh-token-api-test/refresh/request-cookies.adoc[]

===== *Http Response*

include::{snippets}/../../build/generated-snippets/refresh-token-api-test/refresh/http-response.adoc[]

===== *Http Response Headers*

include::{snippets}/../../build/generated-snippets/refresh-token-api-test/refresh/response-headers.adoc[]

===== *Http Response Cookies*

include::{snippets}/../../build/generated-snippets/refresh-token-api-test/refresh/response-cookies.adoc[]
44 changes: 40 additions & 4 deletions backend/baton/src/docs/asciidoc/RunnerPostReadApi.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ include::{snippets}/../../build/generated-snippets/runner-post-read-one-api-test

===== *Http Request*

include::{snippets}/../../build/generated-snippets/runner-post-read-all-api-test/read-all-runner-posts/http-request.adoc[]
include::{snippets}/../../build/generated-snippets/runner-post-read-all-api-test/read-runner-posts-by-review-status/http-request.adoc[]

===== *Http Request Query Parameters*

include::{snippets}/../../build/generated-snippets/runner-post-read-all-api-test/read-all-runner-posts/query-parameters.adoc[]
include::{snippets}/../../build/generated-snippets/runner-post-read-all-api-test/read-runner-posts-by-review-status/query-parameters.adoc[]

===== *Http Response*

include::{snippets}/../../build/generated-snippets/runner-post-read-all-api-test/read-all-runner-posts/http-response.adoc[]
include::{snippets}/../../build/generated-snippets/runner-post-read-all-api-test/read-runner-posts-by-review-status/http-response.adoc[]

===== *Http Response Fields*

include::{snippets}/../../build/generated-snippets/runner-post-read-all-api-test/read-all-runner-posts/response-fields.adoc[]
include::{snippets}/../../build/generated-snippets/runner-post-read-all-api-test/read-runner-posts-by-review-status/response-fields.adoc[]

==== *러너 마이페이지 게시글 조회 API*

Expand Down Expand Up @@ -129,3 +129,39 @@ include::{snippets}/../../build/generated-snippets/runner-post-read-of-supporter
===== *Http Response Fields*

include::{snippets}/../../build/generated-snippets/runner-post-read-of-supporter-by-guest-api-test/read-referenced-by-supporter/response-fields.adoc[]

==== *태그 이름과 리뷰 상태를 조건으로 러너 게시글 페이징 조회 API*

===== *Http Request*

include::{snippets}/../../build/generated-snippets/runner-post-read-search-api-test/read-runner-posts-by-tag-names-and-review-status/http-request.adoc[]

===== *Http Request Query Parameters*

include::{snippets}/../../build/generated-snippets/runner-post-read-search-api-test/read-runner-posts-by-tag-names-and-review-status/query-parameters.adoc[]

===== *Http Response*

include::{snippets}/../../build/generated-snippets/runner-post-read-search-api-test/read-runner-posts-by-tag-names-and-review-status/http-response.adoc[]

===== *Http Response Fields*

include::{snippets}/../../build/generated-snippets/runner-post-read-search-api-test/read-runner-posts-by-tag-names-and-review-status/response-fields.adoc[]

==== *태그 검색 API*

===== *Http Request*

include::{snippets}/../../build/generated-snippets/tag-read-api-test/read-tags/http-request.adoc[]

===== *Http Request Query Parameters*

include::{snippets}/../../build/generated-snippets/tag-read-api-test/read-tags/query-parameters.adoc[]

===== *Http Response*

include::{snippets}/../../build/generated-snippets/tag-read-api-test/read-tags/http-response.adoc[]

===== *Http Response Fields*

include::{snippets}/../../build/generated-snippets/tag-read-api-test/read-tags/response-fields.adoc[]
26 changes: 26 additions & 0 deletions backend/baton/src/docs/asciidoc/RunnerReadApi.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
ifndef::snippets[]
:snippets: ../../../build/generated-snippets
endif::[]
:doctype: book
:icons: font
:source-highlighter: highlight.js
:toc: left
:toclevels: 3
:sectlinks:
:operation-http-request-title: Example Request
:operation-http-response-title: Example Response

==== *러너 프로필 조회 API*

===== *Http Request*

include::{snippets}/../../build/generated-snippets/runner-read-by-runner-id-api-test/read-runner-profile/http-request.adoc[]

===== *Http Response*

include::{snippets}/../../build/generated-snippets/runner-read-by-runner-id-api-test/read-runner-profile/http-response.adoc[]

===== *Http Response Fields*

include::{snippets}/../../build/generated-snippets/runner-read-by-runner-id-api-test/read-runner-profile/response-fields.adoc[]

13 changes: 12 additions & 1 deletion backend/baton/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ endif::[]

= Baton-API

== *[ 깃허브 레포 ]*

=== *사용자 깃허브 브랜치 생성*

include::GithubBranchCreateApi.adoc[]

== *[ 로그인 ]*

include::GithubOauthApi.adoc[]
include::RefreshTokenApi.adoc[]

== *[ 프로필 ]*

=== *사용자 프로필 조회*
Expand All @@ -18,7 +29,7 @@ include::MemberLoginReadApi.adoc[]

=== *러너 프로필 조회*

include::RunneReadApi.adoc[]
include::RunnerReadApi.adoc[]

=== *러너 프로필 수정*

Expand Down
64 changes: 42 additions & 22 deletions backend/baton/src/main/java/touch/baton/common/LoggerAspect.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@

import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Collectors;

@Slf4j
@Profile("!test")
@Aspect
@Component
public class LoggerAspect {
Expand All @@ -25,36 +31,50 @@ public class LoggerAspect {
public void logInfo() {
}

@Around(value = "logInfo()")
public Object printLog(final ProceedingJoinPoint joinPoint) {
@Before("logInfo()")
public void requestLog(final JoinPoint joinPoint) {
final HttpServletRequest request = getRequest();
final String signatureName = getSignatureName(joinPoint);
log.info(">>>>> API start [" + signatureName + "() from "
+ request.getRemoteAddr() + "] by "
+ request.getMethod() + " "
+ request.getRequestURI());

final long startTime = System.currentTimeMillis();
Object proceed = process(joinPoint, request, signatureName);
final long timeDiff = System.currentTimeMillis() - startTime;
log.info("시간차이(m) : {}", timeDiff);
return proceed;
log.info(">>>>> API start [{}() from {}] by {} {}",
signatureName, request.getRemoteAddr(), request.getMethod(), request.getRequestURI());
}

@AfterReturning(value = "logInfo()", returning = "returnObj")
public void after(final JoinPoint joinPoint, final Object returnObj) {
final HttpServletRequest request = getRequest();
final String signatureName = getSignatureName(joinPoint);
log.info("\n>>>>> API finish [{}() from {}] by {} {} \n" +
">>>>> API return value = {}",
signatureName, request, request.getMethod(), request.getRequestURI(),
returnObj);
}

@AfterThrowing(value = "logInfo()", throwing = "exception")
public void afterThrowing(final JoinPoint joinPoint, final Exception exception) {
final HttpServletRequest request = getRequest();
final String signatureName = getSignatureName(joinPoint);
log.warn("""
\n
>>>>> API ERROR [{}() from {}] by {} {}
>>>>> ERROR MESSAGE = {}
>>>>> STACK TRACE = {}
""",
signatureName, request.getRemoteAddr(), request.getMethod(), request.getRequestURI(),
exception.getMessage(),
convertPrettyStackTrace(exception.getStackTrace()));
}

private HttpServletRequest getRequest() {
return ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
}

private String getSignatureName(final ProceedingJoinPoint joinPoint) {
private String getSignatureName(final JoinPoint joinPoint) {
return joinPoint.getSignature().getDeclaringType().getSimpleName() + "." + joinPoint.getSignature().getName();
}

private Object process(final ProceedingJoinPoint joinPoint, final HttpServletRequest request, final String signatureName) {
try {
return joinPoint.proceed();
} catch (Throwable e) {
log.error(">>>>> controller start [" + signatureName + "() from " + request.getRemoteAddr() + "] with Error[" + e.getMessage() + "]");
throw new RuntimeException("에러 나요.");
}
private String convertPrettyStackTrace(final StackTraceElement[] stackTraceElements) {
return Arrays.stream(stackTraceElements)
.map(StackTraceElement::toString)
.collect(Collectors.joining("\n"));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package touch.baton.domain.common;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.ValidationException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.TypeMismatchException;
import org.springframework.http.HttpHeaders;
Expand Down Expand Up @@ -31,6 +32,16 @@
@RestControllerAdvice
public class GlobalControllerAdvice {

@ExceptionHandler(ValidationException.class)
public ResponseEntity<ErrorResponse> handleValidation(final HttpServletRequest request,
final ClientRequestException e
) {
LoggerUtils.logWarn(request, e);
return ResponseEntity
.status(e.getErrorCode().getHttpStatus())
.body(ErrorResponse.from(e));
}

@ExceptionHandler(ClientRequestException.class)
public ResponseEntity<ErrorResponse> handleClientRequest(final HttpServletRequest request,
final ClientRequestException e
Expand Down Expand Up @@ -72,4 +83,12 @@ public ResponseEntity<ServerErrorResponse> handleBaseException(final HttpServlet
LoggerUtils.logWarn(httpServletRequest, ex);
return ResponseEntity.internalServerError().body(ServerErrorResponse.from(ex));
}

@ExceptionHandler(Exception.class)
public ResponseEntity<ServerErrorResponse> handleException(final HttpServletRequest httpServletRequest,
final BaseException ex
) {
LoggerUtils.logWarn(httpServletRequest, ex);
return ResponseEntity.internalServerError().body(ServerErrorResponse.unExpected());
}
}
Loading

0 comments on commit d040704

Please sign in to comment.