Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/kotlin/com/ixfp/gitmon/config/web/WebMvcConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class WebMvcConfig(
.addPathPatterns("/api/v1/member/repo/**") // 인증이 필요한 경로
.addPathPatterns("/api/v1/member", "/api/v1/member/")
.addPathPatterns("/api/v1/posting", "/api/v1/posting/")
.addPathPatterns("/api/v1/posting/images", "/api/v1/posting/images/")
}

override fun addCorsMappings(registry: CorsRegistry) {
Expand Down
77 changes: 77 additions & 0 deletions src/main/kotlin/com/ixfp/gitmon/controller/IPostingController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,81 @@ interface IPostingController {
content: MultipartFile,
member: Member,
): ResponseEntity<ApiResponseBody<PostingReadDto>>

@Operation(
summary = "이미지 업로드",
description = "포스팅에 사용할 이미지를 업로드합니다.",
security = [SecurityRequirement(name = ACCESS_TOKEN)],
)
@ApiResponses(
value = [
ApiResponse(
responseCode = "201",
description = "이미지 업로드 성공",
content = [
Content(
mediaType = "application/json",
schema =
Schema(
example = """
{
"status": "CREATED",
"data": "https://raw.githubusercontent.com/user/repo/main/images/uuid.jpg"
}
""",
),
),
],
),
ApiResponse(
responseCode = "400",
description = "허용되지 않은 이미지 확장자",
content = [
Content(
mediaType = "application/json",
schema =
Schema(
example = """
{
"status": "BAD_REQUEST",
"errorMessage": "invalid image extension"
}
""",
),
),
],
),
ApiResponse(
responseCode = "409",
description = "사용자의 레포지토리가 아직 설정되지 않음",
content = [
Content(
mediaType = "application/json",
schema =
Schema(
example = """
{
"status": "CONFLICT",
"errorMessage": "repository not configured"
}
""",
),
),
],
),
],
)
@io.swagger.v3.oas.annotations.parameters.RequestBody(
description = "업로드할 이미지 파일",
required = true,
content = [
Content(
mediaType = MediaType.MULTIPART_FORM_DATA_VALUE,
),
],
)
fun uploadImage(
image: MultipartFile,
member: Member,
): ResponseEntity<ApiResponseBody<String>>
}
12 changes: 12 additions & 0 deletions src/main/kotlin/com/ixfp/gitmon/controller/PostingController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ class PostingController(
return ApiResponseHelper.success(posting)
}

@PostMapping(
"/images",
consumes = [MediaType.MULTIPART_FORM_DATA_VALUE],
)
override fun uploadImage(
@RequestPart image: MultipartFile,
@RequestAttribute(AUTHENTICATED_MEMBER) member: Member,
): ResponseEntity<ApiResponseBody<String>> {
val imageUrl = postingService.uploadImage(member, image)
return ApiResponseHelper.created(imageUrl)
}

companion object {
private val log = logger {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class PostingService(
return updatedPostingId
}

private fun uploadImage(
fun uploadImage(
member: Member,
content: MultipartFile,
): String {
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
oauth2:
client:
github:
id: ${GITHUB_OAUTH2_CLIENT_ID_DEV}
secret: ${GITHUB_OAUTH2_CLIENT_SECRET_DEV}