From 99c27e45c240fb843b88f59dc6eed9554c51c8b3 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Mon, 27 May 2024 21:59:06 +0900 Subject: [PATCH] wip --- .../core/domain/event/actor/ActorEvent.kt | 41 ++++ .../ActorInstanceRelationshipEvent.kt | 47 ++++ .../domain/event/instance/InstanceEvent.kt | 36 +++ .../core/domain/event/post/PostEvent.kt | 39 +++ .../hideout/core/domain/model/actor/Actor2.kt | 121 +++++++++ .../domain/model/actor/Actor2Repository.kt | 23 ++ .../domain/model/actor/ActorDescription.kt | 27 +++ .../core/domain/model/actor/ActorId.kt | 24 ++ .../core/domain/model/actor/ActorKeyId.kt | 20 ++ .../core/domain/model/actor/ActorName.kt | 20 ++ .../domain/model/actor/ActorPostsCount.kt | 27 +++ .../domain/model/actor/ActorPrivateKey.kt | 20 ++ .../core/domain/model/actor/ActorPublicKey.kt | 20 ++ .../model/actor/ActorRelationshipCount.kt | 27 +++ .../domain/model/actor/ActorScreenName.kt | 28 +++ .../ActorInstanceRelationship.kt | 88 +++++++ .../domain/model/deletedActor/DeletedActor.kt | 14 +- .../model/deletedActor/DeletedActorId.kt | 20 ++ .../model/emoji/CustomEmojiRepository.kt | 1 + .../core/domain/model/emoji/EmojiId.kt | 20 ++ .../core/domain/model/instance/Instance.kt | 55 +++-- .../model/instance/InstanceDescription.kt | 20 ++ .../core/domain/model/instance/InstanceId.kt | 20 ++ .../model/instance/InstanceModerationNote.kt | 20 ++ .../domain/model/instance/InstanceName.kt | 20 ++ .../model/instance/InstanceRepository.kt | 8 +- .../domain/model/instance/InstanceSoftware.kt | 20 ++ .../domain/model/instance/InstanceVersion.kt | 20 ++ .../core/domain/model/media/MediaId.kt | 20 ++ .../hideout/core/domain/model/post/Post2.kt | 229 ++++++++++++++++++ .../core/domain/model/post/Post2Repository.kt | 23 ++ .../core/domain/model/post/PostContent.kt | 34 +++ .../hideout/core/domain/model/post/PostId.kt | 20 ++ .../core/domain/model/post/PostOverview.kt | 20 ++ .../core/domain/model/shared/Domain.kt | 20 ++ .../model/shared/domainevent/DomainEvent.kt | 37 +++ .../shared/domainevent/DomainEventBody.kt | 23 ++ .../shared/domainevent/DomainEventStorable.kt | 29 +++ .../domain/model/userdetails/UserDetail.kt | 35 ++- .../userdetails/UserDetailHashedPassword.kt | 20 ++ .../actor/RemoteActorCheckDomainService.kt | 30 +++ .../actor/local/LocalActorDomainService.kt | 25 ++ .../ActorInstanceRelationshipDomainService.kt | 21 ++ .../service/userdetail/PasswordEncoder.kt | 21 ++ .../userdetail/UserDetailDomainService.kt | 25 ++ .../DeletedActorRepositoryImpl.kt | 6 +- .../factory/Actor2FactoryImpl.kt | 66 +++++ .../factory/ActorDescriptionFactoryImpl.kt | 41 ++++ .../factory/ActorScreenNameFactoryImpl.kt | 45 ++++ .../factory/PostContentFactoryImpl.kt | 35 +++ .../infrastructure/factory/PostFactoryImpl.kt | 67 +++++ .../core/service/user/UserServiceImpl.kt | 6 +- .../DeleteLocalActorApplicationService.kt | 25 ++ .../MigrationLocalActorApplicationService.kt | 25 ++ .../core/usecase/actor/RegisterLocalActor.kt | 22 ++ .../RegisterLocalActorApplicationService.kt | 65 +++++ .../SuspendLocalActorApplicationService.kt | 28 +++ .../UnsuspendLocalActorApplicationService.kt | 23 ++ .../post/DeleteLocalPostApplicationService.kt | 30 +++ .../core/usecase/post/RegisterLocalPost.kt | 30 +++ .../RegisterLocalPostApplicationService.kt | 51 ++++ .../core/usecase/post/UpdateLocalNote.kt | 25 ++ .../post/UpdateLocalNoteApplicationService.kt | 45 ++++ 63 files changed, 2080 insertions(+), 33 deletions(-) create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/actor/ActorEvent.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/actorinstancerelationship/ActorInstanceRelationshipEvent.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/instance/InstanceEvent.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/post/PostEvent.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor2.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor2Repository.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorDescription.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorId.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorKeyId.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorName.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPostsCount.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPrivateKey.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPublicKey.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorRelationshipCount.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorScreenName.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actorinstancerelationship/ActorInstanceRelationship.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/deletedActor/DeletedActorId.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/emoji/EmojiId.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceDescription.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceId.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceModerationNote.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceName.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceSoftware.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceVersion.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/MediaId.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post2.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post2Repository.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContent.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostId.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostOverview.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/Domain.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/domainevent/DomainEvent.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/domainevent/DomainEventBody.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/domainevent/DomainEventStorable.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/userdetails/UserDetailHashedPassword.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/actor/RemoteActorCheckDomainService.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/actor/local/LocalActorDomainService.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/actorinstancerelationship/ActorInstanceRelationshipDomainService.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/userdetail/PasswordEncoder.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/userdetail/UserDetailDomainService.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/Actor2FactoryImpl.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/ActorDescriptionFactoryImpl.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/ActorScreenNameFactoryImpl.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostContentFactoryImpl.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostFactoryImpl.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/DeleteLocalActorApplicationService.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/MigrationLocalActorApplicationService.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/RegisterLocalActor.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/RegisterLocalActorApplicationService.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/SuspendLocalActorApplicationService.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/UnsuspendLocalActorApplicationService.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/DeleteLocalPostApplicationService.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/RegisterLocalPost.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/RegisterLocalPostApplicationService.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/UpdateLocalNote.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/UpdateLocalNoteApplicationService.kt diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/actor/ActorEvent.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/actor/ActorEvent.kt new file mode 100644 index 00000000..62e0d9e9 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/actor/ActorEvent.kt @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.event.actor + +import dev.usbharu.hideout.core.domain.model.actor.Actor2 +import dev.usbharu.hideout.core.domain.model.shared.domainevent.DomainEvent +import dev.usbharu.hideout.core.domain.model.shared.domainevent.DomainEventBody + +class ActorDomainEventFactory(private val actor: Actor2) { + fun createEvent(actorEvent: ActorEvent): DomainEvent { + return DomainEvent.create( + actorEvent.eventName, + ActorEventBody(actor) + ) + } +} + +class ActorEventBody(actor: Actor2) : DomainEventBody( + mapOf( + "actor" to actor + ) +) + +enum class ActorEvent(val eventName: String) { + update("ActorUpdate"), + delete("ActorDelete"), +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/actorinstancerelationship/ActorInstanceRelationshipEvent.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/actorinstancerelationship/ActorInstanceRelationshipEvent.kt new file mode 100644 index 00000000..708c2f4d --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/actorinstancerelationship/ActorInstanceRelationshipEvent.kt @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.event.actorinstancerelationship + +import dev.usbharu.hideout.core.domain.model.actorinstancerelationship.ActorInstanceRelationship +import dev.usbharu.hideout.core.domain.model.shared.domainevent.DomainEvent +import dev.usbharu.hideout.core.domain.model.shared.domainevent.DomainEventBody + +class ActorInstanceRelationshipDomainEventFactory(private val actorInstanceRelationship: ActorInstanceRelationship) { + fun createEvent(actorInstanceRelationshipEvent: ActorInstanceRelationshipEvent): DomainEvent { + return DomainEvent.create( + actorInstanceRelationshipEvent.eventName, + ActorInstanceRelationshipEventBody(actorInstanceRelationship) + ) + } +} + +class ActorInstanceRelationshipEventBody(actorInstanceRelationship: ActorInstanceRelationship) : + DomainEventBody( + mapOf( + "actorId" to actorInstanceRelationship.actorId, + "instanceId" to actorInstanceRelationship.instanceId, + "muting" to actorInstanceRelationship.isMuting(), + "blocking" to actorInstanceRelationship.isBlocking(), + "doNotSendPrivate" to actorInstanceRelationship.isDoNotSendPrivate(), + ) + ) + +enum class ActorInstanceRelationshipEvent(val eventName: String) { + block("ActorInstanceBlock"), + mute("ActorInstanceMute"), + unmute("ActorInstanceUnmute"), +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/instance/InstanceEvent.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/instance/InstanceEvent.kt new file mode 100644 index 00000000..101c1cba --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/instance/InstanceEvent.kt @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.event.instance + +import dev.usbharu.hideout.core.domain.model.instance.Instance +import dev.usbharu.hideout.core.domain.model.shared.domainevent.DomainEvent +import dev.usbharu.hideout.core.domain.model.shared.domainevent.DomainEventBody + +class InstanceEventFactory(private val instance: Instance) { + fun createEvent(event: InstanceEvent): DomainEvent { + return DomainEvent.create( + event.eventName, + InstanceEventBody(instance) + ) + } +} + +class InstanceEventBody(instance: Instance) : DomainEventBody(mapOf("instance" to instance)) + +enum class InstanceEvent(val eventName: String) { + update("InstanceUpdate") +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/post/PostEvent.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/post/PostEvent.kt new file mode 100644 index 00000000..e5c0812f --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/post/PostEvent.kt @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.event.post + +import dev.usbharu.hideout.core.domain.model.post.Post2 +import dev.usbharu.hideout.core.domain.model.shared.domainevent.DomainEvent +import dev.usbharu.hideout.core.domain.model.shared.domainevent.DomainEventBody + +class PostDomainEventFactory(private val post: Post2) { + fun createEvent(postEvent: PostEvent): DomainEvent { + return DomainEvent.create( + postEvent.eventName, + PostEventBody(post) + ) + } +} + +class PostEventBody(post: Post2) : DomainEventBody(mapOf("post" to post)) + +enum class PostEvent(val eventName: String) { + delete("PostDelete"), + update("PostUpdate"), + create("PostCreate"), + checkUpdate("PostCheckUpdate"), +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor2.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor2.kt new file mode 100644 index 00000000..cc4f96ae --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor2.kt @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.actor + +import dev.usbharu.hideout.core.domain.event.actor.ActorDomainEventFactory +import dev.usbharu.hideout.core.domain.event.actor.ActorEvent.delete +import dev.usbharu.hideout.core.domain.event.actor.ActorEvent.update +import dev.usbharu.hideout.core.domain.model.instance.InstanceId +import dev.usbharu.hideout.core.domain.model.shared.Domain +import dev.usbharu.hideout.core.domain.model.shared.domainevent.DomainEventStorable +import java.net.URI +import java.time.Instant + +class Actor2 private constructor( + val id: ActorId, + val name: ActorName, + val domain: Domain, + screenName: ActorScreenName, + description: ActorDescription, + val inbox: URI, + val outbox: URI, + val url: URI, + val publicKey: ActorPublicKey, + val privateKey: ActorPrivateKey? = null, + val createdAt: Instant, + val keyId: ActorKeyId, + val followersEndpoint: URI, + val followingEndpoint: URI, + val instance: InstanceId, + var locked: Boolean, + var followersCount: ActorRelationshipCount?, + var followingCount: ActorRelationshipCount?, + var postsCount: ActorPostsCount, + var lastPostDate: Instant? = null, + var suspend: Boolean, +) : DomainEventStorable() { + + val emojis + get() = screenName.emojis + + + var description = description + set(value) { + addDomainEvent(ActorDomainEventFactory(this).createEvent(update)) + field = value + } + var screenName = screenName + set(value) { + addDomainEvent(ActorDomainEventFactory(this).createEvent(update)) + field = value + } + + + fun delete() { + addDomainEvent(ActorDomainEventFactory(this).createEvent(delete)) + } + + abstract class Actor2Factory { + protected suspend fun create( + id: ActorId, + name: ActorName, + domain: Domain, + screenName: ActorScreenName, + description: ActorDescription, + inbox: URI, + outbox: URI, + url: URI, + publicKey: ActorPublicKey, + privateKey: ActorPrivateKey? = null, + createdAt: Instant, + keyId: ActorKeyId, + followersEndpoint: URI, + followingEndpoint: URI, + instance: InstanceId, + locked: Boolean, + followersCount: ActorRelationshipCount, + followingCount: ActorRelationshipCount, + postsCount: ActorPostsCount, + lastPostDate: Instant? = null, + suspend: Boolean, + ): Actor2 { + return Actor2( + id = id, + name = name, + domain = domain, + screenName = screenName, + description = description, + inbox = inbox, + outbox = outbox, + url = url, + publicKey = publicKey, + privateKey = privateKey, + createdAt = createdAt, + keyId = keyId, + followersEndpoint = followersEndpoint, + followingEndpoint = followingEndpoint, + instance = instance, + locked = locked, + followersCount = followersCount, + followingCount = followingCount, + postsCount = postsCount, + lastPostDate = lastPostDate, + suspend = suspend + ) + } + } +} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor2Repository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor2Repository.kt new file mode 100644 index 00000000..10c21a63 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor2Repository.kt @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.actor + +interface Actor2Repository { + suspend fun save(actor: Actor2): Actor2 + suspend fun deleteById(actor: ActorId) + suspend fun findById(id: ActorId): Actor2? +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorDescription.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorDescription.kt new file mode 100644 index 00000000..3050836d --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorDescription.kt @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.actor + +import dev.usbharu.hideout.core.domain.model.emoji.EmojiId + + +class ActorDescription private constructor(private val description: String, private val emojis: List) { + abstract class ActorDescriptionFactory { + protected suspend fun create(description: String, emojis: List): ActorDescription = + ActorDescription(description, emojis) + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorId.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorId.kt new file mode 100644 index 00000000..73f5a022 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorId.kt @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.actor + +@JvmInline +value class ActorId(val id: Long) { + companion object { + val ghost = ActorId(0L) + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorKeyId.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorKeyId.kt new file mode 100644 index 00000000..776ceda2 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorKeyId.kt @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.actor + +@JvmInline +value class ActorKeyId(private val keyId: String) \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorName.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorName.kt new file mode 100644 index 00000000..77983e4e --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorName.kt @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.actor + +@JvmInline +value class ActorName(val name: String) \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPostsCount.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPostsCount.kt new file mode 100644 index 00000000..ae44b411 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPostsCount.kt @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.actor + +@JvmInline +value class ActorPostsCount(private val postsCount: Long) { + init { + require(0 <= this.postsCount) { "Posts count must be greater than 0" } + } + + operator fun inc() = ActorPostsCount(postsCount + 1) + operator fun dec() = ActorPostsCount(postsCount - 1) +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPrivateKey.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPrivateKey.kt new file mode 100644 index 00000000..a909cfa3 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPrivateKey.kt @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.actor + +@JvmInline +value class ActorPrivateKey(private val privateKey: String) \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPublicKey.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPublicKey.kt new file mode 100644 index 00000000..5428c231 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPublicKey.kt @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.actor + +@JvmInline +value class ActorPublicKey(private val publicKey: String) \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorRelationshipCount.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorRelationshipCount.kt new file mode 100644 index 00000000..c55be570 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorRelationshipCount.kt @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.actor + +@JvmInline +value class ActorRelationshipCount(private val followersCount: Int) { + init { + require(0 <= followersCount) { "Followers count must be > 0" } + } + + operator fun inc(): ActorRelationshipCount = ActorRelationshipCount(followersCount + 1) + operator fun dec(): ActorRelationshipCount = ActorRelationshipCount(followersCount - 1) +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorScreenName.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorScreenName.kt new file mode 100644 index 00000000..83ed08aa --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorScreenName.kt @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.actor + +import dev.usbharu.hideout.core.domain.model.emoji.EmojiId + + +class ActorScreenName private constructor(val screenName: String, val emojis: List) { + + abstract class ActorScreenNameFactory { + protected suspend fun create(screenName: String, emojis: List): ActorScreenName = + ActorScreenName(screenName, emojis) + } +} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actorinstancerelationship/ActorInstanceRelationship.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actorinstancerelationship/ActorInstanceRelationship.kt new file mode 100644 index 00000000..82ce5599 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actorinstancerelationship/ActorInstanceRelationship.kt @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.actorinstancerelationship + +import dev.usbharu.hideout.core.domain.event.actorinstancerelationship.ActorInstanceRelationshipDomainEventFactory +import dev.usbharu.hideout.core.domain.event.actorinstancerelationship.ActorInstanceRelationshipEvent.* +import dev.usbharu.hideout.core.domain.model.actor.ActorId +import dev.usbharu.hideout.core.domain.model.instance.InstanceId +import dev.usbharu.hideout.core.domain.model.shared.domainevent.DomainEventStorable + +data class ActorInstanceRelationship( + val actorId: ActorId, + val instanceId: InstanceId, + private var blocking: Boolean = false, + private var muting: Boolean = false, + private var doNotSendPrivate: Boolean = false, +) : DomainEventStorable() { + fun block(): ActorInstanceRelationship { + addDomainEvent(ActorInstanceRelationshipDomainEventFactory(this).createEvent(block)) + blocking = true + return this + } + + fun unblock(): ActorInstanceRelationship { + blocking = false + return this + } + + fun mute(): ActorInstanceRelationship { + addDomainEvent(ActorInstanceRelationshipDomainEventFactory(this).createEvent(mute)) + muting = true + return this + } + + fun unmute(): ActorInstanceRelationship { + addDomainEvent(ActorInstanceRelationshipDomainEventFactory(this).createEvent(unmute)) + muting = false + return this + } + + fun doNotSendPrivate(): ActorInstanceRelationship { + doNotSendPrivate = true + return this + } + + fun doSendPrivate(): ActorInstanceRelationship { + doNotSendPrivate = false + return this + } + + fun isBlocking() = blocking + + fun isMuting() = muting + + fun isDoNotSendPrivate() = doNotSendPrivate + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as ActorInstanceRelationship + + if (actorId != other.actorId) return false + if (instanceId != other.instanceId) return false + + return true + } + + override fun hashCode(): Int { + var result = actorId.hashCode() + result = 31 * result + instanceId.hashCode() + return result + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/deletedActor/DeletedActor.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/deletedActor/DeletedActor.kt index 0455435f..61e15775 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/deletedActor/DeletedActor.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/deletedActor/DeletedActor.kt @@ -16,13 +16,17 @@ package dev.usbharu.hideout.core.domain.model.deletedActor +import dev.usbharu.hideout.core.domain.model.actor.ActorName +import dev.usbharu.hideout.core.domain.model.actor.ActorPublicKey +import dev.usbharu.hideout.core.domain.model.shared.Domain +import java.net.URI import java.time.Instant data class DeletedActor( - val id: Long, - val name: String, - val domain: String, - val apiId: String, - val publicKey: String, + val id: DeletedActorId, + val name: ActorName, + val domain: Domain, + val apId: URI, + val publicKey: ActorPublicKey, val deletedAt: Instant, ) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/deletedActor/DeletedActorId.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/deletedActor/DeletedActorId.kt new file mode 100644 index 00000000..b8cfbc98 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/deletedActor/DeletedActorId.kt @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.deletedActor + +@JvmInline +value class DeletedActorId(val id: Long) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/emoji/CustomEmojiRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/emoji/CustomEmojiRepository.kt index eaac7bd5..de339d34 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/emoji/CustomEmojiRepository.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/emoji/CustomEmojiRepository.kt @@ -22,4 +22,5 @@ interface CustomEmojiRepository { suspend fun findById(id: Long): CustomEmoji? suspend fun delete(customEmoji: CustomEmoji) suspend fun findByNameAndDomain(name: String, domain: String): CustomEmoji? + suspend fun findByNamesAndDomain(names: List, domain: String): List } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/emoji/EmojiId.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/emoji/EmojiId.kt new file mode 100644 index 00000000..f5d537c2 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/emoji/EmojiId.kt @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.emoji + +@JvmInline +value class EmojiId(private val emojiId: Long) \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Instance.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Instance.kt index 3d0aac30..d8ea3516 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Instance.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Instance.kt @@ -16,19 +16,46 @@ package dev.usbharu.hideout.core.domain.model.instance +import dev.usbharu.hideout.core.domain.event.instance.InstanceEvent +import dev.usbharu.hideout.core.domain.event.instance.InstanceEventFactory +import dev.usbharu.hideout.core.domain.model.shared.domainevent.DomainEventStorable +import java.net.URI import java.time.Instant -data class Instance( - val id: Long, - val name: String, - val description: String, - val url: String, - val iconUrl: String, - val sharedInbox: String?, - val software: String, - val version: String, - val isBlocked: Boolean, - val isMuted: Boolean, - val moderationNote: String, - val createdAt: Instant -) +class Instance( + val id: InstanceId, + var name: InstanceName, + var description: InstanceDescription, + val url: URI, + iconUrl: URI, + var sharedInbox: URI?, + var software: InstanceSoftware, + var version: InstanceVersion, + var isBlocked: Boolean, + var isMuted: Boolean, + var moderationNote: InstanceModerationNote, + val createdAt: Instant, +) : DomainEventStorable() { + + + var iconUrl = iconUrl + set(value) { + addDomainEvent(InstanceEventFactory(this).createEvent(InstanceEvent.update)) + field = value + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as Instance + + return id == other.id + } + + override fun hashCode(): Int { + return id.hashCode() + } + + +} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceDescription.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceDescription.kt new file mode 100644 index 00000000..8a6f2084 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceDescription.kt @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.instance + +@JvmInline +value class InstanceDescription(val description: String) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceId.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceId.kt new file mode 100644 index 00000000..de5e4277 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceId.kt @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.instance + +@JvmInline +value class InstanceId(private val instanceId: Long) \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceModerationNote.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceModerationNote.kt new file mode 100644 index 00000000..6439f75c --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceModerationNote.kt @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.instance + +@JvmInline +value class InstanceModerationNote(val note: String) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceName.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceName.kt new file mode 100644 index 00000000..5133566e --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceName.kt @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.instance + +@JvmInline +value class InstanceName(val name: String) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceRepository.kt index 121e5adc..7ab21f8f 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceRepository.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceRepository.kt @@ -16,10 +16,12 @@ package dev.usbharu.hideout.core.domain.model.instance +import java.net.URI + interface InstanceRepository { - suspend fun generateId(): Long + suspend fun generateId(): InstanceId suspend fun save(instance: Instance): Instance - suspend fun findById(id: Long): Instance? + suspend fun findById(id: InstanceId): Instance? suspend fun delete(instance: Instance) - suspend fun findByUrl(url: String): Instance? + suspend fun findByUrl(url: URI): Instance? } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceSoftware.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceSoftware.kt new file mode 100644 index 00000000..30d06746 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceSoftware.kt @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.instance + +@JvmInline +value class InstanceSoftware(val software: String) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceVersion.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceVersion.kt new file mode 100644 index 00000000..b8770133 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceVersion.kt @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.instance + +@JvmInline +value class InstanceVersion(val version: String) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/MediaId.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/MediaId.kt new file mode 100644 index 00000000..5003f164 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/MediaId.kt @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.media + +@JvmInline +value class MediaId(val id: Long) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post2.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post2.kt new file mode 100644 index 00000000..f2b4f990 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post2.kt @@ -0,0 +1,229 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.post + +import dev.usbharu.hideout.core.domain.event.post.PostDomainEventFactory +import dev.usbharu.hideout.core.domain.event.post.PostEvent +import dev.usbharu.hideout.core.domain.model.actor.ActorId +import dev.usbharu.hideout.core.domain.model.media.MediaId +import dev.usbharu.hideout.core.domain.model.shared.domainevent.DomainEventStorable +import java.net.URI +import java.time.Instant + +class Post2 private constructor( + val id: PostId, + actorId: ActorId, + overview: PostOverview? = null, + content: PostContent, + val createdAt: Instant, + visibility: Visibility, + val url: URI, + val repostId: PostId?, + val replyId: PostId?, + sensitive: Boolean, + val apId: URI, + deleted: Boolean, + mediaIds: List, + visibleActors: List = emptyList(), + hide: Boolean = false, + moveTo: PostId? = null, +) : DomainEventStorable() { + + var actorId = actorId + private set + get() { + if (deleted) { + return ActorId.ghost + } + return field + } + + var visibility = visibility + set(value) { + require(value != Visibility.DIRECT) + require(field.ordinal >= value.ordinal) + + require(deleted.not()) + + if (field != value) { + addDomainEvent(PostDomainEventFactory(this).createEvent(PostEvent.update)) + } + field = value + } + + var visibleActors = visibleActors + set(value) { + require(deleted.not()) + if (visibility == Visibility.DIRECT) { + addDomainEvent(PostDomainEventFactory(this).createEvent(PostEvent.update)) + field = field.plus(value).distinct() + } + } + + var content = content + get() { + if (hide) { + return PostContent.empty + } + return field + } + set(value) { + require(deleted.not()) + if (field != value) { + addDomainEvent(PostDomainEventFactory(this).createEvent(PostEvent.update)) + } + field = value + } + + var overview = overview + get() { + if (hide) { + return null + } + return field + } + set(value) { + require(deleted.not()) + if (field != value) { + addDomainEvent(PostDomainEventFactory(this).createEvent(PostEvent.update)) + } + field = value + } + + var sensitive = sensitive + set(value) { + require(deleted.not()) + if (field != value) { + addDomainEvent(PostDomainEventFactory(this).createEvent(PostEvent.update)) + } + field = value + } + + val text + get() = content.text + + val emojiIds + get() = content.emojiIds + + var mediaIds = mediaIds + get() { + if (hide) { + return emptyList() + } + return field + } + private set + + fun addMediaIds(mediaIds: List) { + require(deleted.not()) + addDomainEvent(PostDomainEventFactory(this).createEvent(PostEvent.update)) + this.mediaIds = this.mediaIds.plus(mediaIds).distinct() + } + + var deleted = deleted + private set + + fun delete() { + if (deleted.not()) { + addDomainEvent(PostDomainEventFactory(this).createEvent(PostEvent.delete)) + content = PostContent.empty + overview = null + mediaIds = emptyList() + + } + deleted = true + } + + fun checkUpdate() { + addDomainEvent(PostDomainEventFactory(this).createEvent(PostEvent.checkUpdate)) + } + + fun restore(content: PostContent, overview: PostOverview?, mediaIds: List) { + deleted = false + this.content = content + this.overview = overview + this.mediaIds = mediaIds + } + + var hide = hide + private set + + fun hide() { + hide = true + } + + fun show() { + hide = false + } + + var moveTo = moveTo + private set + + fun moveTo(moveTo: PostId) { + require(this.moveTo == null) + this.moveTo = moveTo + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as Post2 + + return id == other.id + } + + override fun hashCode(): Int { + return id.hashCode() + } + + abstract class PostFactory { + protected fun create( + id: PostId, + actorId: ActorId, + overview: PostOverview? = null, + content: PostContent, + createdAt: Instant, + visibility: Visibility, + url: URI, + repostId: PostId?, + replyId: PostId?, + sensitive: Boolean, + apId: URI, + deleted: Boolean, + mediaIds: List, + hide: Boolean, + ): Post2 { + return Post2( + id = id, + actorId = actorId, + overview = overview, + content = content, + createdAt = createdAt, + visibility = visibility, + url = url, + repostId = repostId, + replyId = replyId, + sensitive = sensitive, + apId = apId, + deleted = deleted, + mediaIds = mediaIds, + hide = hide + ).apply { addDomainEvent(PostDomainEventFactory(this).createEvent(PostEvent.create)) } + } + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post2Repository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post2Repository.kt new file mode 100644 index 00000000..91961a6f --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post2Repository.kt @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.post + +interface Post2Repository { + suspend fun save(post: Post2): Post2 + suspend fun findById(id: PostId): Post2? + suspend fun deleteById(id: PostId) +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContent.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContent.kt new file mode 100644 index 00000000..2ed4df88 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContent.kt @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.post + +import dev.usbharu.hideout.core.domain.model.emoji.EmojiId + +class PostContent private constructor(val text: String, val content: String, val emojiIds: List) { + + companion object { + val empty = PostContent("", "", emptyList()) + } + + abstract class PostContentFactory { + protected suspend fun create(text: String, content: String, emojiIds: List): PostContent { + return PostContent( + text, content, emojiIds + ) + } + } +} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostId.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostId.kt new file mode 100644 index 00000000..e4682ff1 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostId.kt @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.post + +@JvmInline +value class PostId(val id: Long) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostOverview.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostOverview.kt new file mode 100644 index 00000000..995329b1 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostOverview.kt @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.post + +@JvmInline +value class PostOverview(val overview: String) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/Domain.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/Domain.kt new file mode 100644 index 00000000..a6aaa4c8 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/Domain.kt @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.shared + +@JvmInline +value class Domain(val domain: String) \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/domainevent/DomainEvent.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/domainevent/DomainEvent.kt new file mode 100644 index 00000000..53c48d86 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/domainevent/DomainEvent.kt @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.shared.domainevent + +import java.time.Instant +import java.util.* + +data class DomainEvent( + private val id: String, + private val name: String, + private val occurredOn: Instant, + private val body: DomainEventBody, +) { + companion object { + fun create(name: String, body: DomainEventBody): DomainEvent { + return DomainEvent(UUID.randomUUID().toString(), name, Instant.now(), body) + } + + fun reconstruct(id: String, name: String, occurredOn: Instant, body: DomainEventBody): DomainEvent { + return DomainEvent(id, name, occurredOn, body) + } + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/domainevent/DomainEventBody.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/domainevent/DomainEventBody.kt new file mode 100644 index 00000000..cb7dd4d9 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/domainevent/DomainEventBody.kt @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.shared.domainevent + +abstract class DomainEventBody(val map: Map) { + fun toMap(): Map { + return map + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/domainevent/DomainEventStorable.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/domainevent/DomainEventStorable.kt new file mode 100644 index 00000000..a0da8d06 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/domainevent/DomainEventStorable.kt @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.shared.domainevent + +abstract class DomainEventStorable { + private val domainEvents: MutableList = mutableListOf() + + protected fun addDomainEvent(domainEvent: DomainEvent) { + domainEvents.add(domainEvent) + } + + fun clearDomainEvents() = domainEvents.clear() + + fun getDomainEvents(): List = domainEvents.toList() +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/userdetails/UserDetail.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/userdetails/UserDetail.kt index aabaa0ce..19c32158 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/userdetails/UserDetail.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/userdetails/UserDetail.kt @@ -16,8 +16,33 @@ package dev.usbharu.hideout.core.domain.model.userdetails -data class UserDetail( - val actorId: Long, - val password: String, - val autoAcceptFolloweeFollowRequest: Boolean -) +import dev.usbharu.hideout.core.domain.model.actor.ActorId + +class UserDetail( + val actorId: ActorId, + var password: UserDetailHashedPassword, + var autoAcceptFolloweeFollowRequest: Boolean, +) { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as UserDetail + + return actorId == other.actorId + } + + override fun hashCode(): Int { + return actorId.hashCode() + } + + companion object { + fun create( + actorId: ActorId, + password: UserDetailHashedPassword, + autoAcceptFolloweeFollowRequest: Boolean = false, + ): UserDetail { + return UserDetail(actorId, password, autoAcceptFolloweeFollowRequest) + } + } +} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/userdetails/UserDetailHashedPassword.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/userdetails/UserDetailHashedPassword.kt new file mode 100644 index 00000000..f0dc4399 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/userdetails/UserDetailHashedPassword.kt @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.model.userdetails + +@JvmInline +value class UserDetailHashedPassword(val password: String) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/actor/RemoteActorCheckDomainService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/actor/RemoteActorCheckDomainService.kt new file mode 100644 index 00000000..6c594f1b --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/actor/RemoteActorCheckDomainService.kt @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.service.actor + +import dev.usbharu.hideout.application.config.ApplicationConfig +import dev.usbharu.hideout.core.domain.model.actor.Actor +import org.springframework.stereotype.Service + +interface IRemoteActorCheckDomainService { + fun isRemoteActor(actor: Actor): Boolean +} + +@Service +class RemoteActorCheckDomainService(private val applicationConfig: ApplicationConfig) : IRemoteActorCheckDomainService { + override fun isRemoteActor(actor: Actor): Boolean = actor.domain == applicationConfig.url.host +} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/actor/local/LocalActorDomainService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/actor/local/LocalActorDomainService.kt new file mode 100644 index 00000000..677654f7 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/actor/local/LocalActorDomainService.kt @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.service.actor.local + +import dev.usbharu.hideout.core.domain.model.actor.ActorPrivateKey +import dev.usbharu.hideout.core.domain.model.actor.ActorPublicKey + +interface LocalActorDomainService { + suspend fun usernameAlreadyUse(name: String): Boolean + suspend fun generateKeyPair(): Pair +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/actorinstancerelationship/ActorInstanceRelationshipDomainService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/actorinstancerelationship/ActorInstanceRelationshipDomainService.kt new file mode 100644 index 00000000..ac573d8c --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/actorinstancerelationship/ActorInstanceRelationshipDomainService.kt @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.service.actorinstancerelationship + +interface ActorInstanceRelationshipDomainService { + suspend fun block() +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/userdetail/PasswordEncoder.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/userdetail/PasswordEncoder.kt new file mode 100644 index 00000000..9ff2ee3d --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/userdetail/PasswordEncoder.kt @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.service.userdetail + +interface PasswordEncoder { + suspend fun encode(input: String): String +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/userdetail/UserDetailDomainService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/userdetail/UserDetailDomainService.kt new file mode 100644 index 00000000..33db1331 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/userdetail/UserDetailDomainService.kt @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.domain.service.userdetail + +import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailHashedPassword +import org.springframework.stereotype.Service + +@Service +class UserDetailDomainService(private val passwordEncoder: PasswordEncoder) { + suspend fun hashPassword(password: String) = UserDetailHashedPassword(passwordEncoder.encode(password)) +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/DeletedActorRepositoryImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/DeletedActorRepositoryImpl.kt index 41bd924b..a6900563 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/DeletedActorRepositoryImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/DeletedActorRepositoryImpl.kt @@ -39,7 +39,7 @@ class DeletedActorRepositoryImpl : DeletedActorRepository, AbstractRepository() it[id] = deletedActor.id it[name] = deletedActor.name it[domain] = deletedActor.domain - it[apId] = deletedActor.apiId + it[apId] = deletedActor.apId it[publicKey] = deletedActor.publicKey it[deletedAt] = deletedActor.deletedAt } @@ -47,7 +47,7 @@ class DeletedActorRepositoryImpl : DeletedActorRepository, AbstractRepository() DeletedActors.update({ DeletedActors.id eq deletedActor.id }) { it[name] = deletedActor.name it[domain] = deletedActor.domain - it[apId] = deletedActor.apiId + it[apId] = deletedActor.apId it[publicKey] = deletedActor.publicKey it[deletedAt] = deletedActor.deletedAt } @@ -85,7 +85,7 @@ private fun deletedActor(singleOr: ResultRow): DeletedActor { id = singleOr[DeletedActors.id], name = singleOr[DeletedActors.name], domain = singleOr[DeletedActors.domain], - apiId = singleOr[DeletedActors.publicKey], + apId = singleOr[DeletedActors.publicKey], publicKey = singleOr[DeletedActors.apId], deletedAt = singleOr[DeletedActors.deletedAt] ) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/Actor2FactoryImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/Actor2FactoryImpl.kt new file mode 100644 index 00000000..937744d8 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/Actor2FactoryImpl.kt @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.infrastructure.factory + +import dev.usbharu.hideout.application.config.ApplicationConfig +import dev.usbharu.hideout.application.service.id.IdGenerateService +import dev.usbharu.hideout.core.domain.model.actor.* +import dev.usbharu.hideout.core.domain.model.instance.InstanceId +import dev.usbharu.hideout.core.domain.model.shared.Domain +import org.springframework.stereotype.Component +import java.net.URI +import java.time.Instant + +@Component +class Actor2FactoryImpl( + private val idGenerateService: IdGenerateService, + private val actorScreenNameFactory: ActorScreenNameFactoryImpl, + private val actorDescriptionFactory: ActorDescriptionFactoryImpl, + private val applicationConfig: ApplicationConfig, +) : Actor2.Actor2Factory() { + suspend fun createLocal( + name: String, + keyPair: Pair, + instanceId: InstanceId, + ): Actor2 { + val actorName = ActorName(name) + val userUrl = "${applicationConfig.url}/users/${actorName.name}" + return super.create( + id = ActorId(idGenerateService.generateId()), + name = actorName, + domain = Domain(applicationConfig.url.host), + screenName = actorScreenNameFactory.create(name), + description = actorDescriptionFactory.create(""), + inbox = URI.create("$userUrl/inbox"), + outbox = URI.create("$userUrl/outbox"), + url = applicationConfig.url.toURI(), + publicKey = keyPair.first, + privateKey = keyPair.second, + createdAt = Instant.now(), + keyId = ActorKeyId("$userUrl#main-key"), + followersEndpoint = URI.create("$userUrl/followers"), + followingEndpoint = URI.create("$userUrl/following"), + instance = instanceId, + locked = false, + followersCount = ActorRelationshipCount(0), + followingCount = ActorRelationshipCount(0), + postsCount = ActorPostsCount(0), + lastPostDate = null, + suspend = false + ) + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/ActorDescriptionFactoryImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/ActorDescriptionFactoryImpl.kt new file mode 100644 index 00000000..a5d107e4 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/ActorDescriptionFactoryImpl.kt @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.infrastructure.factory + +import dev.usbharu.hideout.application.config.ApplicationConfig +import dev.usbharu.hideout.core.domain.model.actor.ActorDescription +import dev.usbharu.hideout.core.domain.model.emoji.CustomEmojiRepository +import dev.usbharu.hideout.core.domain.model.emoji.EmojiId +import org.springframework.stereotype.Component + +@Component +class ActorDescriptionFactoryImpl( + private val applicationConfig: ApplicationConfig, + private val emojiRepository: CustomEmojiRepository, +) : ActorDescription.ActorDescriptionFactory() { + val regex = Regex(":(w+):") + suspend fun create(description: String): ActorDescription { + val findAll = regex.findAll(description) + + val emojis = + emojiRepository.findByNamesAndDomain( + findAll.map { it.groupValues[1] }.toList(), + applicationConfig.url.host + ) + return create(description, emojis.map { EmojiId(it.id) }) + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/ActorScreenNameFactoryImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/ActorScreenNameFactoryImpl.kt new file mode 100644 index 00000000..b82773e4 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/ActorScreenNameFactoryImpl.kt @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.infrastructure.factory + +import dev.usbharu.hideout.application.config.ApplicationConfig +import dev.usbharu.hideout.core.domain.model.actor.ActorScreenName +import dev.usbharu.hideout.core.domain.model.emoji.CustomEmojiRepository +import dev.usbharu.hideout.core.domain.model.emoji.EmojiId +import org.springframework.stereotype.Component + +@Component +class ActorScreenNameFactoryImpl( + private val applicationConfig: ApplicationConfig, + private val emojiRepository: CustomEmojiRepository, +) : ActorScreenName.ActorScreenNameFactory() { + val regex = Regex(":(w+):") + + suspend fun create(content: String): ActorScreenName { + + val findAll = regex.findAll(content) + + val emojis = + emojiRepository.findByNamesAndDomain( + findAll.map { it.groupValues[1] }.toList(), + applicationConfig.url.host + ) + return create(content, emojis.map { EmojiId(it.id) }) + + } + +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostContentFactoryImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostContentFactoryImpl.kt new file mode 100644 index 00000000..b8536126 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostContentFactoryImpl.kt @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.infrastructure.factory + +import dev.usbharu.hideout.core.domain.model.post.PostContent +import dev.usbharu.hideout.core.service.post.PostContentFormatter +import org.springframework.stereotype.Component + +@Component +class PostContentFactoryImpl( + private val postContentFormatter: PostContentFormatter, +) : PostContent.PostContentFactory() { + suspend fun create(content: String): PostContent { + val format = postContentFormatter.format(content) + return super.create( + format.content, + format.html, + emptyList() + ) + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostFactoryImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostFactoryImpl.kt new file mode 100644 index 00000000..4a3ae815 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostFactoryImpl.kt @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.infrastructure.factory + +import dev.usbharu.hideout.application.config.ApplicationConfig +import dev.usbharu.hideout.application.service.id.IdGenerateService +import dev.usbharu.hideout.core.domain.model.actor.ActorId +import dev.usbharu.hideout.core.domain.model.actor.ActorName +import dev.usbharu.hideout.core.domain.model.media.MediaId +import dev.usbharu.hideout.core.domain.model.post.Post2 +import dev.usbharu.hideout.core.domain.model.post.PostId +import dev.usbharu.hideout.core.domain.model.post.PostOverview +import dev.usbharu.hideout.core.domain.model.post.Visibility +import org.springframework.stereotype.Component +import java.net.URI +import java.time.Instant + +@Component +class PostFactoryImpl( + private val idGenerateService: IdGenerateService, + private val postContentFactoryImpl: PostContentFactoryImpl, + private val applicationConfig: ApplicationConfig, +) : Post2.PostFactory() { + suspend fun createLocal( + actorId: ActorId, + actorName: ActorName, + overview: PostOverview, + content: String, + visibility: Visibility, + repostId: PostId?, + replyId: PostId?, + sensitive: Boolean, + mediaIds: List, + ): Post2 { + val id = idGenerateService.generateId() + val url = URI.create(applicationConfig.url.toString() + "/users/" + actorName + "/posts/" + id) + return super.create( + PostId(id), + actorId, + overview, + postContentFactoryImpl.create(content), + Instant.now(), + visibility, + url, + repostId, + replyId, + sensitive, + url, + false, + mediaIds + ) + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserServiceImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserServiceImpl.kt index 889c5257..fbc80538 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserServiceImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserServiceImpl.kt @@ -159,7 +159,7 @@ class UserServiceImpl( id = actor.id, name = actor.name, domain = actor.domain, - apiId = actor.url, + apId = actor.url, publicKey = actor.publicKey, deletedAt = Instant.now() ) @@ -179,7 +179,7 @@ class UserServiceImpl( deletedActorRepository.delete(deletedActor) - owlProducer.publishTask(UpdateActorTask(deletedActor.id, deletedActor.apiId)) + owlProducer.publishTask(UpdateActorTask(deletedActor.id, deletedActor.apId)) } override suspend fun deleteLocalUser(userId: Long) { @@ -189,7 +189,7 @@ class UserServiceImpl( id = actor.id, name = actor.name, domain = actor.domain, - apiId = actor.url, + apId = actor.url, publicKey = actor.publicKey, deletedAt = Instant.now() ) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/DeleteLocalActorApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/DeleteLocalActorApplicationService.kt new file mode 100644 index 00000000..c1160fc3 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/DeleteLocalActorApplicationService.kt @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.usecase.actor + +import dev.usbharu.hideout.core.domain.model.actor.ActorId + +class DeleteLocalActorApplicationService { + suspend fun delete(actorId: ActorId, executor: ActorId) { + + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/MigrationLocalActorApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/MigrationLocalActorApplicationService.kt new file mode 100644 index 00000000..ee853538 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/MigrationLocalActorApplicationService.kt @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.usecase.actor + +import dev.usbharu.hideout.core.domain.model.actor.ActorId + +class MigrationLocalActorApplicationService { + suspend fun migration(from: ActorId, to: ActorId, executor: ActorId) { + TODO() + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/RegisterLocalActor.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/RegisterLocalActor.kt new file mode 100644 index 00000000..8031a87c --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/RegisterLocalActor.kt @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.usecase.actor + +data class RegisterLocalActor( + val name: String, + val password: String, +) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/RegisterLocalActorApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/RegisterLocalActorApplicationService.kt new file mode 100644 index 00000000..7127d8a9 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/RegisterLocalActorApplicationService.kt @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.usecase.actor + +import dev.usbharu.hideout.application.config.ApplicationConfig +import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.domain.model.actor.Actor2Repository +import dev.usbharu.hideout.core.domain.model.instance.InstanceRepository +import dev.usbharu.hideout.core.domain.model.userdetails.UserDetail +import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository +import dev.usbharu.hideout.core.domain.service.actor.local.LocalActorDomainService +import dev.usbharu.hideout.core.domain.service.userdetail.UserDetailDomainService +import dev.usbharu.hideout.core.infrastructure.factory.Actor2FactoryImpl +import org.springframework.stereotype.Service + +@Service +class RegisterLocalActorApplicationService( + private val transaction: Transaction, + private val actorDomainService: LocalActorDomainService, + private val actor2Repository: Actor2Repository, + private val actor2FactoryImpl: Actor2FactoryImpl, + private val instanceRepository: InstanceRepository, + private val applicationConfig: ApplicationConfig, + private val userDetailDomainService: UserDetailDomainService, + private val userDetailRepository: UserDetailRepository, +) { + suspend fun register(registerLocalActor: RegisterLocalActor) { + transaction.transaction { + if (actorDomainService.usernameAlreadyUse(registerLocalActor.name)) { + //todo 適切な例外を考える + throw Exception("Username already exists") + } + val instance = instanceRepository.findByUrl(applicationConfig.url.toURI())!! + + + val actor = actor2FactoryImpl.createLocal( + registerLocalActor.name, + actorDomainService.generateKeyPair(), + instance.id + ) + actor2Repository.save(actor) + val userDetail = UserDetail.create( + actor.id, + userDetailDomainService.hashPassword(registerLocalActor.password), + ) + userDetailRepository.save(userDetail) + + } + + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/SuspendLocalActorApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/SuspendLocalActorApplicationService.kt new file mode 100644 index 00000000..1961ce0f --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/SuspendLocalActorApplicationService.kt @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.usecase.actor + +import dev.usbharu.hideout.core.domain.model.actor.Actor2Repository +import dev.usbharu.hideout.core.domain.model.actor.ActorId + +class SuspendLocalActorApplicationService(private val actor2Repository: Actor2Repository) { + suspend fun suspend(actorId: Long, executor: ActorId) { + val findById = actor2Repository.findById(ActorId(actorId))!! + + findById.suspend = true + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/UnsuspendLocalActorApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/UnsuspendLocalActorApplicationService.kt new file mode 100644 index 00000000..e87d9b0d --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/actor/UnsuspendLocalActorApplicationService.kt @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.usecase.actor + +import dev.usbharu.hideout.core.domain.model.actor.ActorId + +interface UnsuspendLocalActorApplicationService { + suspend fun unsuspend(actorId: ActorId, executor: ActorId) +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/DeleteLocalPostApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/DeleteLocalPostApplicationService.kt new file mode 100644 index 00000000..80fd74ca --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/DeleteLocalPostApplicationService.kt @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.usecase.post + +import dev.usbharu.hideout.core.domain.model.post.Post2Repository +import dev.usbharu.hideout.core.domain.model.post.PostId +import org.springframework.stereotype.Service + +@Service +class DeleteLocalPostApplicationService(private val postRepository: Post2Repository) { + suspend fun delete(postId: Long) { + val findById = postRepository.findById(PostId(postId))!! + findById.delete() + postRepository.save(findById) + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/RegisterLocalPost.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/RegisterLocalPost.kt new file mode 100644 index 00000000..025991d9 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/RegisterLocalPost.kt @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.usecase.post + +import dev.usbharu.hideout.core.domain.model.post.Visibility + +data class RegisterLocalPost( + val actorId: Long, + val content: String, + val overview: String, + val visibility: Visibility, + val repostId: Long?, + val replyId: Long?, + val sensitive: Boolean, + val mediaIds: List, +) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/RegisterLocalPostApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/RegisterLocalPostApplicationService.kt new file mode 100644 index 00000000..e08bffb2 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/RegisterLocalPostApplicationService.kt @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.usecase.post + +import dev.usbharu.hideout.core.domain.model.actor.Actor2Repository +import dev.usbharu.hideout.core.domain.model.actor.ActorId +import dev.usbharu.hideout.core.domain.model.media.MediaId +import dev.usbharu.hideout.core.domain.model.post.Post2Repository +import dev.usbharu.hideout.core.domain.model.post.PostId +import dev.usbharu.hideout.core.domain.model.post.PostOverview +import dev.usbharu.hideout.core.infrastructure.factory.PostFactoryImpl +import org.springframework.stereotype.Service + +@Service +class RegisterLocalPostApplicationService( + private val postFactory: PostFactoryImpl, + private val actor2Repository: Actor2Repository, + private val postRepository: Post2Repository, +) { + suspend fun register(registerLocalPost: RegisterLocalPost) { + + val actorId = ActorId(registerLocalPost.actorId) + val post = postFactory.createLocal( + actorId, + actor2Repository.findById(actorId)!!.name, + PostOverview(registerLocalPost.overview), + registerLocalPost.content, + registerLocalPost.visibility, + registerLocalPost.repostId?.let { PostId(it) }, + registerLocalPost.replyId?.let { PostId(it) }, + registerLocalPost.sensitive, + registerLocalPost.mediaIds.map { MediaId(it) } + ) + + postRepository.save(post) + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/UpdateLocalNote.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/UpdateLocalNote.kt new file mode 100644 index 00000000..318c010a --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/UpdateLocalNote.kt @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.usecase.post + +data class UpdateLocalNote( + val postId: Long, + val overview: String?, + val content: String, + val sensitive: Boolean, + val mediaIds: List, +) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/UpdateLocalNoteApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/UpdateLocalNoteApplicationService.kt new file mode 100644 index 00000000..d7aaa905 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/usecase/post/UpdateLocalNoteApplicationService.kt @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.usecase.post + +import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.domain.model.media.MediaId +import dev.usbharu.hideout.core.domain.model.post.Post2Repository +import dev.usbharu.hideout.core.domain.model.post.PostId +import dev.usbharu.hideout.core.domain.model.post.PostOverview +import dev.usbharu.hideout.core.infrastructure.factory.PostContentFactoryImpl +import org.springframework.stereotype.Service + +@Service +class UpdateLocalNoteApplicationService( + private val transaction: Transaction, + private val postRepository: Post2Repository, + private val postContentFactoryImpl: PostContentFactoryImpl, +) { + suspend fun update(updateLocalNote: UpdateLocalNote) { + transaction.transaction { + val post = postRepository.findById(PostId(updateLocalNote.postId))!! + + post.content = postContentFactoryImpl.create(updateLocalNote.content) + post.overview = updateLocalNote.overview?.let { PostOverview(it) } + post.mediaIds = updateLocalNote.mediaIds.map { MediaId(it) } + post.sensitive = updateLocalNote.sensitive + + postRepository.save(post) + } + } +} \ No newline at end of file