Skip to content

Commit de72f32

Browse files
committed
add: image upload api
1 parent e07da2f commit de72f32

File tree

6 files changed

+77
-0
lines changed

6 files changed

+77
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package gogo.gogostage.domain.image.application
2+
3+
import gogo.gogostage.domain.image.application.dto.ImageUploadResDto
4+
import org.springframework.stereotype.Component
5+
6+
@Component
7+
class ImageMapper {
8+
9+
fun mapUpload(url: String): ImageUploadResDto =
10+
ImageUploadResDto(
11+
imageUrl = url
12+
)
13+
14+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package gogo.gogostage.domain.image.application
2+
3+
import gogo.gogostage.domain.image.application.dto.ImageUploadResDto
4+
import org.springframework.web.multipart.MultipartFile
5+
6+
interface ImageService {
7+
fun upload(image: MultipartFile): ImageUploadResDto
8+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package gogo.gogostage.domain.image.application
2+
3+
import gogo.gogostage.domain.image.application.dto.ImageUploadResDto
4+
import gogo.gogostage.global.aws.s3.S3Uploader
5+
import org.springframework.stereotype.Service
6+
import org.springframework.web.multipart.MultipartFile
7+
8+
@Service
9+
class ImageServiceImpl(
10+
private val s3Uploader: S3Uploader,
11+
private val imageMapper: ImageMapper
12+
): ImageService {
13+
14+
override fun upload(image: MultipartFile): ImageUploadResDto {
15+
val url = s3Uploader.upload(image)
16+
return imageMapper.mapUpload(url)
17+
}
18+
19+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package gogo.gogostage.domain.image.application.dto
2+
3+
data class ImageUploadResDto(
4+
val imageUrl: String
5+
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package gogo.gogostage.domain.image.presentation
2+
3+
import gogo.gogostage.domain.image.application.ImageService
4+
import gogo.gogostage.domain.image.application.dto.ImageUploadResDto
5+
import org.springframework.http.HttpStatus
6+
import org.springframework.http.ResponseEntity
7+
import org.springframework.web.bind.annotation.PostMapping
8+
import org.springframework.web.bind.annotation.RequestMapping
9+
import org.springframework.web.bind.annotation.RequestPart
10+
import org.springframework.web.bind.annotation.RestController
11+
import org.springframework.web.multipart.MultipartFile
12+
13+
@RestController
14+
@RequestMapping("/stage/image")
15+
class ImageController(
16+
private val imageService: ImageService
17+
) {
18+
19+
@PostMapping
20+
fun uploadImage(
21+
@RequestPart("image") file: MultipartFile
22+
): ResponseEntity<ImageUploadResDto> {
23+
val response = imageService.upload(file)
24+
return ResponseEntity.status(HttpStatus.CREATED).body(response)
25+
}
26+
27+
}

src/main/kotlin/gogo/gogostage/global/config/SecurityConfig.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gogo.gogostage.global.config
22

33

4+
import gogo.gogostage.domain.image.application.ImageMapper
45
import gogo.gogostage.global.filter.AuthenticationFilter
56
import gogo.gogostage.global.filter.LoggingFilter
67
import gogo.gogostage.global.handler.CustomAccessDeniedHandler
@@ -90,6 +91,9 @@ class SecurityConfig(
9091
httpRequests.requestMatchers(HttpMethod.POST, "/stage/community/comment/{board_id}").hasAnyRole(Authority.USER.name, Authority.STAFF.name)
9192
httpRequests.requestMatchers(HttpMethod.POST, "/stage/community/comment/like/{board_id}").hasAnyRole(Authority.USER.name, Authority.STAFF.name)
9293

94+
// image
95+
httpRequests.requestMatchers(HttpMethod.POST, "/stage/image").hasAnyRole(Authority.USER.name, Authority.STAFF.name)
96+
9397
// server to server
9498
httpRequests.requestMatchers(HttpMethod.GET, "/stage/api/point/{stage_id}").access { _, context -> hasIpAddress(context) }
9599
httpRequests.requestMatchers(HttpMethod.GET, "/stage/api/match/info").access { _, context -> hasIpAddress(context) }

0 commit comments

Comments
 (0)