Skip to content

Commit

Permalink
feat: 이미지 도메인을 User와 Promise로 분리하고 Promise에 좌표값 추가 (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdomo authored Jul 3, 2023
1 parent bffb93a commit 46af5f5
Show file tree
Hide file tree
Showing 23 changed files with 274 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ package com.depromeet.whatnow.api.image.controller
import com.depromeet.whatnow.api.image.dto.ImageUrlResponse
import com.depromeet.whatnow.api.image.usecase.GetPresignedUrlUseCase
import com.depromeet.whatnow.api.image.usecase.ImageUploadSuccessUseCase
import com.depromeet.whatnow.common.vo.CoordinateVo
import com.depromeet.whatnow.config.s3.ImageFileExtension
import com.depromeet.whatnow.domains.image.domain.ImageCommentType
import com.depromeet.whatnow.domains.image.domain.PromiseImageCommentType
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.security.SecurityRequirement
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import javax.validation.Valid

@RestController
@Tag(name = "6. [이미지]")
Expand All @@ -23,8 +26,8 @@ class ImageController(
val getPresignedUrlUseCase: GetPresignedUrlUseCase,
val successUseCase: ImageUploadSuccessUseCase,
) {
@Operation(summary = "약속 관련 이미지 업로드 Presigned URL 발급")
@GetMapping("/promises/{promiseId}/images")
@Operation(summary = "약속 이미지 업로드 Presigned URL 발급")
@GetMapping("/images/promises/{promiseId}")
fun getPresignedUrlOfPromise(
@PathVariable promiseId: Long,
@RequestParam fileExtension: ImageFileExtension,
Expand All @@ -33,21 +36,27 @@ class ImageController(
}

@Operation(summary = "유저 프로필 이미지 업로드 Presigned URL 발급")
@GetMapping("/users/me/images")
@GetMapping("/images/users/me")
fun getPresignedUrlOfUser(
@RequestParam fileExtension: ImageFileExtension,
): ImageUrlResponse {
return getPresignedUrlUseCase.forUser(fileExtension)
}

@Operation(summary = "약속 관련 이미지 업로드 성공 요청")
@PostMapping("/promises/{promiseId}/images/success/{imageKey}")
fun promiseUploadImageSuccess(@PathVariable promiseId: Long, @PathVariable imageKey: String, @RequestParam imageCommentType: ImageCommentType) {
successUseCase.promiseUploadImageSuccess(promiseId, imageKey, imageCommentType)
@Operation(summary = "약속 이미지 업로드 성공 요청")
@PostMapping("/images/{imageKey}/promises/{promiseId}")
fun promiseUploadImageSuccess(
@PathVariable promiseId: Long,
@PathVariable imageKey: String,
@RequestParam promiseImageCommentType: PromiseImageCommentType,
@RequestBody @Valid
userLocation: CoordinateVo,
) {
successUseCase.promiseUploadImageSuccess(promiseId, imageKey, promiseImageCommentType, userLocation)
}

@Operation(summary = "유저 프로필 이미지 업로드 성공 요청")
@PostMapping("/users/me/images/success/{imageKey}")
@PostMapping("/images/{imageKey}/users/me")
fun userUploadImageSuccess(@PathVariable imageKey: String) {
successUseCase.userUploadImageSuccess(imageKey)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
package com.depromeet.whatnow.api.image.usecase

import com.depromeet.whatnow.annotation.UseCase
import com.depromeet.whatnow.common.vo.CoordinateVo
import com.depromeet.whatnow.config.security.SecurityUtils
import com.depromeet.whatnow.domains.image.domain.ImageCommentType
import com.depromeet.whatnow.domains.image.domain.PromiseImageCommentType
import com.depromeet.whatnow.domains.image.service.ImageDomainService

@UseCase
class ImageUploadSuccessUseCase(
val imageDomainService: ImageDomainService,
) {
fun promiseUploadImageSuccess(promiseId: Long, imageKey: String, imageCommentType: ImageCommentType) {
fun promiseUploadImageSuccess(
promiseId: Long,
imageKey: String,
promiseImageCommentType: PromiseImageCommentType,
userLocation: CoordinateVo,
) {
val currentUserId: Long = SecurityUtils.currentUserId
imageDomainService.promiseUploadImageSuccess(currentUserId, promiseId, imageKey, imageCommentType)
imageDomainService.promiseImageUploadSuccess(currentUserId, promiseId, imageKey, promiseImageCommentType, userLocation)
}

fun userUploadImageSuccess(imageKey: String) {
val currentUserId: Long = SecurityUtils.currentUserId
imageDomainService.userUploadImageSuccess(currentUserId, imageKey)
imageDomainService.userImageUploadSuccess(currentUserId, imageKey)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package com.depromeet.whatnow.api.image.controller

import com.depromeet.whatnow.api.image.usecase.GetPresignedUrlUseCase
import com.depromeet.whatnow.api.image.usecase.ImageUploadSuccessUseCase
import com.depromeet.whatnow.common.vo.CoordinateVo
import com.depromeet.whatnow.config.s3.ImageFileExtension
import com.depromeet.whatnow.domains.image.domain.ImageCommentType
import com.depromeet.whatnow.domains.image.domain.PromiseImageCommentType
import com.fasterxml.jackson.databind.ObjectMapper
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import org.springframework.boot.test.mock.mockito.MockBean
import org.springframework.http.MediaType
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
Expand All @@ -18,7 +21,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
@WebMvcTest(ImageController::class)
@ContextConfiguration(classes = [ImageController::class])
@AutoConfigureMockMvc(addFilters = false)
class ImageControllerTest {
class PromiseImageControllerTest {
@MockBean
lateinit var getPresignedUrlUseCase: GetPresignedUrlUseCase

Expand All @@ -28,6 +31,9 @@ class ImageControllerTest {
@Autowired
lateinit var mockMvc: MockMvc

@Autowired
lateinit var objectMapper: ObjectMapper

@Test
fun `약속 이미지 presignedUrl 요청에 성공하면 200을 응답한다`() {
// given
Expand All @@ -36,7 +42,7 @@ class ImageControllerTest {

// when, then
mockMvc.perform(
get("/v1/promises/{promiseId}/images", promiseId)
get("/v1/images/promises/{promiseId}", promiseId)
.param("fileExtension", fileExtension),
)
.andExpect(status().isOk)
Expand All @@ -50,7 +56,7 @@ class ImageControllerTest {

// when, then
mockMvc.perform(
get("/v1/users/me/images")
get("/v1/images/users/me")
.param("fileExtension", fileExtension),
)
.andExpect(status().isOk)
Expand All @@ -62,12 +68,15 @@ class ImageControllerTest {
// given
val promiseId = 1
val imageKey = "imageKey"
val imageCommentType = ImageCommentType.SORRY_LATE
val promiseImageCommentType = PromiseImageCommentType.SORRY_LATE
val userLocation = CoordinateVo(127.3, 23.0)

// when, then
mockMvc.perform(
MockMvcRequestBuilders.post("/v1/promises/{promiseId}/images/success/{imageKey}", promiseId, imageKey)
.param("imageCommentType", imageCommentType.name),
MockMvcRequestBuilders.post("/v1/images/{imageKey}/promises/{promiseId}", imageKey, promiseId)
.param("promiseImageCommentType", promiseImageCommentType.name)
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(userLocation)),
)
.andExpect(status().isOk)
.andDo { print(it) }
Expand All @@ -80,7 +89,7 @@ class ImageControllerTest {

// when, then
mockMvc.perform(
MockMvcRequestBuilders.post("/v1/users/me/images/success/{imageKey}", imageKey),
MockMvcRequestBuilders.post("/v1/images/{imageKey}/users/me", imageKey),
)
.andExpect(status().isOk)
.andDo { print(it) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.depromeet.whatnow.api.image.usecase

import com.depromeet.whatnow.domains.image.domain.ImageCommentType
import com.depromeet.whatnow.common.vo.CoordinateVo
import com.depromeet.whatnow.domains.image.domain.PromiseImageCommentType
import com.depromeet.whatnow.domains.image.service.ImageDomainService
import org.assertj.core.api.Assertions.assertThatCode
import org.junit.jupiter.api.BeforeEach
Expand All @@ -14,7 +15,7 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority
import org.springframework.security.core.context.SecurityContextHolder

@ExtendWith(MockitoExtension::class)
class ImageUploadSuccessUseCaseTest {
class PromiseImageUploadSuccessUseCaseTest {
@Mock
lateinit var imageDomainService: ImageDomainService

Expand All @@ -32,12 +33,13 @@ class ImageUploadSuccessUseCaseTest {
@Test
fun `약속 이미지 업로드 성공 요청시 정상적이라면 에러가 발생하지 않는다`() {
// given
val coordinateVo = CoordinateVo(1.0, 1.0)

// when

// then
assertThatCode {
imageUploadSuccessUseCase.promiseUploadImageSuccess(1, "imageKey", ImageCommentType.SORRY_LATE)
imageUploadSuccessUseCase.promiseUploadImageSuccess(1, "imageKey", PromiseImageCommentType.SORRY_LATE, coordinateVo)
}.doesNotThrowAnyException()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const val DEV = "dev"
const val LOCAL = "local"
const val WITHDRAW_PREFIX = "withdraw"

const val IMAGE_DOMAIN = "https://image.whatnow.kr/"
const val IMAGE_DOMAIN = "https://image.whatnow.kr"

val SWAGGER_PATTERNS = arrayOf(
"/swagger-resources/**",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.depromeet.whatnow.domains.image.adapter

import com.depromeet.whatnow.annotation.Adapter
import com.depromeet.whatnow.domains.image.domain.PromiseImage
import com.depromeet.whatnow.domains.image.repository.PromiseImageRepository

@Adapter
class PromiseImageAdapter(
val promiseImageRepository: PromiseImageRepository,
) {
fun save(promiseImage: PromiseImage): PromiseImage {
return promiseImageRepository.save(promiseImage)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.depromeet.whatnow.domains.image.adapter

import com.depromeet.whatnow.annotation.Adapter
import com.depromeet.whatnow.domains.image.domain.UserImage
import com.depromeet.whatnow.domains.image.repository.UserImageRepository

@Adapter
class UserImageAdapter(
val userImageRepository: UserImageRepository,
) {
fun save(userImage: UserImage): UserImage {
return userImageRepository.save(userImage)
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 46af5f5

Please sign in to comment.