Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into refactor/150-object-converter
Browse files Browse the repository at this point in the history
  • Loading branch information
laminne committed Aug 8, 2023
2 parents 6bb048e + 4647295 commit 164010e
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 84 deletions.
18 changes: 0 additions & 18 deletions .github/workflow/test.yml

This file was deleted.

17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# プルリクに対してテストを実行
name: run test
on:
pull_request:
paths-ignore:
- "**.md"

jobs:
run_test:
name: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: install packages
run: npm i
- name: test
run: npm test
22 changes: 17 additions & 5 deletions src/domain/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
40 changes: 36 additions & 4 deletions src/repository/prisma/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { InternalError } from "../../helpers/errors.js";
export class UserRepository implements IUserRepository {
private prisma: PrismaClient;

constructor(prisma: any) {
constructor(prisma: PrismaClient) {
this.prisma = prisma;
}

Expand Down Expand Up @@ -158,9 +158,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 ?? "",
Expand Down
10 changes: 9 additions & 1 deletion src/server/controller/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
77 changes: 21 additions & 56 deletions src/service/data/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,60 +157,20 @@ export function UserToUserData(v: User): UserData {
role: v.isAdmin ? 1 : 0,
following: v.following().map<UserFollowEventData>((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<UserFollowEventData>(),
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<UserFollowEventData>(),
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({
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}

0 comments on commit 164010e

Please sign in to comment.