Skip to content

Commit

Permalink
SettingService: changing accessing repository's way
Browse files Browse the repository at this point in the history
  • Loading branch information
sheip9 committed Jan 28, 2025
1 parent 3fafd8d commit 73974b9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
package tax.bilibili.nineblog.application.repository

import org.springframework.data.r2dbc.repository.Modifying
import org.springframework.data.r2dbc.repository.Query
import org.springframework.data.r2dbc.repository.R2dbcRepository
import org.springframework.stereotype.Repository
import reactor.core.publisher.Mono
import tax.bilibili.nineblog.application.constant.IdType
import tax.bilibili.nineblog.application.constant.SettingKey
import tax.bilibili.nineblog.application.entity.Setting

@Repository
interface SettingRepository : R2dbcRepository<Setting, IdType> {
@Modifying
@Query(
"INSERT INTO setting (`name`, `value`)" +
"VALUES" +
"(:name, :value)" +
"ON DUPLICATE KEY UPDATE `value` = :value;"
)
fun updateByKey(name: SettingKey, value: String): Mono<Boolean>
}
interface SettingRepository : R2dbcRepository<Setting, IdType>
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ class SettingService : AbstractService<SettingRepository, Setting, Number>() {
)
}

fun updateOneSetting(key: SettingKey, value: String): Mono<Boolean> = repository.updateByKey(key, value)
fun updateOneSetting(key: SettingKey, value: String): Mono<Setting?> = repository.save(Setting(key, value))
}

0 comments on commit 73974b9

Please sign in to comment.