From c64019a9343c4d906d9f21dd6f776cbc836b6a33 Mon Sep 17 00:00:00 2001 From: Tatsuto YAMAMOTO Date: Tue, 8 Aug 2023 14:46:23 +0900 Subject: [PATCH 1/4] =?UTF-8?q?refactor(domain):=20follow=E3=82=AA?= =?UTF-8?q?=E3=83=96=E3=82=B8=E3=82=A7=E3=82=AF=E3=83=88=E3=82=92=E3=83=8D?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=81=97=E3=81=AA=E3=81=84=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E6=94=B9=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/user.ts | 22 +++++++--- src/repository/prisma/user.ts | 40 ++++++++++++++++-- src/server/controller/user.ts | 10 ++++- src/service/data/user.ts | 77 ++++++++++------------------------- 4 files changed, 83 insertions(+), 66 deletions(-) diff --git a/src/domain/user.ts b/src/domain/user.ts index 7ebb43e..241b103 100644 --- a/src/domain/user.ts +++ b/src/domain/user.ts @@ -248,21 +248,33 @@ export class UserAPData { } export class UserFollowEvent { + // ToDo: + // DTOなどへの変換時に再帰的に変換が行われる可能性がある + // ->必要なデータ: id,nickName, fullHandle, iconImageURL, bio + // フォローされたユーザー(dst) - private readonly _follower: User; + private readonly _follower: FollowUser; // フォローしたユーザー(from) - private readonly _following: User; + private readonly _following: FollowUser; - constructor(following: User, follower: User) { + constructor(following: FollowUser, follower: FollowUser) { this._follower = follower; this._following = following; } - get follower(): User { + get follower(): FollowUser { return this._follower; } - get following(): User { + get following(): FollowUser { return this._following; } } + +export interface FollowUser { + id: Snowflake; + nickName: string; + fullHandle: string; + iconImageURL: string; + bio: string; +} diff --git a/src/repository/prisma/user.ts b/src/repository/prisma/user.ts index b824b83..10243ba 100644 --- a/src/repository/prisma/user.ts +++ b/src/repository/prisma/user.ts @@ -8,7 +8,7 @@ import { PrismaErrorConverter } from "./error.js"; export class UserRepository implements IUserRepository { private prisma: PrismaClient; - constructor(prisma: any) { + constructor(prisma: PrismaClient) { this.prisma = prisma; } @@ -150,9 +150,41 @@ export class UserRepository implements IUserRepository { nickName: e.nickName, password: e.password, role: e.role, - following: e.following.map((v: any): UserFollowEvent => { - return new UserFollowEvent(v.following, v.follower); - }), + following: e.following.map( + (v: { + following: { + id: string; + fullHandle: string; + nickName: string; + iconImageURL: string; + bio: string; + }; + follower: { + id: string; + fullHandle: string; + nickName: string; + iconImageURL: string; + bio: string; + }; + }): UserFollowEvent => { + return new UserFollowEvent( + { + id: v.following.id as Snowflake, + bio: v.following.bio, + fullHandle: v.following.fullHandle, + iconImageURL: v.following.iconImageURL, + nickName: v.following.nickName, + }, + { + id: v.follower.id as Snowflake, + bio: v.follower.bio, + fullHandle: v.follower.fullHandle, + iconImageURL: v.follower.iconImageURL, + nickName: v.follower.nickName, + }, + ); + }, + ), apData: new UserAPData({ followersURL: e.userAPData.followersURL ?? "", followingURL: e.userAPData.followingURL ?? "", diff --git a/src/server/controller/user.ts b/src/server/controller/user.ts index a8517ae..f07c44c 100644 --- a/src/server/controller/user.ts +++ b/src/server/controller/user.ts @@ -50,7 +50,15 @@ export class UserController { bio: r.bio, headerImageURL: r.headerImageURL, iconImageURL: r.iconImageURL, - following: r.following, + following: r.following.map((v) => { + return { + id: v.following.id, + fullHandle: v.following.fullHandle, + nickName: v.following.nickName, + bio: v.following.bio, + iconImageURL: v.following.iconImageURL, + }; + }), softwareName: server.value.softwareName, }; return new Success(res); diff --git a/src/service/data/user.ts b/src/service/data/user.ts index 2a0f000..f69d67c 100644 --- a/src/service/data/user.ts +++ b/src/service/data/user.ts @@ -157,60 +157,20 @@ export function UserToUserData(v: User): UserData { role: v.isAdmin ? 1 : 0, following: v.following().map((e) => { return new UserFollowEventData( - new UserData({ - id: e.follower.id, - serverID: e.follower.serverID, - bio: e.follower.bio, - fullHandle: e.follower.fullHandle, - handle: e.follower.handle, - headerImageURL: e.follower.headerImageURL, - iconImageURL: e.follower.iconImageURL, - isLocalUser: e.follower.isLocalUser, - nickName: e.follower.nickName, - role: e.follower.isAdmin ? 1 : 0, - createdAt: e.follower.createdAt, - - // 以下のデータはフォロー関係を示すのには必要ないので空欄 - password: "", - following: new Array(), - apData: new UserAPDataData({ - userID: e.following.id, - userAPID: "", - followersURL: "", - followingURL: "", - inboxURL: "", - outboxURL: "", - privateKey: null, - publicKey: "", - }), - }), - new UserData({ + { id: e.following.id, - serverID: e.following.serverID, bio: e.following.bio, fullHandle: e.following.fullHandle, - handle: e.following.handle, - headerImageURL: e.following.headerImageURL, iconImageURL: e.following.iconImageURL, - isLocalUser: e.following.isLocalUser, nickName: e.following.nickName, - role: e.following.isAdmin ? 1 : 0, - createdAt: e.following.createdAt, - - // 以下のデータはフォロー関係を示すのには必要ないので空欄 - password: "", - following: new Array(), - apData: new UserAPDataData({ - userID: e.following.id, - userAPID: "", - followersURL: "", - followingURL: "", - inboxURL: "", - outboxURL: "", - privateKey: null, - publicKey: "", - }), - }), + }, + { + id: e.follower.id, + bio: e.follower.bio, + fullHandle: e.follower.fullHandle, + iconImageURL: e.follower.iconImageURL, + nickName: e.follower.nickName, + }, ); }), apData: new UserAPDataData({ @@ -322,11 +282,11 @@ export function UserAPDataToUserAPDataData(v: UserAPData) { export class UserFollowEventData { // フォローされたユーザー(dst) - private readonly _follower: UserData; + private readonly _follower: FollowUserData; // フォローしたユーザー(from) - private readonly _following: UserData; + private readonly _following: FollowUserData; - constructor(following: UserData, follower: UserData) { + constructor(following: FollowUserData, follower: FollowUserData) { this._follower = follower; this._following = following; } @@ -340,9 +300,14 @@ export class UserFollowEventData { } public toDomain(): UserFollowEvent { - return new UserFollowEvent( - this._following.toDomain(), - this._follower.toDomain(), - ); + return new UserFollowEvent(this._following, this._follower); } } + +export interface FollowUserData { + id: Snowflake; + nickName: string; + fullHandle: string; + iconImageURL: string; + bio: string; +} From 080d11cfdc661ae4ca5559d8036d627ac0e59e4e Mon Sep 17 00:00:00 2001 From: Tatsuto YAMAMOTO Date: Tue, 8 Aug 2023 15:33:55 +0900 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20CI=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflow/test.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflow/test.yml b/.github/workflow/test.yml index 99ac665..845bbcd 100644 --- a/.github/workflow/test.yml +++ b/.github/workflow/test.yml @@ -4,14 +4,12 @@ on: pull_request: jobs: - run_test: + test: name: test runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - - name: setup - uses: actions/setup-node@v3 + - uses: actions/setup-node@v3 - name: install run: npm ci - name: run test From 53ed661674e7aef9efb0656ba950d59be96977a7 Mon Sep 17 00:00:00 2001 From: Tatsuto YAMAMOTO Date: Tue, 8 Aug 2023 15:36:19 +0900 Subject: [PATCH 3/4] =?UTF-8?q?fix(ci):=20job=E5=90=8D=E3=82=92=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflow/test.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflow/test.yml b/.github/workflow/test.yml index 845bbcd..1bef25f 100644 --- a/.github/workflow/test.yml +++ b/.github/workflow/test.yml @@ -1,16 +1,17 @@ -name: Test - +# プルリクに対してテストを実行 +name: run test on: pull_request: + paths-ignore: + - "**.md" jobs: - test: + run_test: name: test runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - - name: install - run: npm ci - - name: run test + - name: install packages + run: npm i + - name: test run: npm test From 65ebc0a8bb931bdf09d5772338715ca680bc54c5 Mon Sep 17 00:00:00 2001 From: Tatsuto YAMAMOTO Date: Tue, 8 Aug 2023 15:37:51 +0900 Subject: [PATCH 4/4] =?UTF-8?q?chore:=20=E3=83=AF=E3=83=BC=E3=82=AF?= =?UTF-8?q?=E3=83=95=E3=83=AD=E3=83=BC=E3=81=AE=E3=83=87=E3=82=A3=E3=83=AC?= =?UTF-8?q?=E3=82=AF=E3=83=88=E3=83=AA=E3=82=92=E3=83=AA=E3=83=8D=E3=83=BC?= =?UTF-8?q?=E3=83=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/{workflow => workflows}/test.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{workflow => workflows}/test.yml (100%) diff --git a/.github/workflow/test.yml b/.github/workflows/test.yml similarity index 100% rename from .github/workflow/test.yml rename to .github/workflows/test.yml