diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/dto/RemoteUserCreateDto.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/dto/RemoteUserCreateDto.kt new file mode 100644 index 00000000..35081932 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/dto/RemoteUserCreateDto.kt @@ -0,0 +1,12 @@ +package dev.usbharu.hideout.domain.model.hideout.dto + +data class RemoteUserCreateDto( + val name:String, + val domain:String, + val screenName:String, + val description:String, + val inbox:String, + val outbox:String, + val url:String, + val publicKey:String, +) diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubUserServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubUserServiceImpl.kt index 014f3ffa..318cff08 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubUserServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubUserServiceImpl.kt @@ -2,10 +2,10 @@ package dev.usbharu.hideout.service.activitypub import com.fasterxml.jackson.module.kotlin.readValue import dev.usbharu.hideout.config.Config -import dev.usbharu.hideout.domain.model.hideout.entity.User import dev.usbharu.hideout.domain.model.ap.Image import dev.usbharu.hideout.domain.model.ap.Key import dev.usbharu.hideout.domain.model.ap.Person +import dev.usbharu.hideout.domain.model.hideout.dto.RemoteUserCreateDto import dev.usbharu.hideout.exception.UserNotFoundException import dev.usbharu.hideout.exception.ap.IllegalActivityPubObjectException import dev.usbharu.hideout.service.impl.UserService @@ -15,7 +15,6 @@ import io.ktor.client.request.* import io.ktor.client.statement.* import io.ktor.http.* import org.slf4j.LoggerFactory -import java.time.Instant class ActivityPubUserServiceImpl( private val userService: UserService, @@ -85,9 +84,9 @@ class ActivityPubUserServiceImpl( accept(ContentType.Application.Activity) } val person = Config.configData.objectMapper.readValue(httpResponse.bodyAsText()) - userService.create( - User( - id = 0L, + + userService.createRemoteUser( + RemoteUserCreateDto( name = person.preferredUsername ?: throw IllegalActivityPubObjectException("preferredUsername is null"), domain = url.substringAfter(":").substringBeforeLast("/"), @@ -97,7 +96,6 @@ class ActivityPubUserServiceImpl( outbox = person.outbox ?: throw IllegalActivityPubObjectException("outbox is null"), url = url, publicKey = person.publicKey?.publicKeyPem ?: throw IllegalActivityPubObjectException("publicKey is null"), - createdAt = Instant.now() ) ) person diff --git a/src/main/kotlin/dev/usbharu/hideout/service/impl/UserService.kt b/src/main/kotlin/dev/usbharu/hideout/service/impl/UserService.kt index c67d8ecf..8e0f0f06 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/impl/UserService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/impl/UserService.kt @@ -1,6 +1,7 @@ package dev.usbharu.hideout.service.impl import dev.usbharu.hideout.config.Config +import dev.usbharu.hideout.domain.model.hideout.dto.RemoteUserCreateDto import dev.usbharu.hideout.domain.model.hideout.dto.UserCreateDto import dev.usbharu.hideout.domain.model.hideout.entity.User import dev.usbharu.hideout.exception.UserNotFoundException @@ -54,11 +55,6 @@ class UserService(private val userRepository: IUserRepository, private val userA return findByNameAndDomain != null } - @Deprecated("") - suspend fun create(user: User): User { - return userRepository.save(user) - } - suspend fun createLocalUser(user: UserCreateDto): User { val nextId = userRepository.nextId() val HashedPassword = userAuthService.hash(user.password) @@ -80,6 +76,23 @@ class UserService(private val userRepository: IUserRepository, private val userA return userRepository.save(userEntity) } + suspend fun createRemoteUser(user: RemoteUserCreateDto): User { + val nextId = userRepository.nextId() + val userEntity = User( + id = nextId, + name = user.name, + domain = user.domain, + screenName = user.screenName, + description = user.description, + inbox = user.inbox, + outbox = user.outbox, + url = user.url, + publicKey = user.publicKey, + createdAt = Instant.now() + ) + return userRepository.save(userEntity) + } + suspend fun findFollowersById(id: Long): List { return userRepository.findFollowersById(id) }