-
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 pull request #7 from goormthon-Univ/develop
- Loading branch information
Showing
13 changed files
with
276 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
## <i>PULL REQUEST</i> | ||
|
||
### 🎋 작업 중인 브랜치 | ||
### 🎋 Issue Ticket | ||
- | ||
|
||
### 🔑 주요 작업사항 | ||
- | ||
|
||
### 🏞 (Optional) 참고 자료 | ||
- 스크린샷을 첨부해주세요. | ||
|
||
### 관련 이슈 | ||
- | ||
|
||
### (중요) 서브모듈이 수정되었나요? | ||
- 기존 커밋 : | ||
- 변경 커밋 : | ||
- 변경 사항 : | ||
- [] 해당 서브모듈 변경사항이 PR에 잘 반영되었나요? | ||
|
||
### 꼭 확인해 주세요!! | ||
- | ||
- |
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 |
---|---|---|
@@ -1,42 +1,38 @@ | ||
name: 빌드 테스트 / 리뷰어 할당 | ||
name: 테스트 코드 및 빌드 | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, closed] | ||
types: [ opened, synchronize, closed ] | ||
branches: | ||
- 'develop' | ||
- 'master' | ||
|
||
jobs: | ||
build_and_review_assign: | ||
name: "[CI] Check Build/Testcases and Assign Reviewer" | ||
test: | ||
name: "[CI] Check Tests" | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: (Set Up) checkout | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
token: ${{ secrets.GIT_TOKEN }} | ||
submodules: true | ||
|
||
- name: (Set Up) Set up JDK 17 | ||
- name: Setup Java 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
distribution: 'adopt' | ||
|
||
- name: Setup Gradle | ||
uses: gradle/gradle-build-action@v2 | ||
|
||
- name: (Set Up) Grant Execute permission for gradlew | ||
run: chmod 777 gradlew | ||
|
||
- name: (Build) Build with Gradle | ||
id: build | ||
run: ./gradlew test -i | ||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
|
||
- name: (Assign Reviewer) | ||
if: steps.build.outcome == 'success' | ||
uses: hkusu/review-assign-action@v1 | ||
with: | ||
assignees: ${{ github.actor }} | ||
reviewers: HyungJu, h-beeen | ||
ready-comment: '코드 리뷰 요청합니다 🙆 <reviewers>' | ||
merged-comment: '성공적으로 Merge 되었습니다. Shout out to <reviewers> :wink:' | ||
- name: Test with Gradle | ||
run: ./gradlew test |
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
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/com/vacgom/backend/domain/member/Member.kt
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,21 @@ | ||
package com.vacgom.backend.domain.member | ||
|
||
import com.vacgom.backend.global.auditing.BaseEntity | ||
import jakarta.persistence.* | ||
|
||
@Entity | ||
@Table(name = "t_member") | ||
class Member(nickname: String) : BaseEntity() { | ||
|
||
@Id | ||
@Column(name = "member_id") | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
var id: Long? = null | ||
|
||
@Column(name = "nickname") | ||
val nickname: String | ||
|
||
init { | ||
this.nickname = nickname | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/kotlin/com/vacgom/backend/global/exception/ApiExceptionHandler.kt
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,55 @@ | ||
package com.vacgom.backend.global.exception | ||
|
||
import com.vacgom.backend.global.exception.error.BusinessException | ||
import com.vacgom.backend.global.exception.error.ErrorCode | ||
import com.vacgom.backend.global.exception.error.ErrorResponse | ||
import com.vacgom.backend.global.exception.error.GlobalError | ||
import com.vacgom.backend.global.logger.CommonLogger | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.MethodArgumentNotValidException | ||
import org.springframework.web.bind.MissingServletRequestParameterException | ||
import org.springframework.web.bind.annotation.ExceptionHandler | ||
import org.springframework.web.bind.annotation.ResponseStatus | ||
import org.springframework.web.bind.annotation.RestControllerAdvice | ||
|
||
@RestControllerAdvice | ||
class ApiExceptionHandler { | ||
companion object : CommonLogger(); | ||
|
||
@ResponseStatus(HttpStatus.BAD_REQUEST) | ||
@ExceptionHandler(MethodArgumentNotValidException::class) | ||
fun handleMethodArgumentNotValidException(ex: MethodArgumentNotValidException): ErrorResponse? { | ||
return ErrorResponse(ex.fieldErrors) | ||
} | ||
|
||
@ResponseStatus(HttpStatus.BAD_REQUEST) | ||
@ExceptionHandler(MissingServletRequestParameterException::class) | ||
fun missingServletRequestParameterException(): ErrorResponse? { | ||
return ErrorResponse(GlobalError.INVALID_REQUEST_PARAM) | ||
} | ||
|
||
@ExceptionHandler(BusinessException::class) | ||
fun handleBusinessException( | ||
exception: BusinessException | ||
): ResponseEntity<ErrorResponse?> { | ||
logBusinessException(exception) | ||
return convert(exception.errorCode) | ||
} | ||
|
||
private fun convert( | ||
errorCode: ErrorCode | ||
): ResponseEntity<ErrorResponse?> { | ||
return ResponseEntity | ||
.status(errorCode.status) | ||
.body(ErrorResponse(errorCode)) | ||
} | ||
|
||
private fun logBusinessException(exception: BusinessException) { | ||
if (exception.errorCode.status.is5xxServerError) { | ||
log.error("", exception) | ||
} else { | ||
log.error("Error Message = {}", exception.message) | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/kotlin/com/vacgom/backend/global/exception/ApiExceptionHandlingFilter.kt
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,45 @@ | ||
package com.vacgom.backend.global.exception | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.vacgom.backend.global.exception.error.BusinessException | ||
import com.vacgom.backend.global.exception.error.ErrorResponse | ||
import jakarta.servlet.FilterChain | ||
import jakarta.servlet.ServletException | ||
import jakarta.servlet.http.HttpServletRequest | ||
import jakarta.servlet.http.HttpServletResponse | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.http.MediaType | ||
import org.springframework.stereotype.Component | ||
import org.springframework.web.filter.OncePerRequestFilter | ||
import java.io.IOException | ||
|
||
|
||
@Component | ||
class ApiExceptionHandlingFilter( | ||
private val om: ObjectMapper | ||
) : OncePerRequestFilter() { | ||
|
||
@Throws(ServletException::class, IOException::class) | ||
override fun doFilterInternal( | ||
request: HttpServletRequest, | ||
response: HttpServletResponse, | ||
chain: FilterChain | ||
) { | ||
try { | ||
chain.doFilter(request, response) | ||
} catch (exception: BusinessException) { | ||
setErrorResponse(response, exception) | ||
} | ||
} | ||
|
||
private fun setErrorResponse( | ||
response: HttpServletResponse, | ||
exception: BusinessException | ||
) = try { | ||
response.contentType = MediaType.APPLICATION_JSON_VALUE | ||
response.status = HttpStatus.UNAUTHORIZED.value() | ||
om.writeValue(response.outputStream, ErrorResponse(exception.errorCode)) | ||
} catch (exception: IOException) { | ||
throw RuntimeException(exception) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/com/vacgom/backend/global/exception/error/BusinessException.kt
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,6 @@ | ||
package com.vacgom.backend.global.exception.error | ||
|
||
|
||
class BusinessException( | ||
val errorCode: ErrorCode | ||
) : RuntimeException(errorCode.message) |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/com/vacgom/backend/global/exception/error/ErrorCode.kt
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,9 @@ | ||
package com.vacgom.backend.global.exception.error | ||
|
||
import org.springframework.http.HttpStatus | ||
|
||
interface ErrorCode { | ||
val message: String | ||
val status: HttpStatus | ||
val code: String | ||
} |
Oops, something went wrong.