-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: intermodule, use direct function calls
- Loading branch information
Showing
18 changed files
with
242 additions
and
170 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { Result } from '@mikuroxina/mini-fn'; | ||
import type { Account, AccountID } from '../../accounts/model/account.js'; | ||
import type { FetchService } from '../../accounts/service/fetch.js'; | ||
import type { FetchFollowService } from '../../accounts/service/fetchFollow.js'; | ||
import type { | ||
AccountModuleInterface, | ||
PartialAccount, | ||
} from '../interfaces/account.js'; | ||
|
||
export class AccountModule implements AccountModuleInterface { | ||
constructor( | ||
private readonly fetchService: FetchService, | ||
private readonly fetchFollowService: FetchFollowService, | ||
) {} | ||
|
||
async fetchAccount(id: AccountID): Promise<Result.Result<Error, Account>> { | ||
const res = await this.fetchService.fetchAccountByID(id); | ||
if (Result.isErr(res)) { | ||
return res; | ||
} | ||
|
||
return res; | ||
} | ||
|
||
async fetchFollowings( | ||
id: AccountID, | ||
): Promise<Result.Result<Error, PartialAccount[]>> { | ||
const res = await this.fetchFollowService.fetchFollowingsByID(id); | ||
if (Result.isErr(res)) { | ||
return res; | ||
} | ||
|
||
const accounts = await Promise.all( | ||
res[1].map((v) => this.fetchService.fetchAccountByID(v.getTargetID())), | ||
); | ||
|
||
return Result.ok( | ||
accounts | ||
.filter((v) => Result.isOk(v)) | ||
.map((v): PartialAccount => { | ||
return { | ||
id: v[1].getID(), | ||
name: v[1].getName(), | ||
nickname: v[1].getNickname(), | ||
bio: v[1].getBio(), | ||
}; | ||
}), | ||
); | ||
} | ||
|
||
async fetchFollowers( | ||
id: AccountID, | ||
): Promise<Result.Result<Error, PartialAccount[]>> { | ||
const res = await this.fetchFollowService.fetchFollowersByID(id); | ||
if (Result.isErr(res)) { | ||
return res; | ||
} | ||
|
||
const accounts = await Promise.all( | ||
res[1].map((v) => this.fetchService.fetchAccountByID(v.getFromID())), | ||
); | ||
|
||
return Result.ok( | ||
accounts | ||
.filter((v) => Result.isOk(v)) | ||
.map((v): PartialAccount => { | ||
return { | ||
id: v[1].getID(), | ||
name: v[1].getName(), | ||
nickname: v[1].getNickname(), | ||
bio: v[1].getBio(), | ||
}; | ||
}), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Result } from '@mikuroxina/mini-fn'; | ||
import type { Note } from '../../notes/model/note.js'; | ||
import type { PushTimelineService } from '../../timeline/service/push.js'; | ||
|
||
export class TimelineModule { | ||
constructor(private readonly pushTimelineService: PushTimelineService) {} | ||
|
||
/* | ||
* @description Push note to timeline | ||
* @param note to be pushed | ||
* */ | ||
async pushNoteToTimeline(note: Note): Promise<Result.Result<Error, void>> { | ||
const res = await this.pushTimelineService.handle(note); | ||
if (Result.isErr(res)) { | ||
return res; | ||
} | ||
|
||
return Result.ok(undefined); | ||
} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { Result } from '@mikuroxina/mini-fn'; | ||
import type { | ||
Account, | ||
AccountID, | ||
AccountName, | ||
} from '../../accounts/model/account.js'; | ||
|
||
export interface PartialAccount { | ||
id: AccountID; | ||
name: AccountName; | ||
nickname: string; | ||
bio: string; | ||
} | ||
|
||
export interface AccountModuleInterface { | ||
fetchAccount(id: AccountID): Promise<Result.Result<Error, Account>>; | ||
fetchFollowings( | ||
id: AccountID, | ||
): Promise<Result.Result<Error, PartialAccount[]>>; | ||
fetchFollowers( | ||
id: AccountID, | ||
): Promise<Result.Result<Error, PartialAccount[]>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { Result } from '@mikuroxina/mini-fn'; | ||
import type { Note } from '../../notes/model/note.js'; | ||
|
||
export interface TimelineModuleInterface { | ||
/* | ||
* @description Push note to timeline | ||
* @param note to be pushed | ||
* */ | ||
pushNoteToTimeline(note: Note): Promise<Result.Result<Error, void>>; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.