Newer
Older
bremer / src / main / kotlin / dao / AudioPlayHistoryDao.kt
yhornisse on 2 Jul 2023 1 KB add project
/*
 * Copyright (c) 2023. yo-saito. All Rights Reserved.
 */

package net.piedpiper.bremer.dao

import net.piedpiper.bremer.entity.AudioPlayHistoryEntity
import org.apache.ibatis.annotations.*
import org.springframework.stereotype.Repository

@Repository("bremer.dao.AudioPlayHistoryDao")
@Mapper
interface AudioPlayHistoryDao {

    @ResultMap("net.piedpiper.bremer.AudioPlayHistoryEntity")
    @Select("SELECT * FROM audio_play_history ORDER BY last_played_at DESC LIMIT #{limit}")
    fun findAllOrderLastPlayedAtDescLimit(@Param("limit") limit: Int): List<AudioPlayHistoryEntity>

    @Insert(
        """
    INSERT INTO audio_play_history (audio_id,last_played_at) VALUES (#{entity.audioId},
    #{entity.lastPlayedAt, typeHandler=net.piedpiper.bremer.dao.handler.LocalDateTimeTypeHandler})
    ON DUPLICATE KEY UPDATE last_played_at = VALUES (last_played_at);
    """
    )
    @Options(useGeneratedKeys = true, keyProperty = "id")
    fun insertOrUpdateOne(@Param("entity") entity: AudioPlayHistoryEntity): Boolean
}