diff --git a/src/main/kotlin/dao/AudioDao.kt b/src/main/kotlin/dao/AudioDao.kt index dc2c2a7..a306032 100644 --- a/src/main/kotlin/dao/AudioDao.kt +++ b/src/main/kotlin/dao/AudioDao.kt @@ -5,6 +5,7 @@ package net.piedpiper.bremer.dao import net.piedpiper.bremer.entity.AlbumEntity +import net.piedpiper.bremer.entity.ArtistEntity import net.piedpiper.bremer.entity.AudioEntity import net.piedpiper.bremer.entity.AudioNameEntity import net.piedpiper.bremer.utils.SelectSQLBuilder @@ -48,6 +49,8 @@ @JvmStatic fun findOneById(): String = SelectSQLBuilder(AudioEntity::class) .leftOuterJoin(AlbumEntity::class, "audio.album_id = album.id") + .leftOuterJoin(ArtistEntity::class, "album.artist_id = artist.id", AlbumEntity::class) + .leftOuterJoin(AudioNameEntity::class, "audio.id = audio_name.audio_id") .toSql() .WHERE("audio.id = #{id}") .toString() @@ -55,6 +58,8 @@ @JvmStatic fun findOneBySlug(): String = SelectSQLBuilder(AudioEntity::class) .leftOuterJoin(AlbumEntity::class, "audio.album_id = album.id") + .leftOuterJoin(ArtistEntity::class, "album.artist_id = artist.id", AlbumEntity::class) + .leftOuterJoin(AudioNameEntity::class, "audio.id = audio_name.audio_id") .toSql() .WHERE("audio.slug = #{slug}") .toString() @@ -63,6 +68,8 @@ fun findAllByAlbumIdIn(@Param("albumIds") albumIds: List): String = SelectSQLBuilder(AudioEntity::class) .leftOuterJoin(AlbumEntity::class, "audio.album_id = album.id") + .leftOuterJoin(ArtistEntity::class, "album.artist_id = artist.id", AlbumEntity::class) + .leftOuterJoin(AudioNameEntity::class, "audio.id = audio_name.audio_id") .toSql() .WHERE_IN("audio.album_id", "albumIds", albumIds.size) .toString() @@ -71,6 +78,8 @@ fun findAllByIdIn(@Param("ids") ids: List): String = SelectSQLBuilder(AudioEntity::class) .leftOuterJoin(AlbumEntity::class, "audio.album_id = album.id") + .leftOuterJoin(ArtistEntity::class, "album.artist_id = artist.id", AlbumEntity::class) + .leftOuterJoin(AudioNameEntity::class, "audio.id = audio_name.audio_id") .toSql() .WHERE_IN("audio.id", "ids", ids.size) .toString() @@ -79,6 +88,8 @@ fun findAllBySlugIn(@Param("slugs") slugs: List): String = SelectSQLBuilder(AudioEntity::class) .leftOuterJoin(AlbumEntity::class, "audio.album_id = album.id") + .leftOuterJoin(ArtistEntity::class, "album.artist_id = artist.id", AlbumEntity::class) + .leftOuterJoin(AudioNameEntity::class, "audio.id = audio_name.audio_id") .toSql() .WHERE_IN("audio.slug", "slugs", slugs.size) .toString() @@ -90,12 +101,14 @@ ): String = SelectSQLBuilder(AudioEntity::class) .leftOuterJoin(AlbumEntity::class, "audio.album_id = album.id") + .leftOuterJoin(ArtistEntity::class, "album.artist_id = artist.id", AlbumEntity::class) .leftOuterJoin(AudioNameEntity::class, "audio.id = audio_name.audio_id") .toSql() .WHERE( - "audio.name LIKE CONCAT('%', #{nameLike}, '%') OR " + - "audio_name.name LIKE CONCAT('%', #{nameLike}, '%')" + "audio.name LIKE CONCAT('%', #{nameLike}, '%') OR " + + "audio_name.name LIKE CONCAT('%', #{nameLike}, '%')" ) + .ORDER_BY("audio.album_id, audio.sequence") .LIMIT("#{limit}") .toString() }