From 76cd8614d0b6db902bd360b255435e8b65dc0b4a Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sun, 10 Dec 2023 16:20:29 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=E3=83=86=E3=83=BC=E3=83=96?= =?UTF-8?q?=E3=83=AB=E5=AE=9A=E7=BE=A9=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hideout/core/domain/model/block/Block.kt | 12 ----- .../domain/model/block/BlockRepository.kt | 31 ----------- .../exposedrepository/BlockRepositoryImpl.kt | 53 ------------------- .../resources/db/migration/V1__Init_DB.sql | 33 ++++++------ .../resources/db/migration/V2__Add_Block.sql | 8 --- 5 files changed, 17 insertions(+), 120 deletions(-) delete mode 100644 src/main/kotlin/dev/usbharu/hideout/core/domain/model/block/Block.kt delete mode 100644 src/main/kotlin/dev/usbharu/hideout/core/domain/model/block/BlockRepository.kt delete mode 100644 src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/BlockRepositoryImpl.kt delete mode 100644 src/main/resources/db/migration/V2__Add_Block.sql diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/block/Block.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/block/Block.kt deleted file mode 100644 index 7435183e..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/block/Block.kt +++ /dev/null @@ -1,12 +0,0 @@ -package dev.usbharu.hideout.core.domain.model.block - -/** - * ブロック関係を表します - * - * @property userId ブロックの動作を行ったユーザーid - * @property target ブロックの対象のユーザーid - */ -data class Block( - val userId: Long, - val target: Long -) diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/block/BlockRepository.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/block/BlockRepository.kt deleted file mode 100644 index 3504ffea..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/block/BlockRepository.kt +++ /dev/null @@ -1,31 +0,0 @@ -package dev.usbharu.hideout.core.domain.model.block - -/** - * ブロックの状態を永続化します - * - */ -interface BlockRepository { - /** - * ブロックの状態を永続化します - * - * @param block 永続化するブロック - * @return 永続化されたブロック - */ - suspend fun save(block: Block): Block - - /** - * ブロックの状態を削除します - * - * @param block 削除する永続化されたブロック - */ - suspend fun delete(block: Block) - - /** - * - * - * @param userId - * @param target - * @return - */ - suspend fun findByUserIdAndTarget(userId: Long, target: Long): Block -} diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/BlockRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/BlockRepositoryImpl.kt deleted file mode 100644 index c3d60ea9..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/BlockRepositoryImpl.kt +++ /dev/null @@ -1,53 +0,0 @@ -package dev.usbharu.hideout.core.infrastructure.exposedrepository - -import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException -import dev.usbharu.hideout.core.domain.model.block.Block -import dev.usbharu.hideout.core.domain.model.block.BlockRepository -import dev.usbharu.hideout.util.singleOr -import org.jetbrains.exposed.dao.id.LongIdTable -import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq -import org.jetbrains.exposed.sql.and -import org.jetbrains.exposed.sql.deleteWhere -import org.jetbrains.exposed.sql.insert -import org.jetbrains.exposed.sql.select -import org.springframework.stereotype.Repository - -@Repository -class BlockRepositoryImpl : BlockRepository { - override suspend fun save(block: Block): Block { - Blocks.insert { - it[userId] = block.userId - it[target] = block.target - } - return block - } - - override suspend fun delete(block: Block) { - Blocks.deleteWhere { Blocks.userId eq block.userId and (Blocks.target eq block.target) } - } - - override suspend fun findByUserIdAndTarget(userId: Long, target: Long): Block { - val singleOr = Blocks - .select { Blocks.userId eq userId and (Blocks.target eq target) } - .singleOr { - FailedToGetResourcesException( - "userId: $userId target: $target is duplicate or not exist.", - it - ) - } - - return Block( - singleOr[Blocks.userId], - singleOr[Blocks.target] - ) - } -} - -object Blocks : LongIdTable("blocks") { - val userId = long("user_id").references(Users.id).index() - val target = long("target").references(Users.id) - - init { - uniqueIndex(userId, target) - } -} diff --git a/src/main/resources/db/migration/V1__Init_DB.sql b/src/main/resources/db/migration/V1__Init_DB.sql index 1440fb61..234078e7 100644 --- a/src/main/resources/db/migration/V1__Init_DB.sql +++ b/src/main/resources/db/migration/V1__Init_DB.sql @@ -34,14 +34,7 @@ create table if not exists users unique ("name", "domain"), constraint fk_users_instance__id foreign key ("instance") references instance (id) on delete restrict on update restrict ); -create table if not exists follow_requests -( - id bigserial primary key, - user_id bigint not null, - follower_id bigint not null, - constraint fk_follow_requests_user_id__id foreign key (user_id) references users (id) on delete restrict on update restrict, - constraint fk_follow_requests_follower_id__id foreign key (follower_id) references users (id) on delete restrict on update restrict -); + create table if not exists media ( id bigint primary key, @@ -119,14 +112,7 @@ create table if not exists timelines is_pure_repost boolean not null, media_ids varchar(255) not null ); -create table if not exists users_followers -( - id bigserial primary key, - user_id bigint not null, - follower_id bigint not null, - constraint fk_users_followers_user_id__id foreign key (user_id) references users (id) on delete restrict on update restrict, - constraint fk_users_followers_follower_id__id foreign key (follower_id) references users (id) on delete restrict on update restrict -); + create table if not exists application_authorization ( id varchar(255) primary key, @@ -186,4 +172,19 @@ create table if not exists registered_client scopes varchar(1000) not null, client_settings varchar(2000) not null, token_settings varchar(2000) not null +); + +create table if not exists relationships +( + id bigserial primary key, + user_id bigint not null, + target_user_id bigint not null, + following boolean not null, + blocking boolean not null, + muting boolean not null, + follow_request boolean not null, + ignore_follow_request boolean not null, + constraint fk_relationships_user_id__id foreign key (user_id) references users (id) on delete restrict on update restrict, + constraint fk_relationships_target_user_id__id foreign key (target_user_id) references users (id) on delete restrict on update restrict, + unique (user_id, target_user_id) ) diff --git a/src/main/resources/db/migration/V2__Add_Block.sql b/src/main/resources/db/migration/V2__Add_Block.sql deleted file mode 100644 index d82d705e..00000000 --- a/src/main/resources/db/migration/V2__Add_Block.sql +++ /dev/null @@ -1,8 +0,0 @@ -create table if not exists blocks -( - id bigserial primary key, - user_id bigint not null, - target bigint not null, - constraint fk_blocks_user_id__id foreign key (user_id) references users (id) on delete restrict on update restrict, - constraint fk_blocks_target_id__id foreign key (target) references users (id) on delete restrict on update restrict -);