Skip to content

Commit

Permalink
[feat #190] 썸네일 수정 API (#191)
Browse files Browse the repository at this point in the history
* feat : 썸네일 수정 API

* feat : 썸네일 수정 비즈니스 로직
  • Loading branch information
dlswns2480 authored Nov 28, 2024
1 parent c905deb commit 4ad50db
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Content> {
return contentUseCase.updateThumbnail(user.id, contentId,request.toDto())
.wrapOk()
}

}

Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -45,4 +46,6 @@ interface ContentUseCase {
fun deleteUncategorized(userId: Long, contentIds: List<Long>)

fun categorize(userId: Long, command: CategorizeCommand)

fun updateThumbnail(userId: Long, contentId: Long, thumbnail: String): Content
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions domain/src/main/kotlin/com/pokit/content/model/Content.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ data class Content(
else -> domain
}
}

fun modifyThumbnail(thumbnail: String) {
this.thumbNail = thumbnail
}
}

data class ContentInfo(
Expand Down

0 comments on commit 4ad50db

Please sign in to comment.