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 3 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
60 changes: 32 additions & 28 deletions pkg/accounts/adaptor/controller/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ 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 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 freezeAccountService: FreezeAccountService;
private readonly tokenVerifyService: TokenVerifyService;
private readonly authenticationService: AuthenticationService;
private readonly silenceService: SilenceService;
private readonly followService: FollowService;
private readonly unFollowService: UnfollowService;
private readonly authenticateAccountService: AuthenticateAccountService;
private readonly silenceAccountService: SilenceAccountService;
private readonly followAccountService: FollowAccountService;
private readonly unFollowAccountService: UnfollowAccountService;
Allianaab2m marked this conversation as resolved.
Show resolved Hide resolved
private readonly resendTokenService: ResendVerifyTokenService;

constructor(args: {
registerAccountService: RegisterAccountService;
editAccountService: EditAccountService;
fetchAccountService: FetchAccountService;
freezeService: FreezeService;
freezeAccountService: FreezeAccountService;
tokenVerifyService: TokenVerifyService;
authenticationService: AuthenticationService;
silenceService: SilenceService;
followService: FollowService;
unFollowService: UnfollowService;
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.freezeAccountService = args.freezeAccountService;
this.tokenVerifyService = args.tokenVerifyService;
this.authenticationService = args.authenticationService;
this.silenceService = args.silenceService;
this.followService = args.followService;
this.unFollowService = args.unFollowService;
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 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
25 changes: 14 additions & 11 deletions pkg/accounts/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ import {
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';

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,8 +64,11 @@ 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,
Expand All @@ -77,13 +80,13 @@ export const controller = new AccountController({
new Clock(),
),
}),
silenceService: new SilenceService(accountRepository),
silenceAccountService: new SilenceAccountService(accountRepository),
tokenVerifyService: new TokenVerifyService(
accountVerifyTokenRepository,
accountRepository,
new Clock(),
),
unFollowService: new UnfollowService(
unFollowAccountService: new UnfollowAccountService(
Allianaab2m marked this conversation as resolved.
Show resolved Hide resolved
accountFollowRepository,
accountRepository,
),
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

モデル名が AccountFollow なので accountFollow になると思います. ただ, follow を名詞的に扱って良いのか少し疑問です. その場合は, モデル名の命名の問題になります.

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 @@ -9,7 +9,7 @@ import {
} 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';

const repository = new InMemoryAccountRepository();
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 { SilenceService } from './silence.js';
import { SilenceAccountService } from './silenceAccount.js';

const repository = new InMemoryAccountRepository();
await repository.create(
Expand All @@ -22,7 +22,7 @@ await repository.create(
createdAt: new Date(),
}),
);
const silenceService = new SilenceService(repository);
const silenceService = new SilenceAccountService(repository);

describe('SilenceService', () => {
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 SilenceService {
export class SilenceAccountService {
private readonly accountRepository: AccountRepository;

constructor(accountRepository: AccountRepository) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
InMemoryAccountRepository,
} from '../adaptor/repository/dummy.js';
import { Account, type AccountID } from '../model/account.js';
import { AccountFollow } from '../model/follow.js';
import { UnfollowService } from './unfollow.js';
import { AccountFollow } from '../model/followAccount.js';
import { UnfollowAccountService } from './unfollowAccount.js';

const accountRepository = new InMemoryAccountRepository();
await accountRepository.create(
Expand Down Expand Up @@ -52,7 +52,7 @@ const repository = new InMemoryAccountFollowRepository([
createdAt: new Date(),
}),
]);
const service = new UnfollowService(repository, accountRepository);
const service = new UnfollowAccountService(repository, accountRepository);

describe('UnfollowService', () => {
it('should unfollow', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
AccountRepository,
} from '../model/repository.js';

export class UnfollowService {
export class UnfollowAccountService {
constructor(
private readonly followRepository: AccountFollowRepository,
private readonly accountRepository: AccountRepository,
Expand Down
Loading
Loading