From c0f03560d5633c88b6d9be9a400b9cbe3e4f94e8 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sat, 29 Jun 2024 00:02:50 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20TimelinePostCreateSubscriber=E3=81=8C?= =?UTF-8?q?=E6=A9=9F=E8=83=BD=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 3 ++- docker-compose.yml | 11 +++++++++ .../domainevent/subscribers/Subscriber.kt | 4 ++++ .../subscribers/SubscriberRunner.kt | 12 ++++++++++ .../TimelinePostCreateSubscriber.kt | 11 +++++++-- .../hideout/core/domain/model/post/Post.kt | 24 +++++++++++++++++++ .../src/main/resources/application.yml | 4 ++-- .../resources/db/migration/V1__Init_DB.sql | 9 +++++++ hideout-core/src/main/resources/log4j2.xml | 2 +- hideout-mastodon/build.gradle.kts | 9 +++++++ .../exposedquery/ExposedStatusQueryService.kt | 3 ++- 11 files changed, 85 insertions(+), 7 deletions(-) create mode 100644 docker-compose.yml create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/Subscriber.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/SubscriberRunner.kt diff --git a/build.gradle.kts b/build.gradle.kts index 3ad2888b..2906c67f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -66,4 +66,5 @@ tasks.register("run") { springBoot { mainClass = "dev.usbharu.hideout.SpringApplicationKt" -} \ No newline at end of file +} + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..78204d19 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: "3" + +services: + db: + image: postgres:16 + ports: + - "5432:5432" + environment: + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: "password" + POSTGRES_DB: "hideout" \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/Subscriber.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/Subscriber.kt new file mode 100644 index 00000000..4a430bea --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/Subscriber.kt @@ -0,0 +1,4 @@ +package dev.usbharu.hideout.core.application.domainevent.subscribers + +interface Subscriber { +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/SubscriberRunner.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/SubscriberRunner.kt new file mode 100644 index 00000000..14b51199 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/SubscriberRunner.kt @@ -0,0 +1,12 @@ +package dev.usbharu.hideout.core.application.domainevent.subscribers + +import org.springframework.boot.ApplicationArguments +import org.springframework.boot.ApplicationRunner +import org.springframework.stereotype.Component + +@Component +class SubscriberRunner(subscribers:List) : ApplicationRunner { + override fun run(args: ApplicationArguments?) { + + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/TimelinePostCreateSubscriber.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/TimelinePostCreateSubscriber.kt index e6d7ba41..08555477 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/TimelinePostCreateSubscriber.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/TimelinePostCreateSubscriber.kt @@ -2,16 +2,23 @@ package dev.usbharu.hideout.core.application.domainevent.subscribers import dev.usbharu.hideout.core.domain.event.post.PostEvent import dev.usbharu.hideout.core.domain.event.post.PostEventBody +import org.slf4j.LoggerFactory +import org.springframework.context.annotation.Scope import org.springframework.stereotype.Component @Component -class TimelinePostCreateSubscriber(domainEventSubscriber: DomainEventSubscriber) { +class TimelinePostCreateSubscriber(domainEventSubscriber: DomainEventSubscriber) :Subscriber{ init { domainEventSubscriber.subscribe(PostEvent.CREATE.eventName) { val post = it.body.getPost() val actor = it.body.getActor() - println(post.toString()) + logger.info("New Post! : {}",post) + } } + + companion object{ + private val logger = LoggerFactory.getLogger(TimelinePostCreateSubscriber::class.java) + } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt index 389aa714..d48b557e 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt @@ -244,6 +244,30 @@ class Post( ) } + override fun toString(): String { + return "Post(" + + "id=$id, " + + "createdAt=$createdAt, " + + "url=$url, " + + "repostId=$repostId, " + + "replyId=$replyId, " + + "apId=$apId, " + + "actorId=$actorId, " + + "visibility=$visibility, " + + "visibleActors=$visibleActors, " + + "content=$content, " + + "overview=$overview, " + + "sensitive=$sensitive, " + + "text='$text', " + + "emojiIds=$emojiIds, " + + "mediaIds=$mediaIds, " + + "deleted=$deleted, " + + "hide=$hide, " + + "moveTo=$moveTo" + + ")" + } + + companion object { @Suppress("LongParameterList") fun create( diff --git a/hideout-core/src/main/resources/application.yml b/hideout-core/src/main/resources/application.yml index 55cec25b..d2726451 100644 --- a/hideout-core/src/main/resources/application.yml +++ b/hideout-core/src/main/resources/application.yml @@ -24,9 +24,9 @@ spring: default-property-inclusion: always datasource: driver-class-name: org.postgresql.Driver - url: "jdbc:postgresql:hideout3" + url: "jdbc:postgresql:hideout" username: "postgres" - password: "" + password: "password" data: mongodb: auto-index-creation: true diff --git a/hideout-core/src/main/resources/db/migration/V1__Init_DB.sql b/hideout-core/src/main/resources/db/migration/V1__Init_DB.sql index fdc8afea..b4aa135f 100644 --- a/hideout-core/src/main/resources/db/migration/V1__Init_DB.sql +++ b/hideout-core/src/main/resources/db/migration/V1__Init_DB.sql @@ -56,6 +56,8 @@ create table if not exists actors move_to bigint null default null, emojis varchar(3000) not null default '', deleted boolean not null default false, + icon bigint null, + banner bigint null, unique ("name", "domain"), constraint fk_actors_instance__id foreign key ("instance") references instance (id) on delete restrict on update restrict, constraint fk_actors_actors__move_to foreign key ("move_to") references actors (id) on delete restrict on update restrict @@ -91,6 +93,13 @@ create table if not exists media mime_type varchar(255) not null, description varchar(4000) null ); + +alter table actors + add constraint fk_actors_media__icon foreign key ("icon") references media (id) on delete cascade on update cascade; +alter table actors + add constraint fk_actors_media__banner foreign key ("banner") references media (id) on delete cascade on update cascade; + + create table if not exists posts ( id bigint primary key, diff --git a/hideout-core/src/main/resources/log4j2.xml b/hideout-core/src/main/resources/log4j2.xml index 195006c3..4a2ec926 100644 --- a/hideout-core/src/main/resources/log4j2.xml +++ b/hideout-core/src/main/resources/log4j2.xml @@ -6,7 +6,7 @@ - + diff --git a/hideout-mastodon/build.gradle.kts b/hideout-mastodon/build.gradle.kts index 54fea879..dfc584a1 100644 --- a/hideout-mastodon/build.gradle.kts +++ b/hideout-mastodon/build.gradle.kts @@ -19,10 +19,18 @@ repositories { mavenCentral() } +configurations { + all { + exclude("org.springframework.boot", "spring-boot-starter-logging") + exclude("ch.qos.logback", "logback-classic") + } +} + dependencies { implementation("org.springframework.boot:spring-boot-starter-web") implementation("org.springframework.boot:spring-boot-starter-security") implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") + implementation("org.springframework.boot:spring-boot-starter-log4j2") implementation("dev.usbharu:hideout-core:0.0.1") @@ -67,3 +75,4 @@ sourceSets.main { "$buildDir/generated/sources/mastodon/src/main/kotlin" ) } + diff --git a/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/ExposedStatusQueryService.kt b/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/ExposedStatusQueryService.kt index 09265d67..98a8a4c4 100644 --- a/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/ExposedStatusQueryService.kt +++ b/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/ExposedStatusQueryService.kt @@ -28,6 +28,7 @@ import dev.usbharu.hideout.mastodon.query.StatusQuery import dev.usbharu.hideout.mastodon.query.StatusQueryService import org.jetbrains.exposed.sql.ResultRow import org.jetbrains.exposed.sql.andWhere +import org.jetbrains.exposed.sql.leftJoin import org.jetbrains.exposed.sql.selectAll import org.springframework.stereotype.Repository import java.net.URI @@ -120,7 +121,7 @@ class StatusQueryServiceImpl : StatusQueryService { val map = Posts .leftJoin(PostsMedia) .leftJoin(Actors) - .leftJoin(Media) + .leftJoin(Media,{PostsMedia.mediaId},{Media.id}) .selectAll() .where { Posts.id eq id } .groupBy { it[Posts.id] }