관리자 - 라이브 관심사 등록/수정/삭제 API
This commit is contained in:
parent
12c9b14168
commit
38f6e8d870
|
@ -1,12 +1,17 @@
|
||||||
package kr.co.vividnext.sodalive.live.tag
|
package kr.co.vividnext.sodalive.live.tag
|
||||||
|
|
||||||
|
import kr.co.vividnext.sodalive.admin.member.tag.UpdateTagOrdersRequest
|
||||||
import kr.co.vividnext.sodalive.common.ApiResponse
|
import kr.co.vividnext.sodalive.common.ApiResponse
|
||||||
import kr.co.vividnext.sodalive.common.SodaException
|
import kr.co.vividnext.sodalive.common.SodaException
|
||||||
import kr.co.vividnext.sodalive.member.Member
|
import kr.co.vividnext.sodalive.member.Member
|
||||||
import org.springframework.security.access.prepost.PreAuthorize
|
import org.springframework.security.access.prepost.PreAuthorize
|
||||||
import org.springframework.security.core.annotation.AuthenticationPrincipal
|
import org.springframework.security.core.annotation.AuthenticationPrincipal
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping
|
||||||
import org.springframework.web.bind.annotation.GetMapping
|
import org.springframework.web.bind.annotation.GetMapping
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable
|
||||||
import org.springframework.web.bind.annotation.PostMapping
|
import org.springframework.web.bind.annotation.PostMapping
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody
|
||||||
import org.springframework.web.bind.annotation.RequestMapping
|
import org.springframework.web.bind.annotation.RequestMapping
|
||||||
import org.springframework.web.bind.annotation.RequestPart
|
import org.springframework.web.bind.annotation.RequestPart
|
||||||
import org.springframework.web.bind.annotation.RestController
|
import org.springframework.web.bind.annotation.RestController
|
||||||
|
@ -22,6 +27,24 @@ class LiveTagController(private val service: LiveTagService) {
|
||||||
@RequestPart("request") requestString: String
|
@RequestPart("request") requestString: String
|
||||||
) = ApiResponse.ok(service.enrollmentLiveTag(image, requestString), "등록되었습니다.")
|
) = ApiResponse.ok(service.enrollmentLiveTag(image, requestString), "등록되었습니다.")
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
@PreAuthorize("hasRole('ADMIN')")
|
||||||
|
fun deleteSudaTag(@PathVariable id: Long) = ApiResponse.ok(service.deleteTag(id), "삭제되었습니다.")
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
@PreAuthorize("hasRole('ADMIN')")
|
||||||
|
fun modifySudaTag(
|
||||||
|
@PathVariable id: Long,
|
||||||
|
@RequestPart("image") image: MultipartFile?,
|
||||||
|
@RequestPart("request") requestString: String
|
||||||
|
) = ApiResponse.ok(service.modifyTag(id, image, requestString), "수정되었습니다.")
|
||||||
|
|
||||||
|
@PutMapping("/orders")
|
||||||
|
@PreAuthorize("hasRole('ADMIN')")
|
||||||
|
fun updateTagOrders(
|
||||||
|
@RequestBody request: UpdateTagOrdersRequest
|
||||||
|
) = ApiResponse.ok(service.updateTagOrders(request.ids), "수정되었습니다.")
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
fun getTags(
|
fun getTags(
|
||||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
||||||
|
|
|
@ -7,7 +7,9 @@ import kr.co.vividnext.sodalive.common.SodaException
|
||||||
import kr.co.vividnext.sodalive.member.Member
|
import kr.co.vividnext.sodalive.member.Member
|
||||||
import kr.co.vividnext.sodalive.utils.generateFileName
|
import kr.co.vividnext.sodalive.utils.generateFileName
|
||||||
import org.springframework.beans.factory.annotation.Value
|
import org.springframework.beans.factory.annotation.Value
|
||||||
|
import org.springframework.data.repository.findByIdOrNull
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
import org.springframework.transaction.annotation.Transactional
|
||||||
import org.springframework.web.multipart.MultipartFile
|
import org.springframework.web.multipart.MultipartFile
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@ -22,6 +24,7 @@ class LiveTagService(
|
||||||
@Value("\${cloud.aws.cloud-front.host}")
|
@Value("\${cloud.aws.cloud-front.host}")
|
||||||
private val cloudFrontHost: String
|
private val cloudFrontHost: String
|
||||||
) {
|
) {
|
||||||
|
@Transactional
|
||||||
fun enrollmentLiveTag(image: MultipartFile, requestString: String) {
|
fun enrollmentLiveTag(image: MultipartFile, requestString: String) {
|
||||||
val request = objectMapper.readValue(requestString, CreateLiveTagRequest::class.java)
|
val request = objectMapper.readValue(requestString, CreateLiveTagRequest::class.java)
|
||||||
tagExistCheck(request)
|
tagExistCheck(request)
|
||||||
|
@ -42,6 +45,50 @@ class LiveTagService(
|
||||||
tag.image = tagImagePath
|
tag.image = tagImagePath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
fun deleteTag(id: Long) {
|
||||||
|
val tag = repository.findByIdOrNull(id)
|
||||||
|
?: throw SodaException("잘못된 요청입니다.")
|
||||||
|
|
||||||
|
tag.tag = "${tag.tag}_deleted"
|
||||||
|
tag.isActive = false
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
fun modifyTag(id: Long, image: MultipartFile?, requestString: String) {
|
||||||
|
val tag = repository.findByIdOrNull(id)
|
||||||
|
?: throw SodaException("잘못된 요청입니다.")
|
||||||
|
|
||||||
|
val request = objectMapper.readValue(requestString, CreateLiveTagRequest::class.java)
|
||||||
|
tag.tag = request.tag
|
||||||
|
|
||||||
|
if (image != null) {
|
||||||
|
val metadata = ObjectMetadata()
|
||||||
|
metadata.contentLength = image.size
|
||||||
|
|
||||||
|
val tagImageFileName = generateFileName(prefix = "${tag.id}-")
|
||||||
|
val tagImagePath = s3Uploader.upload(
|
||||||
|
inputStream = image.inputStream,
|
||||||
|
bucket = coverImageBucket,
|
||||||
|
filePath = "live_cover/${tag.id}/$tagImageFileName",
|
||||||
|
metadata = metadata
|
||||||
|
)
|
||||||
|
|
||||||
|
tag.image = tagImagePath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
fun updateTagOrders(ids: List<Long>) {
|
||||||
|
for (index in ids.indices) {
|
||||||
|
val tag = repository.findByIdOrNull(ids[index])
|
||||||
|
|
||||||
|
if (tag != null) {
|
||||||
|
tag.orders = index + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getTags(member: Member): List<GetLiveTagResponse> {
|
fun getTags(member: Member): List<GetLiveTagResponse> {
|
||||||
return repository.getTags(role = member.role, isAdult = member.auth != null, cloudFrontHost = cloudFrontHost)
|
return repository.getTags(role = member.role, isAdult = member.auth != null, cloudFrontHost = cloudFrontHost)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue