/*
* Copyright (c) 2023. yo-saito. All Rights Reserved.
*/
package net.piedpiper.bremer.service.domain
import net.piedpiper.bremer.entity.PlaylistEntity
import net.piedpiper.bremer.repository.PlaylistRepository
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.util.*
@Service("bremer.service.PlaylistDomainService")
class PlaylistDomainService(
private val playlistRepository: PlaylistRepository
) {
@Transactional
fun findAll(): List<PlaylistEntity> = playlistRepository.findAll()
@Transactional
fun findOneBySlug(slug: String): PlaylistEntity? = playlistRepository.findBySlug(slug)
@Transactional
fun insertOne(entity: PlaylistEntity): PlaylistEntity = playlistRepository.insertOne(entity)
.let { playlistRepository.findOneById(it) ?: throw IllegalStateException() }
@Transactional
fun updateOne(entity: PlaylistEntity): PlaylistEntity {
playlistRepository.updateOne(entity)
return playlistRepository.findOneById(entity.id) ?: throw IllegalStateException()
}
}