diff --git a/src/main/kotlin/dao/AlbumDao.kt b/src/main/kotlin/dao/AlbumDao.kt
index b92fe0d..532d0c3 100644
--- a/src/main/kotlin/dao/AlbumDao.kt
+++ b/src/main/kotlin/dao/AlbumDao.kt
@@ -5,11 +5,10 @@
package net.piedpiper.bremer.dao
import net.piedpiper.bremer.entity.AlbumEntity
+import net.piedpiper.bremer.entity.AudioEntity
import net.piedpiper.bremer.entity.AudioPlayHistoryEntity
-import org.apache.ibatis.annotations.Mapper
-import org.apache.ibatis.annotations.Param
-import org.apache.ibatis.annotations.ResultMap
-import org.apache.ibatis.annotations.Select
+import net.piedpiper.bremer.utils.DaoUtils
+import org.apache.ibatis.annotations.*
import org.springframework.stereotype.Repository
@Repository("bremer.dao.AlbumDao")
@@ -17,13 +16,19 @@
interface AlbumDao {
@ResultMap("net.piedpiper.bremer.AlbumEntity")
- @Select("""""")
+ """
+ )
fun findAllByArtistIdInLimit(
@Param("artistIds") artistIds: List,
@Param("limit") limit: Int
@@ -35,4 +40,15 @@
@Param("nameLike") nameLike: String,
@Param("limit") limit: Int
): List
+
+ @UpdateProvider(type = Sql::class, method = "updateOne")
+ fun updateOne(@Param("entity") entity: AlbumEntity)
+
+ class Sql {
+ companion object {
+ @JvmStatic
+ fun updateOne(@Param("entity") entity: AlbumEntity): String =
+ DaoUtils.updateOne(entity)
+ }
+ }
}
\ No newline at end of file
diff --git a/src/main/kotlin/dao/ArtistDao.kt b/src/main/kotlin/dao/ArtistDao.kt
index b6504ee..e3ec6fb 100644
--- a/src/main/kotlin/dao/ArtistDao.kt
+++ b/src/main/kotlin/dao/ArtistDao.kt
@@ -5,10 +5,8 @@
package net.piedpiper.bremer.dao
import net.piedpiper.bremer.entity.ArtistEntity
-import org.apache.ibatis.annotations.Mapper
-import org.apache.ibatis.annotations.Param
-import org.apache.ibatis.annotations.ResultMap
-import org.apache.ibatis.annotations.Select
+import net.piedpiper.bremer.utils.DaoUtils
+import org.apache.ibatis.annotations.*
import org.springframework.stereotype.Repository
@Repository("bremer.dao.ArtistDao")
@@ -21,4 +19,19 @@
@Param("nameLike") nameLike: String,
@Param("limit") limit: Int
): List
+
+ @ResultMap("net.piedpiper.bremer.ArtistEntity")
+ @Select("SELECT * FROM artist WHERE id = #{id} FOR UPDATE")
+ fun findOneByIdWithLock(@Param("id") id: Long) : ArtistEntity?
+
+ @UpdateProvider(type = Sql::class, method = "updateOne")
+ fun updateOne(@Param("entity") entity: ArtistEntity)
+
+ class Sql {
+ companion object {
+ @JvmStatic
+ fun updateOne(@Param("entity") entity: ArtistEntity): String =
+ DaoUtils.updateOne(entity)
+ }
+ }
}
\ No newline at end of file
diff --git a/src/main/kotlin/service/AudioService.kt b/src/main/kotlin/service/AudioService.kt
index 3cf4e78..8b04853 100644
--- a/src/main/kotlin/service/AudioService.kt
+++ b/src/main/kotlin/service/AudioService.kt
@@ -93,13 +93,24 @@
}
@Transactional
- fun update(slug: String, request: AudioRequest)
- = audioDao.findOneBySlugWithLock(slug)
+ fun update(slug: String, request: AudioRequest) = audioDao.findOneBySlugWithLock(slug)
?.let {
- request?.name?.apply {
+ request.name?.apply {
it.name = request.name
audioDao.updateOne(it)
}
+ albumDao.findOneByIdWithLock(it.albumId)?.let { album ->
+ request.album?.apply {
+ album.name = request.album
+ albumDao.updateOne(album)
+ }
+ request.artist?.apply {
+ artistDao.findOneByIdWithLock(album.artistId)?.let { artist ->
+ artist.name = request.artist
+ artistDao.updateOne(artist)
+ }
+ }
+ }
} ?: throw NotFoundException()
private fun findAllByArtistNameLikeLimit(