feat: 未実装箇所を実装

This commit is contained in:
usbharu 2024-02-12 12:36:04 +09:00
parent 5cb014730e
commit 41d1e59322
2 changed files with 38 additions and 2 deletions

View File

@ -46,6 +46,11 @@ class ExposedFilterRepository(private val idGenerateService: IdGenerateService)
return@query Filters.selectAll().where { Filters.id eq id }.singleOrNull()?.toFilter()
}
override suspend fun findByUserIdAndId(userId: Long, id: Long): Filter? = query {
return@query Filters.selectAll().where { Filters.userId eq userId and (Filters.id eq id) }.singleOrNull()
?.toFilter()
}
override suspend fun findByUserIdAndType(userId: Long, types: List<FilterType>): List<Filter> = query {
return@query Filters.selectAll().where { Filters.userId eq userId }.map { it.toFilter() }
.filter { it.context.containsAll(types) }
@ -55,6 +60,10 @@ class ExposedFilterRepository(private val idGenerateService: IdGenerateService)
Filters.deleteWhere { Filters.id eq id }
}
override suspend fun deleteByUserIdAndId(userId: Long, id: Long) {
Filters.deleteWhere { Filters.userId eq userId and (Filters.id eq id) }
}
companion object {
private val logger = LoggerFactory.getLogger(ExposedFilterRepository::class.java)
}
@ -76,4 +85,4 @@ object Filters : Table() {
val filterAction = varchar("action", 255)
override val primaryKey: PrimaryKey = PrimaryKey(id)
}
}

View File

@ -6,6 +6,7 @@ import dev.usbharu.hideout.core.infrastructure.exposedrepository.Filters
import dev.usbharu.hideout.core.infrastructure.exposedrepository.toFilter
import dev.usbharu.hideout.core.infrastructure.exposedrepository.toFilterKeyword
import org.jetbrains.exposed.sql.Query
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.selectAll
import org.springframework.stereotype.Repository
@ -19,6 +20,32 @@ class ExposedFilterQueryService : FilterQueryService {
.toFilterQueryModel()
}
override suspend fun findByUserId(userId: Long): List<FilterQueryModel> {
return Filters
.rightJoin(FilterKeywords)
.selectAll()
.where { Filters.userId eq userId }
.toFilterQueryModel()
}
override suspend fun findByUserIdAndId(userId: Long, id: Long): FilterQueryModel? {
return Filters
.leftJoin(FilterKeywords)
.selectAll()
.where { Filters.userId eq userId and (Filters.id eq id) }
.toFilterQueryModel()
.firstOrNull()
}
override suspend fun findByUserIdAndKeywordId(userId: Long, keywordId: Long): FilterQueryModel? {
return Filters
.leftJoin(FilterKeywords)
.selectAll()
.where { Filters.userId eq userId and (FilterKeywords.id eq keywordId) }
.toFilterQueryModel()
.firstOrNull()
}
private fun Query.toFilterQueryModel(): List<FilterQueryModel> {
return this
.groupBy { it[Filters.id] }
@ -30,4 +57,4 @@ class ExposedFilterQueryService : FilterQueryService {
)
}
}
}
}