Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Proposal: Standardize file names to the format <verb><Domain>[Context] #250

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 37 additions & 33 deletions pkg/accounts/adaptor/controller/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { Option, Result } from '@mikuroxina/mini-fn';

import type { ID } from '../../../id/type.js';
import { type AccountID, type AccountName } from '../../model/account.js';
import type { TokenVerifyService } from '../../service/accountVerifyToken.js';
import type { AuthenticationService } from '../../service/authenticate.js';
import type { AuthenticateAccountService } from '../../service/authenticateAccount.js';
import type { EditAccountService } from '../../service/editAccount.js';
import type { FetchAccountService } from '../../service/fetchAccount.js';
import type { FollowService } from '../../service/follow.js';
import type { FreezeService } from '../../service/freeze.js';
import type { RegisterAccountService } from '../../service/register.js';
import type { FollowAccountService } from '../../service/followAccount.js';
import type { FreezeAccountService } from '../../service/freezeAccount.js';
import type { RegisterAccountService } from '../../service/registerAccount.js';
import type { ResendVerifyTokenService } from '../../service/resendToken.js';
import type { SilenceService } from '../../service/silence.js';
import { type UnfollowService } from '../../service/unfollow.js';
import type { SilenceAccountService } from '../../service/silenceAccount.js';
import { type UnfollowAccountService } from '../../service/unfollowAccount.js';
import type { VerifyAccountTokenService } from '../../service/verifyAccountToken.js';
import {
type CreateAccountResponseSchema,
type GetAccountResponseSchema,
Expand All @@ -24,35 +24,35 @@ export class AccountController {
private readonly registerAccountService: RegisterAccountService;
private readonly editAccountService: EditAccountService;
private readonly fetchAccountService: FetchAccountService;
private readonly freezeService: FreezeService;
private readonly tokenVerifyService: TokenVerifyService;
private readonly authenticationService: AuthenticationService;
private readonly silenceService: SilenceService;
private readonly followService: FollowService;
private readonly unFollowService: UnfollowService;
private readonly freezeAccountService: FreezeAccountService;
private readonly verifyAccountTokenService: VerifyAccountTokenService;
private readonly authenticateAccountService: AuthenticateAccountService;
private readonly silenceAccountService: SilenceAccountService;
private readonly followAccountService: FollowAccountService;
private readonly unfollowAccountService: UnfollowAccountService;
private readonly resendTokenService: ResendVerifyTokenService;

constructor(args: {
registerAccountService: RegisterAccountService;
editAccountService: EditAccountService;
fetchAccountService: FetchAccountService;
freezeService: FreezeService;
tokenVerifyService: TokenVerifyService;
authenticationService: AuthenticationService;
silenceService: SilenceService;
followService: FollowService;
unFollowService: UnfollowService;
freezeAccountService: FreezeAccountService;
verifyAccountTokenService: VerifyAccountTokenService;
authenticateAccountService: AuthenticateAccountService;
silenceAccountService: SilenceAccountService;
followAccountService: FollowAccountService;
unfollowAccountService: UnfollowAccountService;
resendTokenService: ResendVerifyTokenService;
}) {
this.registerAccountService = args.registerAccountService;
this.editAccountService = args.editAccountService;
this.fetchAccountService = args.fetchAccountService;
this.freezeService = args.freezeService;
this.tokenVerifyService = args.tokenVerifyService;
this.authenticationService = args.authenticationService;
this.silenceService = args.silenceService;
this.followService = args.followService;
this.unFollowService = args.unFollowService;
this.freezeAccountService = args.freezeAccountService;
this.verifyAccountTokenService = args.verifyAccountTokenService;
this.authenticateAccountService = args.authenticateAccountService;
this.silenceAccountService = args.silenceAccountService;
this.followAccountService = args.followAccountService;
this.unfollowAccountService = args.unfollowAccountService;
this.resendTokenService = args.resendTokenService;
}

Expand Down Expand Up @@ -152,7 +152,7 @@ export class AccountController {
}

async freezeAccount(name: string): Promise<Result.Result<Error, void>> {
const res = await this.freezeService.setFreeze(name as AccountName);
const res = await this.freezeAccountService.setFreeze(name as AccountName);
if (Result.isErr(res)) {
return res;
}
Expand All @@ -161,7 +161,7 @@ export class AccountController {
}

async unFreezeAccount(name: string): Promise<Result.Result<Error, void>> {
const res = await this.freezeService.undoFreeze(name as AccountName);
const res = await this.freezeAccountService.undoFreeze(name as AccountName);
if (Result.isErr(res)) {
return res;
}
Expand All @@ -173,7 +173,7 @@ export class AccountController {
name: string,
token: string,
): Promise<Result.Result<Error, void>> {
const res = await this.tokenVerifyService.verify(
const res = await this.verifyAccountTokenService.verify(
name as AccountName,
token,
);
Expand Down Expand Up @@ -249,7 +249,7 @@ export class AccountController {
passphrase: string,
): Promise<Result.Result<Error, z.infer<typeof LoginResponseSchema>>> {
// ToDo: Check Captcha token
const res = await this.authenticationService.handle(
const res = await this.authenticateAccountService.handle(
name as AccountName,
passphrase,
);
Expand All @@ -265,7 +265,9 @@ export class AccountController {

async silenceAccount(name: string): Promise<Result.Result<Error, void>> {
// ToDo: check user's permission
const res = await this.silenceService.setSilence(name as AccountName);
const res = await this.silenceAccountService.setSilence(
name as AccountName,
);
if (Result.isErr(res)) {
return res;
}
Expand All @@ -275,7 +277,9 @@ export class AccountController {

async unSilenceAccount(name: string): Promise<Result.Result<Error, void>> {
// ToDo: check user's permission
const res = await this.silenceService.undoSilence(name as AccountName);
const res = await this.silenceAccountService.undoSilence(
name as AccountName,
);
if (Result.isErr(res)) {
return res;
}
Expand All @@ -285,7 +289,7 @@ export class AccountController {

async followAccount(name: string): Promise<Result.Result<Error, void>> {
// ToDo: get following account's name from request
const res = await this.followService.handle(
const res = await this.followAccountService.handle(
'' as AccountName,
name as AccountName,
);
Expand All @@ -297,7 +301,7 @@ export class AccountController {
}

async unFollowAccount(name: string): Promise<Result.Result<Error, void>> {
const res = await this.unFollowService.handle(
const res = await this.unfollowAccountService.handle(
name as AccountName,
'' as AccountName,
);
Expand Down
2 changes: 1 addition & 1 deletion pkg/accounts/adaptor/repository/dummy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Option, Result } from '@mikuroxina/mini-fn';

import { type ID } from '../../../id/type.js';
import { type Account, type AccountID } from '../../model/account.js';
import { type AccountFollow } from '../../model/follow.js';
import { type AccountFollow } from '../../model/followAccount.js';
import type { InactiveAccount } from '../../model/inactiveAccount.js';
import type {
AccountFollowRepository,
Expand Down
2 changes: 1 addition & 1 deletion pkg/accounts/adaptor/repository/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
type AccountSilenced,
type AccountStatus,
} from '../../model/account.js';
import { AccountFollow } from '../../model/follow.js';
import { AccountFollow } from '../../model/followAccount.js';
import type {
AccountFollowRepository,
AccountRepository,
Expand Down
33 changes: 18 additions & 15 deletions pkg/accounts/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ import {
UpdateAccountRoute,
VerifyEmailRoute,
} from './router.js';
import { TokenVerifyService } from './service/accountVerifyToken.js';
import { AuthenticationService } from './service/authenticate.js';
import { AuthenticateAccountService } from './service/authenticateAccount.js';
import { EditAccountService } from './service/editAccount.js';
import { EtagVerifyService } from './service/etagGenerateVerify.js';
import { FetchAccountService } from './service/fetchAccount.js';
import { FollowService } from './service/follow.js';
import { FreezeService } from './service/freeze.js';
import { RegisterAccountService } from './service/register.js';
import { FollowAccountService } from './service/followAccount.js';
import { FreezeAccountService } from './service/freezeAccount.js';
import { RegisterAccountService } from './service/registerAccount.js';
import { ResendVerifyTokenService } from './service/resendToken.js';
import { DummySendNotificationService } from './service/sendNotification.js';
import { SilenceService } from './service/silence.js';
import { SilenceAccountService } from './service/silenceAccount.js';
import { TokenGenerator } from './service/tokenGenerator.js';
import { UnfollowService } from './service/unfollow.js';
import { UnfollowAccountService } from './service/unfollowAccount.js';
import { VerifyAccountTokenService } from './service/verifyAccountToken.js';

export const accounts = new OpenAPIHono();
const accountRepository = new InMemoryAccountRepository();
Expand All @@ -53,7 +53,7 @@ const idGenerator = new SnowflakeIDGenerator(0, new Clock());
const passwordEncoder = new Argon2idPasswordEncoder();

export const controller = new AccountController({
authenticationService: new AuthenticationService({
authenticateAccountService: new AuthenticateAccountService({
accountRepository: accountRepository,
tokenGenerator: tokenGenerator,
passwordEncoder: passwordEncoder,
Expand All @@ -64,32 +64,35 @@ export const controller = new AccountController({
passwordEncoder,
),
fetchAccountService: new FetchAccountService(accountRepository),
followService: new FollowService(accountFollowRepository, accountRepository),
freezeService: new FreezeService(accountRepository),
followAccountService: new FollowAccountService(
accountFollowRepository,
accountRepository,
),
freezeAccountService: new FreezeAccountService(accountRepository),
registerAccountService: new RegisterAccountService({
repository: accountRepository,
idGenerator: idGenerator,
passwordEncoder: passwordEncoder,
sendNotification: new DummySendNotificationService(),
verifyTokenService: new TokenVerifyService(
verifyAccountTokenService: new VerifyAccountTokenService(
accountVerifyTokenRepository,
accountRepository,
new Clock(),
),
}),
silenceService: new SilenceService(accountRepository),
tokenVerifyService: new TokenVerifyService(
silenceAccountService: new SilenceAccountService(accountRepository),
verifyAccountTokenService: new VerifyAccountTokenService(
accountVerifyTokenRepository,
accountRepository,
new Clock(),
),
unFollowService: new UnfollowService(
unfollowAccountService: new UnfollowAccountService(
accountFollowRepository,
accountRepository,
),
resendTokenService: new ResendVerifyTokenService(
accountRepository,
new TokenVerifyService(
new VerifyAccountTokenService(
accountVerifyTokenRepository,
accountRepository,
new Clock(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { describe, expect, it } from 'vitest';

import type { ID } from '../../id/type.js';
import type { AccountID } from './account.js';
import { AccountFollow, type CreateAccountFollowArgs } from './follow.js';
import {
AccountFollow,
type CreateAccountFollowArgs,
} from './followAccount.js';

describe('AccountFollow', () => {
it('generate new instance', () => {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion pkg/accounts/model/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Option, Result } from '@mikuroxina/mini-fn';
import { type ID } from '../../id/type.js';
import type { Account } from './account.js';
import { type AccountID } from './account.js';
import type { AccountFollow } from './follow.js';
import type { AccountFollow } from './followAccount.js';
import type { InactiveAccount } from './inactiveAccount.js';

export interface AccountRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { ID } from '../../id/type.js';
import { Argon2idPasswordEncoder } from '../../password/mod.js';
import { InMemoryAccountRepository } from '../adaptor/repository/dummy.js';
import { Account } from '../model/account.js';
import { AuthenticationService } from './authenticate.js';
import { AuthenticateAccountService } from './authenticateAccount.js';
import { TokenGenerator } from './tokenGenerator.js';

describe('AuthenticationService', () => {
Expand Down Expand Up @@ -35,7 +35,7 @@ describe('AuthenticationService', () => {

const tokenGenerator = await TokenGenerator.new();

const service = new AuthenticationService({
const service = new AuthenticateAccountService({
accountRepository: accountRepository,
tokenGenerator: tokenGenerator,
passwordEncoder: encoder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface TokenPair {
refreshToken: string;
}

export class AuthenticationService {
export class AuthenticateAccountService {
private readonly accountRepository: AccountRepository;
private readonly tokenGenerator: TokenGenerator;
private readonly passwordEncoder: PasswordEncoder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
InMemoryAccountRepository,
} from '../adaptor/repository/dummy.js';
import { Account, type AccountID } from '../model/account.js';
import { FollowService } from './follow.js';
import { FollowAccountService } from './followAccount.js';

const accountRepository = new InMemoryAccountRepository();
await accountRepository.create(
Expand Down Expand Up @@ -45,7 +45,7 @@ await accountRepository.create(
}),
);
const repository = new InMemoryAccountFollowRepository();
const service = new FollowService(repository, accountRepository);
const service = new FollowAccountService(repository, accountRepository);

describe('FollowService', () => {
it('should follow', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Option, Result } from '@mikuroxina/mini-fn';

import type { AccountName } from '../model/account.js';
import { AccountFollow } from '../model/follow.js';
import { AccountFollow } from '../model/followAccount.js';
import type {
AccountFollowRepository,
AccountRepository,
} from '../model/repository.js';

export class FollowService {
export class FollowAccountService {
constructor(
private readonly followRepository: AccountFollowRepository,
private readonly accountRepository: AccountRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { afterEach, describe, expect, it } from 'vitest';
import type { ID } from '../../id/type.js';
import { InMemoryAccountRepository } from '../adaptor/repository/dummy.js';
import { Account, type AccountID } from '../model/account.js';
import { FreezeService } from './freeze.js';
import { FreezeAccountService } from './freezeAccount.js';

const repository = new InMemoryAccountRepository();
await repository.create(
Expand All @@ -22,7 +22,7 @@ await repository.create(
createdAt: new Date(),
}),
);
const freezeService = new FreezeService(repository);
const freezeService = new FreezeAccountService(repository);

describe('FreezeService', () => {
afterEach(() => repository.reset());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Option, Result } from '@mikuroxina/mini-fn';
import type { AccountName } from '../model/account.js';
import { type AccountRepository } from '../model/repository.js';

export class FreezeService {
export class FreezeAccountService {
private readonly accountRepository: AccountRepository;

constructor(accountRepository: AccountRepository) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
InMemoryAccountVerifyTokenRepository,
} from '../adaptor/repository/dummy.js';
import { type AccountName, type AccountRole } from '../model/account.js';
import { TokenVerifyService } from './accountVerifyToken.js';
import { RegisterAccountService } from './register.js';
import { RegisterAccountService } from './registerAccount.js';
import { DummySendNotificationService } from './sendNotification.js';
import { VerifyAccountTokenService } from './verifyAccountToken.js';

const repository = new InMemoryAccountRepository();
const verifyRepository = new InMemoryAccountVerifyTokenRepository();
Expand All @@ -21,7 +21,7 @@ const registerService: RegisterAccountService = new RegisterAccountService({
idGenerator: new SnowflakeIDGenerator(1, mockClock),
passwordEncoder: new Argon2idPasswordEncoder(),
sendNotification: new DummySendNotificationService(),
verifyTokenService: new TokenVerifyService(
verifyAccountTokenService: new VerifyAccountTokenService(
verifyRepository,
repository,
mockClock,
Expand Down
Loading
Loading