Skip to content

Commit

Permalink
feat :: Add Update BannerLink
Browse files Browse the repository at this point in the history
  • Loading branch information
rudeh2926 committed Nov 12, 2023
1 parent 1f76fae commit 2d8331e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package hs.kr.equus.feed.domain.banner.exception

import hs.kr.equus.feed.global.error.exception.EquusException
import hs.kr.equus.feed.global.error.exception.ErrorCode

object BannerLinkNotFoundException : EquusException (
ErrorCode.BANNERLINK_NOT_FOUND
)
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
package hs.kr.equus.feed.domain.banner.presentation

import hs.kr.equus.feed.domain.banner.service.CreateBannerLinkService
import hs.kr.equus.feed.domain.banner.service.UpdateBannerLinkService
import org.springframework.http.HttpStatus
import org.springframework.lang.Nullable
import org.springframework.web.bind.annotation.PatchMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestPart
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.multipart.MultipartFile
import java.util.UUID

@RequestMapping("/banner")
@RestController
class BannerLinkController(
private val createBannerLinkService: CreateBannerLinkService
private val createBannerLinkService: CreateBannerLinkService,
private val updateBannerLinkService: UpdateBannerLinkService
) {
@ResponseStatus(HttpStatus.CREATED)
@PostMapping
fun createBannerLink(@RequestPart(name = "photo") file: MultipartFile): String =
createBannerLinkService.execute(file)

@PatchMapping("/{banner-id}")
fun updateBannerLink(@RequestPart(name = "photo") @Nullable file: MultipartFile,
@PathVariable("banner-id") bannerId : UUID): String =
updateBannerLinkService.execute(file, bannerId)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package hs.kr.equus.feed.domain.banner.service

import hs.kr.equus.feed.domain.banner.domain.BannerLink
import hs.kr.equus.feed.domain.banner.domain.repository.BannerLinkRepository
import hs.kr.equus.feed.domain.banner.exception.BannerLinkNotFoundException
import hs.kr.equus.feed.global.utils.s3.S3Utils
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.multipart.MultipartFile
import java.util.UUID

@Service
class UpdateBannerLinkService (
private val bannerLinkRepository: BannerLinkRepository,
private val s3Utils: S3Utils
){
@Transactional
fun execute(file : MultipartFile, id : UUID) : String {
val bannerLink : BannerLink = bannerLinkRepository.findById(id)
.orElseThrow {BannerLinkNotFoundException}

val fileName = s3Utils.upload(file, "banner/")

bannerLink.updateBanner(fileName)

return s3Utils.generateObjectUrl(fileName)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum class ErrorCode(
QUESTION_NOT_FOUND(404, "Question Not Found"),
REPLY_NOT_FOUND(404, "Reply Not Found"),
FAQ_NOT_FOUND(404, "Faq Not Found"),
BANNERLINK_NOT_FOUND(404, "BannerLink Not Found"),

// Conflict
REPLY_EXISTS(409, "Reply Already Exists")
Expand Down

0 comments on commit 2d8331e

Please sign in to comment.