GitBucket
4.23.0
Toggle navigation
Sign in
Files
Branches
1
Releases
Issues
Pull requests
Labels
Priorities
Milestones
Wiki
Forks
yhornisse
/
bremer
Browse code
fix tables
master
1 parent
c9763a5
commit
9db1c3d4cdc160007e72fba548a7e576d83f0bb4
yhornisse
authored
on 9 Jul 2023
Patch
Showing
5 changed files
src/main/kotlin/dao/AudioDao.kt
src/main/kotlin/entity/Audio.kt
src/main/kotlin/model/api/Audio.kt
src/main/kotlin/model/api/Playlist.kt
src/main/resources/mapper/mapper.xml
Ignore Space
Show notes
View
src/main/kotlin/dao/AudioDao.kt
/* * Copyright (c) 2023. yo-saito. All Rights Reserved. */ 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.utils.SelectSQLBuilder import net.piedpiper.bremer.utils.WHERE_IN import org.apache.ibatis.annotations.* import org.springframework.stereotype.Repository @Repository("bremer.dao.AudioDao") @Mapper interface AudioDao { @ResultMap("net.piedpiper.bremer.AudioEntity") @SelectProvider(type = Sql::class, method = "findOneById") fun findOneById(@Param("id") id: Long): AudioEntity? @ResultMap("net.piedpiper.bremer.AudioEntity") @SelectProvider(type = Sql::class, method = "findOneBySlug") fun findOneBySlug(@Param("slug") slug: String): AudioEntity? @ResultMap("net.piedpiper.bremer.AudioEntity") @SelectProvider(type = Sql::class, method = "findAllByArtistIdIn") fun findAllByArtistIdIn(@Param("artistIds") artistIds: List<Long>): List<AudioEntity> @ResultMap("net.piedpiper.bremer.AudioEntity") @SelectProvider(type = Sql::class, method = "findAllByAlbumIdIn") fun findAllByAlbumIdIn(@Param("albumIds") albumIds: List<Long>): List<AudioEntity> @ResultMap("net.piedpiper.bremer.AudioEntity") @SelectProvider(type = Sql::class, method = "findAllByIdIn") fun findAllByIdIn(@Param("ids") ids: List<Long>): List<AudioEntity> @ResultMap("net.piedpiper.bremer.AudioEntity") @SelectProvider(type = Sql::class, method = "findAllBySlugIn") fun findAllBySlugIn(@Param("slugs") ids: List<String>): List<AudioEntity> @ResultMap("net.piedpiper.bremer.AudioEntity") @SelectProvider(type = Sql::class, method = "findAllByNameLikeLimit") fun findAllByNameLikeLimit( @Param("nameLike") nameLike: String, @Param("limit") limit: Int ): List<AudioEntity> class Sql { companion object { @JvmStatic fun findOneById(): String = SelectSQLBuilder(AudioEntity::class) .leftOuterJoin(AlbumEntity::class, "audio.album_id = album.id") .toSql() .WHERE("audio.id = #{id}") .toString() @JvmStatic fun findOneBySlug(): String = SelectSQLBuilder(AudioEntity::class) .leftOuterJoin(AlbumEntity::class, "audio.album_id = album.id") .toSql() .WHERE("audio.slug = #{slug}") .toString() @JvmStatic fun findAllByArtistIdIn(@Param("artistIds") artistIds: List<Long>): 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<Long>): String = SelectSQLBuilder(AudioEntity::class) .leftOuterJoin(AlbumEntity::class, "audio.album_id = album.id") .toSql() .WHERE_IN("audio.album_id", "albumIds", albumIds.size) .toString() @JvmStatic fun findAllByIdIn(@Param("ids") ids: List<Long>): String = SelectSQLBuilder(AudioEntity::class) .leftOuterJoin(AlbumEntity::class, "audio.album_id = album.id") .toSql() .WHERE_IN("audio.id", "ids", ids.size) .toString() @JvmStatic fun findAllBySlugIn(@Param("slugs") slugs: List<String>): String = SelectSQLBuilder(AudioEntity::class) .leftOuterJoin(AlbumEntity::class, "audio.album_id = album.id") .toSql() .WHERE_IN("audio.slug", "slugs", slugs.size) .toString() @JvmStatic fun findAllByNameLikeLimit( @Param("nameLike") nameLike: String, @Param("limit") limit: Long ): String = SelectSQLBuilder(AudioEntity::class) .leftOuterJoin(AlbumEntity::class, "audio.album_id = album.id") .toSql() .WHERE("audio.name LIKE CONCAT('%', #{nameLike}, '%')") .LIMIT("#{limit}") .toString() } } }
/* * Copyright (c) 2023. yo-saito. All Rights Reserved. */ 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.utils.SelectSQLBuilder import net.piedpiper.bremer.utils.WHERE_IN import org.apache.ibatis.annotations.* import org.springframework.stereotype.Repository @Repository("bremer.dao.AudioDao") @Mapper interface AudioDao { @ResultMap("net.piedpiper.bremer.AudioEntity") @SelectProvider(type = Sql::class, method = "findOneById") fun findOneById(@Param("id") id: Long): AudioEntity? @ResultMap("net.piedpiper.bremer.AudioEntity") @SelectProvider(type = Sql::class, method = "findOneBySlug") fun findOneBySlug(@Param("slug") slug: String): AudioEntity? @ResultMap("net.piedpiper.bremer.AudioEntity") @SelectProvider(type = Sql::class, method = "findAllByArtistIdIn") fun findAllByArtistIdIn(@Param("artistIds") artistIds: List<Long>): List<AudioEntity> @ResultMap("net.piedpiper.bremer.AudioEntity") @SelectProvider(type = Sql::class, method = "findAllByAlbumIdIn") fun findAllByAlbumIdIn(@Param("albumIds") albumIds: List<Long>): List<AudioEntity> @ResultMap("net.piedpiper.bremer.AudioEntity") @SelectProvider(type = Sql::class, method = "findAllByIdIn") fun findAllByIdIn(@Param("ids") ids: List<Long>): List<AudioEntity> @ResultMap("net.piedpiper.bremer.AudioEntity") @SelectProvider(type = Sql::class, method = "findAllBySlugIn") fun findAllBySlugIn(@Param("slugs") ids: List<String>): List<AudioEntity> @ResultMap("net.piedpiper.bremer.AudioEntity") @SelectProvider(type = Sql::class, method = "findAllByNameLikeLimit") fun findAllByNameLikeLimit( @Param("nameLike") nameLike: String, @Param("limit") limit: Int ): List<AudioEntity> class Sql { companion object { @JvmStatic fun findOneById(): String = SelectSQLBuilder(AudioEntity::class) .leftOuterJoin(AlbumEntity::class, "audio.album_id = album.id") .leftOuterJoin(ArtistEntity::class, "audio.artist_id = artist.id") .toSql() .WHERE("audio.id = #{id}") .toString() @JvmStatic fun findOneBySlug(): String = SelectSQLBuilder(AudioEntity::class) .leftOuterJoin(AlbumEntity::class, "audio.album_id = album.id") .leftOuterJoin(ArtistEntity::class, "audio.artist_id = artist.id") .toSql() .WHERE("audio.slug = #{slug}") .toString() @JvmStatic fun findAllByArtistIdIn(@Param("artistIds") artistIds: List<Long>): String = SelectSQLBuilder(AudioEntity::class) .leftOuterJoin(AlbumEntity::class, "audio.album_id = album.id") .leftOuterJoin(ArtistEntity::class, "audio.artist_id = artist.id") .toSql() .WHERE_IN("audio.artist_id", "artistIds", artistIds.size) .toString() @JvmStatic fun findAllByAlbumIdIn(@Param("albumIds") albumIds: List<Long>): String = SelectSQLBuilder(AudioEntity::class) .leftOuterJoin(AlbumEntity::class, "audio.album_id = album.id") .leftOuterJoin(ArtistEntity::class, "audio.artist_id = artist.id") .toSql() .WHERE_IN("audio.album_id", "albumIds", albumIds.size) .toString() @JvmStatic fun findAllByIdIn(@Param("ids") ids: List<Long>): String = SelectSQLBuilder(AudioEntity::class) .leftOuterJoin(AlbumEntity::class, "audio.album_id = album.id") .leftOuterJoin(ArtistEntity::class, "audio.artist_id = artist.id") .toSql() .WHERE_IN("audio.id", "ids", ids.size) .toString() @JvmStatic fun findAllBySlugIn(@Param("slugs") slugs: List<String>): String = SelectSQLBuilder(AudioEntity::class) .leftOuterJoin(AlbumEntity::class, "audio.album_id = album.id") .leftOuterJoin(ArtistEntity::class, "audio.artist_id = artist.id") .toSql() .WHERE_IN("audio.slug", "slugs", slugs.size) .toString() @JvmStatic fun findAllByNameLikeLimit( @Param("nameLike") nameLike: String, @Param("limit") limit: Long ): String = SelectSQLBuilder(AudioEntity::class) .leftOuterJoin(AlbumEntity::class, "audio.album_id = album.id") .leftOuterJoin(ArtistEntity::class, "audio.artist_id = artist.id") .toSql() .WHERE("audio.name LIKE CONCAT('%', #{nameLike}, '%')") .LIMIT("#{limit}") .toString() } } }
Ignore Space
Show notes
View
src/main/kotlin/entity/Audio.kt
/* * Copyright (c) 2023. yo-saito. All Rights Reserved. */ package net.piedpiper.bremer.entity import net.piedpiper.bremer.utils.sql.Column import net.piedpiper.bremer.utils.sql.Table import java.time.LocalDateTime @Table("audio") data class AudioEntity( @property:Column("id", insertable = false, updatable = false) var id: Long = 0L, @property:Column("slug") var slug: String = "", @property:Column("name") var name: String = "", @property:Column("album_id") var albumId: Long = 0L, @property:Column("path") var path: String = "", // join var album: AlbumEntity? = null ) @Table("album") data class AlbumEntity( @property:Column("id", insertable = false, updatable = false) var id: Long = 0L, @property:Column("artist_id") var artistId: Long = 0L, @property:Column("name") var name: String = "", // join var artist: ArtistEntity? = null ) @Table("artist") data class ArtistEntity( @property:Column("id", insertable = false, updatable = false) var id: Long = 0L, @property:Column("name") var name: String = "", ) @Table("audio_play_history") data class AudioPlayHistoryEntity( @property:Column("id", insertable = false, updatable = false) var id: Long = 0L, @property:Column("audio_id") var audioId: Long = 0L, @property:Column("last_played_at") var lastPlayedAt: LocalDateTime = LocalDateTime.MIN )
/* * Copyright (c) 2023. yo-saito. All Rights Reserved. */ package net.piedpiper.bremer.entity import net.piedpiper.bremer.utils.sql.Column import net.piedpiper.bremer.utils.sql.Table import java.time.LocalDateTime @Table("audio") data class AudioEntity( @property:Column("id", insertable = false, updatable = false) var id: Long = 0L, @property:Column("slug") var slug: String = "", @property:Column("name") var name: String = "", @property:Column("artist_id") var artistId: Long = 0L, @property:Column("album_id") var albumId: Long = 0L, @property:Column("path") var path: String = "", // join var artist: ArtistEntity? = null, var album: AlbumEntity? = null ) @Table("album") data class AlbumEntity( @property:Column("id", insertable = false, updatable = false) var id: Long = 0L, @property:Column("name") var name: String = "", ) @Table("artist") data class ArtistEntity( @property:Column("id", insertable = false, updatable = false) var id: Long = 0L, @property:Column("name") var name: String = "", ) @Table("audio_play_history") data class AudioPlayHistoryEntity( @property:Column("id", insertable = false, updatable = false) var id: Long = 0L, @property:Column("audio_id") var audioId: Long = 0L, @property:Column("last_played_at") var lastPlayedAt: LocalDateTime = LocalDateTime.MIN )
Ignore Space
Show notes
View
src/main/kotlin/model/api/Audio.kt
/* * Copyright (c) 2023. yo-saito. All Rights Reserved. */ package net.piedpiper.bremer.model.api import net.piedpiper.bremer.entity.AudioEntity data class AudioListResponse( private val entities: List<AudioEntity> ) { val audio: List<Audio> = entities.map { Audio(it) } data class Audio( private val entity: AudioEntity ) { val name: String = entity.name val slug: String = entity.slug val artist: String? = entity?.album?.artist?.name val album: String? = entity?.album?.name } }
/* * Copyright (c) 2023. yo-saito. All Rights Reserved. */ package net.piedpiper.bremer.model.api import net.piedpiper.bremer.entity.AudioEntity data class AudioListResponse( private val entities: List<AudioEntity> ) { val audio: List<Audio> = entities.map { Audio(it) } data class Audio( private val entity: AudioEntity ) { val name: String = entity.name val slug: String = entity.slug val artist: String? = entity?.artist?.name val album: String? = entity?.album?.name } }
Ignore Space
Show notes
View
src/main/kotlin/model/api/Playlist.kt
/* * Copyright (c) 2023. yo-saito. All Rights Reserved. */ package net.piedpiper.bremer.model import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.annotation.JsonProperty import jakarta.validation.constraints.NotBlank import jakarta.validation.constraints.NotEmpty import net.piedpiper.bremer.entity.AudioEntity import net.piedpiper.bremer.entity.PlaylistEntity data class PlaylistListResponse( private val entities: List<PlaylistEntity> ) { val playlist: List<Playlist> = entities.map { Playlist(it.name, it.slug) } data class Playlist( val name: String, val slug: String ) } data class PlaylistRequest( @field:NotBlank val name: String = "", @field:NotEmpty @field:JsonProperty("audio_slugs") val audioSlugs: List<String> = mutableListOf() ) class PlaylistAudioResponse( private val playlistEntity: PlaylistEntity, private val audioEntityList: List<AudioEntity> ) { val name: String = playlistEntity.name val slug: String = playlistEntity.slug @field:JsonProperty("audio_list") val audioList: List<Audio> = audioEntityList.map { Audio(it) } @JsonInclude(JsonInclude.Include.NON_NULL) class Audio(private val entity: AudioEntity) { val name: String = entity.name val slug: String = entity.slug val artist: String? = entity.album?.artist?.name val album: String? = entity.album?.name } }
/* * Copyright (c) 2023. yo-saito. All Rights Reserved. */ package net.piedpiper.bremer.model import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.annotation.JsonProperty import jakarta.validation.constraints.NotBlank import jakarta.validation.constraints.NotEmpty import net.piedpiper.bremer.entity.AudioEntity import net.piedpiper.bremer.entity.PlaylistEntity data class PlaylistListResponse( private val entities: List<PlaylistEntity> ) { val playlist: List<Playlist> = entities.map { Playlist(it.name, it.slug) } data class Playlist( val name: String, val slug: String ) } data class PlaylistRequest( @field:NotBlank val name: String = "", @field:NotEmpty @field:JsonProperty("audio_slugs") val audioSlugs: List<String> = mutableListOf() ) class PlaylistAudioResponse( private val playlistEntity: PlaylistEntity, private val audioEntityList: List<AudioEntity> ) { val name: String = playlistEntity.name val slug: String = playlistEntity.slug @field:JsonProperty("audio_list") val audioList: List<Audio> = audioEntityList.map { Audio(it) } @JsonInclude(JsonInclude.Include.NON_NULL) class Audio(private val entity: AudioEntity) { val name: String = entity.name val slug: String = entity.slug val artist: String? = entity.artist?.name val album: String? = entity.album?.name } }
Ignore Space
Show notes
View
src/main/resources/mapper/mapper.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="net.piedpiper.bremer"> <resultMap id="AudioEntity" type="net.piedpiper.bremer.entity.AudioEntity"> <id property="id" column="id"/> <result property="name" column="name"/> <result property="slug" column="slug"/> <result property="articleId" column="article_id"/> <result property="albumId" column="album_id"/> <result property="path" column="path"/> <association property="album" columnPrefix="album__" resultMap="AlbumEntity"/> </resultMap> <resultMap id="ArtistEntity" type="net.piedpiper.bremer.entity.ArtistEntity"> <id property="id" column="id"/> <result property="name" column="name"/> <association property="artist" columnPrefix="artist__" resultMap="ArtistEntity"/> </resultMap> <resultMap id="AlbumEntity" type="net.piedpiper.bremer.entity.AlbumEntity"> <id property="id" column="id"/> <result property="name" column="name"/> </resultMap> <resultMap id="AudioPlayHistoryEntity" type="net.piedpiper.bremer.entity.AudioPlayHistoryEntity"> <id property="id" column="id"/> <result property="audioId" column="audio_id"/> <result property="lastPlayedAt" column="last_played_at" typeHandler="net.piedpiper.bremer.dao.handler.LocalDateTimeTypeHandler"/> </resultMap> <resultMap id="PlaylistEntity" type="net.piedpiper.bremer.entity.PlaylistEntity"> <id property="id" column="id"/> <result property="albumId" column="album_id"/> <result property="slug" column="slug"/> <result property="name" column="name"/> <collection property="playlistAudio" columnPrefix="playlist_audio__" resultMap="PlaylistAudioEntity"/> </resultMap> <resultMap id="PlaylistAudioEntity" type="net.piedpiper.bremer.entity.PlaylistAudioEntity"> <id property="id" column="id"/> <result property="playlistId" column="playlist_id"/> <result property="sequence" column="sequence"/> <result property="audioId" column="audio_id"/> </resultMap> <resultMap id="UserEntity" type="net.piedpiper.bremer.entity.UserEntity"> <id property="id" column="id"/> <result property="name" column="name"/> <result property="secret" column="secret"/> </resultMap> </mapper>
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="net.piedpiper.bremer"> <resultMap id="AudioEntity" type="net.piedpiper.bremer.entity.AudioEntity"> <id property="id" column="id"/> <result property="name" column="name"/> <result property="slug" column="slug"/> <result property="articleId" column="article_id"/> <result property="albumId" column="album_id"/> <result property="path" column="path"/> <association property="album" columnPrefix="album__" resultMap="AlbumEntity"/> <association property="artist" columnPrefix="artist__" resultMap="ArtistEntity"/> </resultMap> <resultMap id="ArtistEntity" type="net.piedpiper.bremer.entity.ArtistEntity"> <id property="id" column="id"/> <result property="name" column="name"/> </resultMap> <resultMap id="AlbumEntity" type="net.piedpiper.bremer.entity.AlbumEntity"> <id property="id" column="id"/> <result property="name" column="name"/> </resultMap> <resultMap id="AudioPlayHistoryEntity" type="net.piedpiper.bremer.entity.AudioPlayHistoryEntity"> <id property="id" column="id"/> <result property="audioId" column="audio_id"/> <result property="lastPlayedAt" column="last_played_at" typeHandler="net.piedpiper.bremer.dao.handler.LocalDateTimeTypeHandler"/> </resultMap> <resultMap id="PlaylistEntity" type="net.piedpiper.bremer.entity.PlaylistEntity"> <id property="id" column="id"/> <result property="albumId" column="album_id"/> <result property="slug" column="slug"/> <result property="name" column="name"/> <collection property="playlistAudio" columnPrefix="playlist_audio__" resultMap="PlaylistAudioEntity"/> </resultMap> <resultMap id="PlaylistAudioEntity" type="net.piedpiper.bremer.entity.PlaylistAudioEntity"> <id property="id" column="id"/> <result property="playlistId" column="playlist_id"/> <result property="sequence" column="sequence"/> <result property="audioId" column="audio_id"/> </resultMap> <resultMap id="UserEntity" type="net.piedpiper.bremer.entity.UserEntity"> <id property="id" column="id"/> <result property="name" column="name"/> <result property="secret" column="secret"/> </resultMap> </mapper>
Show line notes below