Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DVK-110] fix: 전자책 메인 사진 업로드 수정 #82

Merged
merged 2 commits into from
Nov 23, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ interface EbookImageControllerDocs {
),
ApiResponse(
responseCode = "400",
description = "- EBOOK-400-18: 메인 사진이 반드시 필요합니다.\n" +
description = "- COMMON-400-6: 사진이 반드시 필요합니다.\n" +
"- COMMON-400-3: 사진 내용이 반드시 필요합니다.\n" +
"- COMMON-400-4: 유효하지 않은 사진 확장자입니다. JPG, PNG, JPEG만 가능합니다.\n" +
"- COMMON-400-5: 50MB 이하의 영상만 저장이 가능합니다.\n" +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,18 @@
package com.devooks.backend.ebook.v1.dto.request

import com.devooks.backend.common.domain.Image
import com.devooks.backend.common.domain.Image.Companion.validateByteSize
import com.devooks.backend.common.domain.ImageExtension.Companion.validateImageExtension
import com.devooks.backend.common.error.CommonError
import com.devooks.backend.common.error.validateNotBlank
import com.devooks.backend.common.dto.ImageDto
import com.devooks.backend.common.error.validateImage
import com.devooks.backend.ebook.v1.domain.EbookImageType.MAIN
import com.devooks.backend.ebook.v1.dto.command.SaveImagesCommand
import com.devooks.backend.ebook.v1.error.EbookError
import java.util.*

data class SaveMainImageRequest(
val image: MainImageDto?,
val image: ImageDto?,
) {

data class MainImageDto(
val base64Raw: String?,
val extension: String?,
val byteSize: Long?,
) {
fun toCommand() =
Image(
base64Raw = base64Raw.validateNotBlank(CommonError.REQUIRED_BASE64RAW.exception),
extension = extension.validateImageExtension(),
byteSize = byteSize.validateByteSize(),
order = 1
)
}

fun toCommand(requesterId: UUID) =
SaveImagesCommand(
imageList = listOf(image?.toCommand() ?: throw EbookError.REQUIRED_MAIN_IMAGE.exception),
imageList = listOf(image.validateImage()),
requesterId = requesterId,
imageType = MAIN
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
package com.devooks.backend.ebook.v1.dto.response

import com.devooks.backend.ebook.v1.domain.EbookImage
import io.swagger.v3.oas.annotations.media.Schema
import java.util.*
import kotlin.io.path.pathString
import com.devooks.backend.ebook.v1.dto.EbookImageDto
import com.devooks.backend.ebook.v1.dto.EbookImageDto.Companion.toDto

data class SaveMainImageResponse(
val mainImage: MainImageDto,
val mainImage: EbookImageDto,
) {
data class MainImageDto(
@Schema(description = "메인 사진 식별자")
val id: UUID,
@Schema(description = "메인 사진 경로")
val imagePath: String,
)

companion object {
fun EbookImage.toSaveMainImageResponse() =
SaveMainImageResponse(
MainImageDto(
id = id,
imagePath = imagePath.pathString
)
)
SaveMainImageResponse(toDto())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ enum class EbookError(val exception: GeneralException) {
INVALID_EBOOK_INQUIRY_COMMENT_ID(GeneralException("EBOOK-400-15", BAD_REQUEST, "잘못된 형식의 댓글 식별자입니다.")),
INVALID_EBOOK_ID(GeneralException("EBOOK-400-16", BAD_REQUEST, "잘못된 형식의 전자책 식별자입니다.")),
REQUIRED_EBOOK_FOR_MODIFY(GeneralException("EBOOK-400-17", BAD_REQUEST, "전자책이 반드시 필요합니다.")),
REQUIRED_MAIN_IMAGE(GeneralException("EBOOK-400-18", BAD_REQUEST, "메인 사진이 반드시 필요합니다.")),
REQUIRED_MAIN_IMAGE_ID(GeneralException("EBOOK-400-19", BAD_REQUEST, "메인 사진 식별자가 반드시 필요합니다.")),
INVALID_MAIN_IMAGE_ID(GeneralException("EBOOK-400-20", BAD_REQUEST, "잘못된 형식의 메인 사진 식별자입니다.")),
REQUIRED_DESCRIPTION_IMAGE_ID(GeneralException("EBOOK-400-21", BAD_REQUEST, "설명 사진 식별자가 반드시 필요합니다.")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1059,12 +1059,13 @@ internal class EbookControllerTest @Autowired constructor(
imageBase64Raw: String?,
imagePath: Path,
accessToken: AccessToken,
): SaveMainImageResponse.MainImageDto {
): EbookImageDto {
val saveMainImageRequest = SaveMainImageRequest(
SaveMainImageRequest.MainImageDto(
imageBase64Raw,
imagePath.extension,
imagePath.fileSize(),
ImageDto(
base64Raw = imageBase64Raw,
extension = imagePath.extension,
byteSize = imagePath.fileSize(),
order = 1
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,11 @@ internal class EbookImageControllerTest @Autowired constructor(
val imageBase64Raw = Base64.getEncoder().encodeToString(imageBytes)

val request = SaveMainImageRequest(
SaveMainImageRequest.MainImageDto(
ImageDto(
imageBase64Raw,
imagePath.extension,
imagePath.fileSize(),
1
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,13 @@ internal class EbookInquiryCommentControllerTest @Autowired constructor(
imageBase64Raw: String?,
imagePath: Path,
accessToken: AccessToken,
): SaveMainImageResponse.MainImageDto {
): EbookImageDto {
val saveMainImageRequest = SaveMainImageRequest(
SaveMainImageRequest.MainImageDto(
ImageDto(
imageBase64Raw,
imagePath.extension,
imagePath.fileSize(),
1
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,13 @@ internal class EbookInquiryControllerTest @Autowired constructor(
imageBase64Raw: String?,
imagePath: Path,
accessToken: AccessToken,
): SaveMainImageResponse.MainImageDto {
): EbookImageDto {
val saveMainImageRequest = SaveMainImageRequest(
SaveMainImageRequest.MainImageDto(
ImageDto(
imageBase64Raw,
imagePath.extension,
imagePath.fileSize(),
1
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,12 +430,13 @@ internal class ReviewCommentControllerTest @Autowired constructor(
imageBase64Raw: String?,
imagePath: Path,
accessToken: AccessToken,
): SaveMainImageResponse.MainImageDto {
): EbookImageDto {
val saveMainImageRequest = SaveMainImageRequest(
SaveMainImageRequest.MainImageDto(
ImageDto(
imageBase64Raw,
imagePath.extension,
imagePath.fileSize(),
1
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,12 +518,13 @@ internal class ReviewControllerTest @Autowired constructor(
imageBase64Raw: String?,
imagePath: Path,
accessToken: AccessToken,
): SaveMainImageResponse.MainImageDto {
): EbookImageDto {
val saveMainImageRequest = SaveMainImageRequest(
SaveMainImageRequest.MainImageDto(
ImageDto(
imageBase64Raw,
imagePath.extension,
imagePath.fileSize(),
1
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,13 @@ internal class TransactionControllerTest @Autowired constructor(
imageBase64Raw: String?,
imagePath: Path,
accessToken: AccessToken,
): SaveMainImageResponse.MainImageDto {
): EbookImageDto {
val saveMainImageRequest = SaveMainImageRequest(
SaveMainImageRequest.MainImageDto(
ImageDto(
imageBase64Raw,
imagePath.extension,
imagePath.fileSize(),
1
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,13 @@ internal class WishlistControllerTest @Autowired constructor(
imageBase64Raw: String?,
imagePath: Path,
accessToken: AccessToken,
): SaveMainImageResponse.MainImageDto {
): EbookImageDto {
val saveMainImageRequest = SaveMainImageRequest(
SaveMainImageRequest.MainImageDto(
ImageDto(
imageBase64Raw,
imagePath.extension,
imagePath.fileSize(),
1
)
)

Expand Down
Loading