refactor: テーブル定義を修正

This commit is contained in:
usbharu 2023-12-10 16:20:29 +09:00
parent d2faa7f204
commit ed7b3e8c65
5 changed files with 17 additions and 120 deletions

View File

@ -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
)

View File

@ -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
}

View File

@ -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)
}
}

View File

@ -34,14 +34,7 @@ create table if not exists users
unique ("name", "domain"), unique ("name", "domain"),
constraint fk_users_instance__id foreign key ("instance") references instance (id) on delete restrict on update restrict 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 create table if not exists media
( (
id bigint primary key, id bigint primary key,
@ -119,14 +112,7 @@ create table if not exists timelines
is_pure_repost boolean not null, is_pure_repost boolean not null,
media_ids varchar(255) 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 create table if not exists application_authorization
( (
id varchar(255) primary key, id varchar(255) primary key,
@ -186,4 +172,19 @@ create table if not exists registered_client
scopes varchar(1000) not null, scopes varchar(1000) not null,
client_settings varchar(2000) not null, client_settings varchar(2000) not null,
token_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)
) )

View File

@ -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
);