Skip to content

Commit

Permalink
refactor: move initAlbumForUser from service to dao
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiinaKin committed Sep 24, 2024
1 parent 92e028b commit 2928733
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ interface AlbumDao {
fun listAlbumByUserId(userId: Long): List<Album>
fun getAlbumById(albumId: Long): Album?
fun saveAlbum(insertDTO: AlbumInsertDTO): Long
fun initAlbumForUser(userId: Long): Long
}
16 changes: 16 additions & 0 deletions app/src/main/kotlin/io/sakurasou/model/dao/album/AlbumDaoImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package io.sakurasou.model.dao.album

import io.sakurasou.model.dto.AlbumInsertDTO
import io.sakurasou.model.entity.Album
import kotlinx.datetime.Clock
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime
import org.jetbrains.exposed.sql.insertAndGetId
import org.jetbrains.exposed.sql.selectAll

Expand Down Expand Up @@ -54,4 +57,17 @@ class AlbumDaoImpl : AlbumDao {
}
return entityID.value
}

override fun initAlbumForUser(userId: Long): Long {
val now = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault())
val uncategorizedAlbum = AlbumInsertDTO(
userId = userId,
name = "uncategorized",
description = "default, cannot delete",
imageCount = 0,
isUncategorized = true,
createTime = now
)
return saveAlbum(uncategorizedAlbum)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ package io.sakurasou.service.album
* 2024/9/13 14:48
*/
interface AlbumService {
suspend fun initAlbumForUser(userId: Long): Long
suspend fun saveAlbum(): Long
}
20 changes: 0 additions & 20 deletions app/src/main/kotlin/io/sakurasou/service/album/AlbumServiceImpl.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package io.sakurasou.service.album

import io.sakurasou.model.DatabaseSingleton.dbQuery
import io.sakurasou.model.dao.album.AlbumDao
import io.sakurasou.model.dto.AlbumInsertDTO
import kotlinx.datetime.Clock
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime

/**
* @author Shiina Kin
Expand All @@ -14,21 +9,6 @@ import kotlinx.datetime.toLocalDateTime
class AlbumServiceImpl(
private val albumDao: AlbumDao
) : AlbumService {
override suspend fun initAlbumForUser(userId: Long): Long {
val now = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault())
val uncategorizedAlbum = AlbumInsertDTO(
userId = userId,
name = "uncategorized",
description = "default, cannot delete",
imageCount = 0,
isUncategorized = true,
createTime = now
)
return dbQuery {
albumDao.saveAlbum(uncategorizedAlbum)
}
}

override suspend fun saveAlbum(): Long {
TODO("Not yet implemented")
}
Expand Down

0 comments on commit 2928733

Please sign in to comment.