mirror of https://github.com/usbharu/Hideout.git
feat: リモートユーザーの作成を追加
This commit is contained in:
parent
6d2999452a
commit
943b09a3a5
|
@ -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,
|
||||
)
|
|
@ -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<Person>(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
|
||||
|
|
|
@ -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<User> {
|
||||
return userRepository.findFollowersById(id)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue