Skip to content

Commit

Permalink
feat:試合表の生成後のエントリーを受け付けない
Browse files Browse the repository at this point in the history
  • Loading branch information
speak-mentaiko committed Oct 21, 2024
1 parent f8dbf35 commit a66d883
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
15 changes: 14 additions & 1 deletion packages/kcms/src/team/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ import { TeamID } from './models/team.js';

import { apiReference } from '@scalar/hono-api-reference';
import { SnowflakeIDGenerator } from '../id/main';
import { DummyMainMatchRepository } from '../match/adaptor/dummy/mainMatchRepository';
import { DummyPreMatchRepository } from '../match/adaptor/dummy/preMatchRepository';
import { PrismaMainMatchRepository } from '../match/adaptor/prisma/mainMatchRepository';
import { PrismaPreMatchRepository } from '../match/adaptor/prisma/preMatchRepository';
import { GetMatchService } from '../match/service/get';
import { CreateTeamService } from './service/createTeam';
import { DeleteTeamService } from './service/delete';
import { EntryService } from './service/entry';
Expand All @@ -29,12 +34,20 @@ const isProduction = process.env.NODE_ENV === 'production';
const teamRepository = isProduction
? new PrismaTeamRepository(prismaClient)
: new DummyRepository();
const preMatchRepository = isProduction
? new PrismaPreMatchRepository(prismaClient)
: new DummyPreMatchRepository();
const mainMatchRepository = isProduction
? new PrismaMainMatchRepository(prismaClient)
: new DummyMainMatchRepository();
const idGenerator = new SnowflakeIDGenerator(1, () => BigInt(new Date().getTime()));

const getMatchService = new GetMatchService(preMatchRepository, mainMatchRepository);

const fetchTeamService = new FetchTeamService(teamRepository);
const createTeamService = new CreateTeamService(teamRepository, idGenerator);
const deleteTeamService = new DeleteTeamService(teamRepository);
const entryService = new EntryService(teamRepository);
const entryService = new EntryService(teamRepository, getMatchService);

export const controller = new TeamController(
createTeamService,
Expand Down
16 changes: 15 additions & 1 deletion packages/kcms/src/team/service/entry.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Option, Result } from '@mikuroxina/mini-fn';
import { GetMatchService } from '../../match/service/get';
import { TeamRepository } from '../models/repository';
import { Team, TeamID } from '../models/team';

/**
* 当日参加を行うService
*/
export class EntryService {
constructor(private readonly teamRepository: TeamRepository) {}
constructor(
private readonly teamRepository: TeamRepository,
private readonly PreMatch: GetMatchService
) {}

/**
* チームの出欠を登録します
Expand All @@ -15,6 +19,11 @@ export class EntryService {
*/
async enter(teamID: TeamID): Promise<Result.Result<Error, Team>> {
const teamRes = await this.teamRepository.findByID(teamID);
const matchRes = await this.PreMatch.findAllPreMatch();

if (!Result.isErr(matchRes)) {
return Result.err(new Error('Cannot enter now'));
}
if (Option.isNone(teamRes)) {
return Result.err(new Error('Team not found'));
}
Expand All @@ -35,6 +44,11 @@ export class EntryService {
*/
async cancel(teamID: TeamID): Promise<Result.Result<Error, Team>> {
const teamRes = await this.teamRepository.findByID(teamID);
const matchRes = await this.PreMatch.findAllPreMatch();

if (!Result.isErr(matchRes)) {
return Result.err(new Error('Cannot enter now'));
}
if (Option.isNone(teamRes)) {
return Result.err(new Error('Team not found'));
}
Expand Down

0 comments on commit a66d883

Please sign in to comment.