diff --git a/src/main/kotlin/dao/AlbumDao.kt b/src/main/kotlin/dao/AlbumDao.kt
index 57b3b7d..b92fe0d 100644
--- a/src/main/kotlin/dao/AlbumDao.kt
+++ b/src/main/kotlin/dao/AlbumDao.kt
@@ -17,6 +17,19 @@
interface AlbumDao {
@ResultMap("net.piedpiper.bremer.AlbumEntity")
+ @Select("""""")
+ fun findAllByArtistIdInLimit(
+ @Param("artistIds") artistIds: List,
+ @Param("limit") limit: Int
+ ): List
+
+ @ResultMap("net.piedpiper.bremer.AlbumEntity")
@Select("SELECT * FROM album WHERE name LIKE CONCAT('%', #{nameLike}, '%') LIMIT #{limit}")
fun findAllByNameLikeLimit(
@Param("nameLike") nameLike: String,
diff --git a/src/main/kotlin/dao/ArtistDao.kt b/src/main/kotlin/dao/ArtistDao.kt
index 277f3a9..b6504ee 100644
--- a/src/main/kotlin/dao/ArtistDao.kt
+++ b/src/main/kotlin/dao/ArtistDao.kt
@@ -4,7 +4,6 @@
package net.piedpiper.bremer.dao
-import net.piedpiper.bremer.entity.AlbumEntity
import net.piedpiper.bremer.entity.ArtistEntity
import org.apache.ibatis.annotations.Mapper
import org.apache.ibatis.annotations.Param
diff --git a/src/main/kotlin/dao/AudioDao.kt b/src/main/kotlin/dao/AudioDao.kt
index 56b7fa0..dc2c2a7 100644
--- a/src/main/kotlin/dao/AudioDao.kt
+++ b/src/main/kotlin/dao/AudioDao.kt
@@ -5,8 +5,8 @@
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
import net.piedpiper.bremer.utils.WHERE_IN
import org.apache.ibatis.annotations.*
@@ -25,10 +25,6 @@
fun findOneBySlug(@Param("slug") slug: String): AudioEntity?
@ResultMap("net.piedpiper.bremer.AudioEntity")
- @SelectProvider(type = Sql::class, method = "findAllByArtistIdIn")
- fun findAllByArtistIdIn(@Param("artistIds") artistIds: List): List
-
- @ResultMap("net.piedpiper.bremer.AudioEntity")
@SelectProvider(type = Sql::class, method = "findAllByAlbumIdIn")
fun findAllByAlbumIdIn(@Param("albumIds") albumIds: List): List
@@ -64,14 +60,6 @@
.toString()
@JvmStatic
- fun findAllByArtistIdIn(@Param("artistIds") artistIds: List): String =
- SelectSQLBuilder(AudioEntity::class)
- .leftOuterJoin(AlbumEntity::class, "audio.album_id = album.id")
- .toSql()
- .WHERE_IN("audio.artist_id", "artistIds", artistIds.size)
- .toString()
-
- @JvmStatic
fun findAllByAlbumIdIn(@Param("albumIds") albumIds: List): String =
SelectSQLBuilder(AudioEntity::class)
.leftOuterJoin(AlbumEntity::class, "audio.album_id = album.id")
@@ -102,8 +90,12 @@
): String =
SelectSQLBuilder(AudioEntity::class)
.leftOuterJoin(AlbumEntity::class, "audio.album_id = album.id")
+ .leftOuterJoin(AudioNameEntity::class, "audio.id = audio_name.audio_id")
.toSql()
- .WHERE("audio.name LIKE CONCAT('%', #{nameLike}, '%')")
+ .WHERE(
+ "audio.name LIKE CONCAT('%', #{nameLike}, '%') OR " +
+ "audio_name.name LIKE CONCAT('%', #{nameLike}, '%')"
+ )
.LIMIT("#{limit}")
.toString()
}
diff --git a/src/main/kotlin/entity/Audio.kt b/src/main/kotlin/entity/Audio.kt
index 0363347..4892970 100644
--- a/src/main/kotlin/entity/Audio.kt
+++ b/src/main/kotlin/entity/Audio.kt
@@ -21,7 +21,18 @@
@property:Column("path")
var path: String = "",
// join
- var album: AlbumEntity? = null
+ var album: AlbumEntity? = null,
+ var aliasNames: List? = null
+)
+
+@Table("audio_name")
+data class AudioNameEntity(
+ @property:Column("id", insertable = false, updatable = false)
+ var id: Long = 0L,
+ @property:Column("audio_id")
+ var audioId: Long = 0L,
+ @property:Column("name")
+ var name: String = ""
)
@Table("album")
diff --git a/src/main/kotlin/model/api/Audio.kt b/src/main/kotlin/model/api/Audio.kt
index e3557a0..3f0059d 100644
--- a/src/main/kotlin/model/api/Audio.kt
+++ b/src/main/kotlin/model/api/Audio.kt
@@ -19,5 +19,6 @@
val slug: String = entity.slug
val artist: String? = entity?.album?.artist?.name
val album: String? = entity?.album?.name
+ var aliasNames: List? = entity?.aliasNames?.map { it.name }
}
}
\ No newline at end of file
diff --git a/src/main/kotlin/repository/AudioRepository.kt b/src/main/kotlin/repository/AudioRepository.kt
index 8393b5e..8e0ca5f 100644
--- a/src/main/kotlin/repository/AudioRepository.kt
+++ b/src/main/kotlin/repository/AudioRepository.kt
@@ -13,7 +13,6 @@
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.stereotype.Repository
import java.time.LocalDateTime
-import java.time.ZoneId
@Repository("bremer.repository.AudioRepository")
class AudioRepository(
@@ -40,8 +39,14 @@
fun findAllByArtistNameLikeLimit(artistNameLike: String, limit: Int): List {
val artists = artistDao.findAllByNameLikeLimit(artistNameLike, limit)
- return if (artists.isNotEmpty()) audioDao
- .findAllByArtistIdIn(artists.map { it.id }) else emptyList()
+ if (artists.isEmpty()) {
+ return emptyList()
+ }
+ val albums = albumDao.findAllByArtistIdInLimit(artists.map { it.id }.distinct(), limit)
+ if (albums.isEmpty()) {
+ return emptyList()
+ }
+ return audioDao.findAllByAlbumIdIn(albums.map { it.id }.distinct())
}
fun findAllByAlbumNameLikeLimit(albumNameLike: String, limit: Int): List {
diff --git a/src/main/kotlin/service/app/AudioAppService.kt b/src/main/kotlin/service/app/AudioAppService.kt
index 96d6f70..3729b42 100644
--- a/src/main/kotlin/service/app/AudioAppService.kt
+++ b/src/main/kotlin/service/app/AudioAppService.kt
@@ -4,12 +4,10 @@
package net.piedpiper.bremer.service.app
-import net.piedpiper.bremer.config.Log
import net.piedpiper.bremer.entity.AudioPlayHistoryEntity
import net.piedpiper.bremer.exception.NotFoundException
import net.piedpiper.bremer.model.api.AudioListResponse
import net.piedpiper.bremer.service.domain.AudioDomainService
-import org.slf4j.Logger
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
@@ -53,7 +51,7 @@
albumName: String?
): AudioListResponse =
AudioListResponse(
- audioDomainService.findAllByKeywords(
+ audioDomainService.findAllByKeyword(
audioName,
artistName,
albumName,
diff --git a/src/main/kotlin/service/domain/AudioDomainService.kt b/src/main/kotlin/service/domain/AudioDomainService.kt
index 4ab9108..62cb8b4 100644
--- a/src/main/kotlin/service/domain/AudioDomainService.kt
+++ b/src/main/kotlin/service/domain/AudioDomainService.kt
@@ -44,7 +44,7 @@
fun findAllLruLimit(limit: Int): List = audioRepository.findAllLruLimit(limit)
@Transactional
- fun findAllByKeywords(
+ fun findAllByKeyword(
nameLike: String?,
artistNameLike: String?,
albumNameLike: String?,
diff --git a/src/main/resources/mapper/mapper.xml b/src/main/resources/mapper/mapper.xml
index e8f7a6a..39ff746 100644
--- a/src/main/resources/mapper/mapper.xml
+++ b/src/main/resources/mapper/mapper.xml
@@ -6,21 +6,27 @@
-
+
+
+
+
+
+
+
-
+
diff --git a/src/main/resources/static/bremer/login.html b/src/main/resources/static/bremer/login.html
index fc6ab61..7dc8666 100644
--- a/src/main/resources/static/bremer/login.html
+++ b/src/main/resources/static/bremer/login.html
@@ -23,9 +23,9 @@