관리자
- 시리즈 장르 등록, 수정, 삭제 API 추가 크리에이터 관리자 - 시리즈 장르 조회 API 추가
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package kr.co.vividnext.sodalive.admin.content.series.genre
|
||||
|
||||
import kr.co.vividnext.sodalive.common.ApiResponse
|
||||
import org.springframework.security.access.prepost.PreAuthorize
|
||||
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.RestController
|
||||
|
||||
@RestController
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
@RequestMapping("/admin/audio-content/series/genre")
|
||||
class AdminContentSeriesGenreController(private val service: AdminContentSeriesGenreService) {
|
||||
@PostMapping
|
||||
fun createSeriesGenre(@RequestBody request: CreateSeriesGenreRequest) =
|
||||
ApiResponse.ok(service.createSeriesGenre(genre = request.genre), "생성되었습니다.")
|
||||
|
||||
@PutMapping
|
||||
fun modifySeriesGenre(@RequestBody request: ModifySeriesGenreRequest) = ApiResponse.ok(
|
||||
service.modifySeriesGenre(request = request),
|
||||
"수정되었습니다."
|
||||
)
|
||||
|
||||
@PutMapping("/orders")
|
||||
fun modifySeriesGenreOrders(@RequestBody request: ModifySeriesGenreOrderRequest) = ApiResponse.ok(
|
||||
service.modifySeriesGenreOrders(ids = request.ids),
|
||||
"수정되었습니다."
|
||||
)
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
package kr.co.vividnext.sodalive.admin.content.series.genre
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
|
||||
interface AdminContentSeriesGenreRepository : JpaRepository<SeriesGenre, Long>, AdminContentSeriesGenreQueryRepository
|
||||
|
||||
interface AdminContentSeriesGenreQueryRepository
|
||||
|
||||
class AdminContentSeriesGenreQueryRepositoryImpl : AdminContentSeriesGenreQueryRepository
|
@@ -0,0 +1,49 @@
|
||||
package kr.co.vividnext.sodalive.admin.content.series.genre
|
||||
|
||||
import kr.co.vividnext.sodalive.common.SodaException
|
||||
import org.springframework.data.repository.findByIdOrNull
|
||||
import org.springframework.stereotype.Service
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
|
||||
@Service
|
||||
class AdminContentSeriesGenreService(private val repository: AdminContentSeriesGenreRepository) {
|
||||
|
||||
@Transactional
|
||||
fun createSeriesGenre(genre: String) {
|
||||
val seriesGenre = SeriesGenre(genre = genre.trim())
|
||||
repository.save(seriesGenre)
|
||||
}
|
||||
|
||||
@Transactional
|
||||
fun modifySeriesGenre(request: ModifySeriesGenreRequest) {
|
||||
if (request.genre == null && request.isAdult == null && request.isActive == null) {
|
||||
throw SodaException("변경사항이 없습니다.")
|
||||
}
|
||||
|
||||
val seriesGenre = repository.findByIdOrNull(id = request.id)
|
||||
?: throw SodaException("잘못된 요청입니다.")
|
||||
|
||||
if (request.genre != null) {
|
||||
seriesGenre.genre = request.genre
|
||||
}
|
||||
|
||||
if (request.isAdult != null) {
|
||||
seriesGenre.isAdult = request.isAdult
|
||||
}
|
||||
|
||||
if (request.isActive != null) {
|
||||
seriesGenre.isActive = request.isActive
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
fun modifySeriesGenreOrders(ids: List<Long>) {
|
||||
for (index in ids.indices) {
|
||||
val seriesGenre = repository.findByIdOrNull(ids[index])
|
||||
|
||||
if (seriesGenre != null) {
|
||||
seriesGenre.orders = index + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
package kr.co.vividnext.sodalive.admin.content.series.genre
|
||||
|
||||
data class CreateSeriesGenreRequest(val genre: String, val isAdult: Boolean)
|
@@ -0,0 +1,5 @@
|
||||
package kr.co.vividnext.sodalive.admin.content.series.genre
|
||||
|
||||
data class ModifySeriesGenreRequest(val id: Long, val genre: String?, val isAdult: Boolean?, val isActive: Boolean?)
|
||||
|
||||
data class ModifySeriesGenreOrderRequest(val ids: List<Long>)
|
@@ -0,0 +1,17 @@
|
||||
package kr.co.vividnext.sodalive.admin.content.series.genre
|
||||
|
||||
import kr.co.vividnext.sodalive.common.BaseEntity
|
||||
import javax.persistence.Column
|
||||
import javax.persistence.Entity
|
||||
|
||||
@Entity
|
||||
data class SeriesGenre(
|
||||
@Column(nullable = false)
|
||||
var genre: String,
|
||||
@Column(nullable = false)
|
||||
var isAdult: Boolean = false,
|
||||
@Column(nullable = false)
|
||||
var isActive: Boolean = true,
|
||||
@Column(nullable = false)
|
||||
var orders: Int = 1
|
||||
) : BaseEntity()
|
Reference in New Issue
Block a user