Skip to content

Commit

Permalink
refactor: ImageController를 AdminController로 병합
Browse files Browse the repository at this point in the history
  • Loading branch information
belljun3395 committed Jul 1, 2024
1 parent 9db3244 commit af75f56
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 176 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.few.api.domain.image.dto
package com.few.api.domain.admin.document.dto

import org.springframework.web.multipart.MultipartFile

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.few.api.domain.image.dto
package com.few.api.domain.admin.document.dto

import java.net.URL

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface GetUrlService {
}

@Profile("local")
@Service(value = "adminGetLocalUrlService") // todo remove value and image/GetLocalUrlService
@Service
class GetLocalUrlService(
private val services: Map<String, GetPreSignedObjectUrlService>
) : GetUrlService {
Expand All @@ -34,7 +34,7 @@ class GetLocalUrlService(
}

@Profile("!local")
@Service(value = "adminGetCdnUrlService") // todo remove value and image/GetCdnUrlService
@Service
class GetCdnUrlService(
private val cdnProperty: CdnProperty
) : GetUrlService {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.few.api.domain.image.usecase
package com.few.api.domain.admin.document.usecase

import com.few.api.domain.image.dto.PutImageUseCaseIn
import com.few.api.domain.image.dto.PutImageUseCaseOut
import com.few.api.domain.image.service.GetUrlService
import com.few.api.domain.image.service.dto.GetUrlQuery
import com.few.api.domain.admin.document.dto.PutImageUseCaseIn
import com.few.api.domain.admin.document.dto.PutImageUseCaseOut
import com.few.api.domain.admin.document.service.GetUrlService
import com.few.api.domain.admin.document.service.dto.GetUrlQuery
import com.few.api.repo.dao.image.ImageDao
import com.few.api.repo.dao.image.command.InsertImageIfoCommand
import com.few.storage.image.service.PutImageService
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.few.api.web.controller.admin

import com.few.api.domain.admin.document.dto.*
import com.few.api.domain.admin.document.usecase.AddArticleUseCase
import com.few.api.domain.admin.document.usecase.AddWorkbookUseCase
import com.few.api.domain.admin.document.usecase.ConvertContentUseCase
import com.few.api.domain.admin.document.usecase.MapArticleUseCase
import com.few.api.domain.admin.document.usecase.*
import com.few.api.web.controller.admin.request.AddArticleRequest
import com.few.api.web.controller.admin.request.AddWorkbookRequest
import com.few.api.web.controller.admin.request.ConvertContentRequest
import com.few.api.web.controller.admin.request.MapArticleRequest
import com.few.api.web.controller.admin.response.AddArticleResponse
import com.few.api.web.controller.admin.response.AddWorkbookResponse
import com.few.api.web.controller.admin.response.ConvertContentResponse
import com.few.api.web.controller.admin.request.ImageSourceRequest
import com.few.api.web.controller.admin.response.ImageSourceResponse
import com.few.api.web.support.ApiResponse
import com.few.api.web.support.ApiResponseGenerator
import com.few.api.web.support.MessageCode
Expand All @@ -30,7 +29,8 @@ class AdminController(
private val addArticleUseCase: AddArticleUseCase,
private val addWorkbookUseCase: AddWorkbookUseCase,
private val mapArticleUseCase: MapArticleUseCase,
private val convertContentUseCase: ConvertContentUseCase
private val convertContentUseCase: ConvertContentUseCase,
private val putImageUseCase: PutImageUseCase
) {
@PostMapping("/workbooks")
fun addWorkbook(@RequestBody request: AddWorkbookRequest): ApiResponse<ApiResponse.SuccessBody<AddWorkbookResponse>> {
Expand Down Expand Up @@ -103,4 +103,15 @@ class AdminController(
return ApiResponseGenerator.success(it, HttpStatus.OK)
}
}

@PostMapping("/utilities/conversion/image", consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
fun putImage(request: ImageSourceRequest): ApiResponse<ApiResponse.SuccessBody<ImageSourceResponse>> {
val useCaseOut = PutImageUseCaseIn(request.source).let { useCaseIn: PutImageUseCaseIn ->
putImageUseCase.execute(useCaseIn)
}

return ImageSourceResponse(useCaseOut.url).let {
ApiResponseGenerator.success(it, HttpStatus.OK)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.few.api.web.controller.image.request
package com.few.api.web.controller.admin.request

import org.springframework.web.multipart.MultipartFile

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.few.api.web.controller.image.response
package com.few.api.web.controller.admin.response

import java.net.URL

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import com.epages.restdocs.apispec.ResourceSnippetParameters
import com.epages.restdocs.apispec.Schema
import com.fasterxml.jackson.databind.ObjectMapper
import com.few.api.domain.admin.document.dto.*
import com.few.api.domain.admin.document.usecase.AddArticleUseCase
import com.few.api.domain.admin.document.usecase.AddWorkbookUseCase
import com.few.api.domain.admin.document.usecase.ConvertContentUseCase
import com.few.api.domain.admin.document.usecase.MapArticleUseCase
import com.few.api.domain.admin.document.usecase.*
import com.few.api.web.controller.ControllerTestSpec
import com.few.api.web.controller.admin.request.*
import com.few.api.web.controller.admin.response.ImageSourceResponse
import com.few.api.web.controller.description.Description
import com.few.api.web.controller.helper.*
import org.junit.jupiter.api.BeforeEach
Expand Down Expand Up @@ -61,6 +59,9 @@ class AdminControllerTest : ControllerTestSpec() {
@MockBean
private lateinit var convertContentUseCase: ConvertContentUseCase

@MockBean
private lateinit var putImageUseCase: PutImageUseCase

companion object {
private val BASE_URL = "/api/v1/admin"
private val TAG = "AdminController"
Expand Down Expand Up @@ -277,4 +278,50 @@ class AdminControllerTest : ControllerTestSpec() {
)
)
}

@Test
@DisplayName("[POST] /api/v1/utilities/conversion/image")
fun putImage() {
// given
val api = "PutImage"
val uri = UriComponentsBuilder.newInstance().path("$BASE_URL/utilities/conversion/image").build().toUriString()
val request = ImageSourceRequest(source = MockMultipartFile("source", "test.jpg", "image/jpeg", "test".toByteArray()))
val response = ImageSourceResponse(URL("http://localhost:8080/test.jpg"))
val useCaseOut = PutImageUseCaseOut(response.url)
val useCaseIn = PutImageUseCaseIn(request.source)
`when`(putImageUseCase.execute(useCaseIn)).thenReturn(useCaseOut)

// when
mockMvc.perform(
multipart(uri)
.file(request.source as MockMultipartFile)
.contentType(MediaType.MULTIPART_FORM_DATA_VALUE)
)
.andExpect(status().isOk)
.andDo(
document(
api.toIdentifier(),
resource(
ResourceSnippetParameters.builder()
.summary(api.toIdentifier())
.description("이미지 업로드")
.tag(TAG)
.requestSchema(Schema.schema(api.toRequestSchema()))
.responseSchema(Schema.schema(api.toResponseSchema())).responseFields(
*Description.describe(
arrayOf(
PayloadDocumentation.fieldWithPath("data")
.fieldWithObject("data"),
PayloadDocumentation.fieldWithPath("data.url")
.fieldWithString(
"이미지 URL"
)
)
)
).build()
)
)

)
}
}

This file was deleted.

0 comments on commit af75f56

Please sign in to comment.