diff --git a/adapters/in-web/src/main/kotlin/com/pokit/content/ContentController.kt b/adapters/in-web/src/main/kotlin/com/pokit/content/ContentController.kt index 0ca8feb2..a5111636 100644 --- a/adapters/in-web/src/main/kotlin/com/pokit/content/ContentController.kt +++ b/adapters/in-web/src/main/kotlin/com/pokit/content/ContentController.kt @@ -15,6 +15,7 @@ import com.pokit.content.dto.response.ContentResponse import com.pokit.content.dto.response.ContentsResponse import com.pokit.content.dto.response.toResponse import com.pokit.content.exception.ContentErrorCode +import com.pokit.content.model.Content import com.pokit.content.port.`in`.ContentUseCase import io.swagger.v3.oas.annotations.Operation import jakarta.validation.Valid @@ -191,6 +192,16 @@ class ContentController( .wrapUnit() } + @PatchMapping("/thumbnail/{contentId}") + @Operation(summary = "썸네일 수정 API") + fun updateThumbnail( + @AuthenticationPrincipal user: PrincipalUser, + @PathVariable("contentId") contentId: Long, + @RequestBody request: UpdateThumbnailRequest + ): ResponseEntity { + return contentUseCase.updateThumbnail(user.id, contentId,request.toDto()) + .wrapOk() + } } diff --git a/adapters/in-web/src/main/kotlin/com/pokit/content/dto/request/UpdateThumbnailRequest.kt b/adapters/in-web/src/main/kotlin/com/pokit/content/dto/request/UpdateThumbnailRequest.kt new file mode 100644 index 00000000..c9402591 --- /dev/null +++ b/adapters/in-web/src/main/kotlin/com/pokit/content/dto/request/UpdateThumbnailRequest.kt @@ -0,0 +1,12 @@ +package com.pokit.content.dto.request + +import io.swagger.v3.oas.annotations.media.Schema +import jakarta.validation.constraints.NotBlank + +data class UpdateThumbnailRequest( + @field:Schema(description = "수정할 썸네일 링크") + @field:NotBlank + val thumbnail: String, +) + +internal fun UpdateThumbnailRequest.toDto() = thumbnail diff --git a/application/src/main/kotlin/com/pokit/content/port/in/ContentUseCase.kt b/application/src/main/kotlin/com/pokit/content/port/in/ContentUseCase.kt index 10db9be7..91c3b038 100644 --- a/application/src/main/kotlin/com/pokit/content/port/in/ContentUseCase.kt +++ b/application/src/main/kotlin/com/pokit/content/port/in/ContentUseCase.kt @@ -4,6 +4,7 @@ import com.pokit.content.dto.request.CategorizeCommand import com.pokit.content.dto.request.ContentCommand import com.pokit.content.dto.request.ContentSearchCondition import com.pokit.content.dto.response.* +import com.pokit.content.model.Content import com.pokit.user.model.User import org.springframework.data.domain.Pageable import org.springframework.data.domain.Slice @@ -45,4 +46,6 @@ interface ContentUseCase { fun deleteUncategorized(userId: Long, contentIds: List) fun categorize(userId: Long, command: CategorizeCommand) + + fun updateThumbnail(userId: Long, contentId: Long, thumbnail: String): Content } diff --git a/application/src/main/kotlin/com/pokit/content/port/service/ContentService.kt b/application/src/main/kotlin/com/pokit/content/port/service/ContentService.kt index 158a6773..1a783c3f 100644 --- a/application/src/main/kotlin/com/pokit/content/port/service/ContentService.kt +++ b/application/src/main/kotlin/com/pokit/content/port/service/ContentService.kt @@ -189,6 +189,13 @@ class ContentService( contentPort.updateCategoryId(contents, category.categoryId) } + @Transactional + override fun updateThumbnail(userId: Long, contentId: Long, thumbnail: String): Content { + val content = verifyContent(userId, contentId) + content.modifyThumbnail(thumbnail) + return contentPort.persist(content) + } + private fun verifyContent(userId: Long, contentId: Long): Content { return contentPort.loadByUserIdAndId(userId, contentId) ?: throw NotFoundCustomException(ContentErrorCode.NOT_FOUND_CONTENT) diff --git a/domain/src/main/kotlin/com/pokit/content/model/Content.kt b/domain/src/main/kotlin/com/pokit/content/model/Content.kt index af5176f0..ab7fe6d6 100644 --- a/domain/src/main/kotlin/com/pokit/content/model/Content.kt +++ b/domain/src/main/kotlin/com/pokit/content/model/Content.kt @@ -37,6 +37,10 @@ data class Content( else -> domain } } + + fun modifyThumbnail(thumbnail: String) { + this.thumbNail = thumbnail + } } data class ContentInfo(