mirror of https://github.com/usbharu/Hideout.git
feat: InstanceServiceを追加
This commit is contained in:
parent
22d6ba40ed
commit
1db8f31b5f
|
@ -8,7 +8,7 @@ data class Instance(
|
||||||
val description: String,
|
val description: String,
|
||||||
val url: String,
|
val url: String,
|
||||||
val iconUrl: String,
|
val iconUrl: String,
|
||||||
val sharedInbox: String,
|
val sharedInbox: String?,
|
||||||
val software: String,
|
val software: String,
|
||||||
val version: String,
|
val version: String,
|
||||||
val isBlocked: Boolean,
|
val isBlocked: Boolean,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package dev.usbharu.hideout.core.domain.model.instance
|
package dev.usbharu.hideout.core.domain.model.instance
|
||||||
|
|
||||||
interface InstanceRepository {
|
interface InstanceRepository {
|
||||||
|
suspend fun generateId(): Long
|
||||||
suspend fun save(instance: Instance): Instance
|
suspend fun save(instance: Instance): Instance
|
||||||
suspend fun findById(id: Long): Instance
|
suspend fun findById(id: Long): Instance
|
||||||
suspend fun delete(instance: Instance)
|
suspend fun delete(instance: Instance)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package dev.usbharu.hideout.core.infrastructure.exposedrepository
|
package dev.usbharu.hideout.core.infrastructure.exposedrepository
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.application.service.id.IdGenerateService
|
||||||
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
||||||
import dev.usbharu.hideout.core.domain.model.instance.InstanceRepository
|
import dev.usbharu.hideout.core.domain.model.instance.InstanceRepository
|
||||||
import dev.usbharu.hideout.util.singleOr
|
import dev.usbharu.hideout.util.singleOr
|
||||||
|
@ -10,7 +11,9 @@ import org.springframework.stereotype.Repository
|
||||||
import dev.usbharu.hideout.core.domain.model.instance.Instance as InstanceEntity
|
import dev.usbharu.hideout.core.domain.model.instance.Instance as InstanceEntity
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
class InstanceRepositoryImpl : InstanceRepository {
|
class InstanceRepositoryImpl(private val idGenerateService: IdGenerateService) : InstanceRepository {
|
||||||
|
override suspend fun generateId(): Long = idGenerateService.generateId()
|
||||||
|
|
||||||
override suspend fun save(instance: InstanceEntity): InstanceEntity {
|
override suspend fun save(instance: InstanceEntity): InstanceEntity {
|
||||||
if (Instance.select { Instance.id.eq(instance.id) }.firstOrNull() == null) {
|
if (Instance.select { Instance.id.eq(instance.id) }.firstOrNull() == null) {
|
||||||
Instance.insert {
|
Instance.insert {
|
||||||
|
@ -78,7 +81,7 @@ object Instance : Table("instance") {
|
||||||
val description = varchar("description", 5000)
|
val description = varchar("description", 5000)
|
||||||
val url = varchar("url", 255)
|
val url = varchar("url", 255)
|
||||||
val iconUrl = varchar("icon_url", 255)
|
val iconUrl = varchar("icon_url", 255)
|
||||||
val sharedInbox = varchar("shared_inbox", 255)
|
val sharedInbox = varchar("shared_inbox", 255).nullable()
|
||||||
val software = varchar("software", 255)
|
val software = varchar("software", 255)
|
||||||
val version = varchar("version", 255)
|
val version = varchar("version", 255)
|
||||||
val isBlocked = bool("is_blocked")
|
val isBlocked = bool("is_blocked")
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package dev.usbharu.hideout.core.service.instance
|
||||||
|
|
||||||
|
data class InstanceCreateDto(
|
||||||
|
val name: String?,
|
||||||
|
val description: String?,
|
||||||
|
val url: String,
|
||||||
|
val iconUrl: String,
|
||||||
|
val sharedInbox: String?,
|
||||||
|
val software: String?,
|
||||||
|
val version: String?,
|
||||||
|
)
|
|
@ -0,0 +1,33 @@
|
||||||
|
package dev.usbharu.hideout.core.service.instance
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.core.domain.model.instance.Instance
|
||||||
|
import dev.usbharu.hideout.core.domain.model.instance.InstanceRepository
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
import java.time.Instant
|
||||||
|
|
||||||
|
interface InstanceService {
|
||||||
|
suspend fun createNewInstance(instanceCreateDto: InstanceCreateDto): Instance
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Service
|
||||||
|
class InstanceServiceImpl(private val instanceRepository: InstanceRepository) : InstanceService {
|
||||||
|
override suspend fun createNewInstance(instanceCreateDto: InstanceCreateDto): Instance {
|
||||||
|
val instance = Instance(
|
||||||
|
instanceRepository.generateId(),
|
||||||
|
instanceCreateDto.name ?: instanceCreateDto.url,
|
||||||
|
instanceCreateDto.description ?: "",
|
||||||
|
instanceCreateDto.url,
|
||||||
|
instanceCreateDto.iconUrl,
|
||||||
|
instanceCreateDto.sharedInbox,
|
||||||
|
instanceCreateDto.software ?: "unknown",
|
||||||
|
instanceCreateDto.version ?: "unknown",
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
"",
|
||||||
|
Instant.now()
|
||||||
|
)
|
||||||
|
instanceRepository.save(instance)
|
||||||
|
return instance
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue