From 943b09a3a59cdbae361d2ab14ce3782161e21f6f Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Fri, 28 Apr 2023 15:41:31 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=83=AA=E3=83=A2=E3=83=BC=E3=83=88?= =?UTF-8?q?=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BC=E3=81=AE=E4=BD=9C=E6=88=90?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/hideout/dto/RemoteUserCreateDto.kt | 12 ++++++++++ .../activitypub/ActivityPubUserServiceImpl.kt | 10 ++++---- .../hideout/service/impl/UserService.kt | 23 +++++++++++++++---- 3 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/dto/RemoteUserCreateDto.kt 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) }