Skip to content

Commit

Permalink
Participant のリポジトリをクエリサービスに変更
Browse files Browse the repository at this point in the history
  • Loading branch information
k-kbot committed Sep 3, 2023
1 parent ba5d7e7 commit a8a4e8c
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions backend/src/controller/participant/participants.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Get, Controller } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
import { ParticipantRepository } from '../../infra/db/repository/participant-repository';
import { ParticipantQueryService } from '../../infra/db/query-service/participant-query-service';
import { GetParticipantsUsecase } from '../../usecase/participant/get-participants-usecase';
import { GetParticipantsResponse } from './response/get-participants-response';

Expand All @@ -9,8 +9,8 @@ export class ParticipantsController {
@Get()
async getParticipants(): Promise<GetParticipantsResponse> {
const prisma = new PrismaClient();
const participantRepository = new ParticipantRepository(prisma);
const usecase = new GetParticipantsUsecase(participantRepository);
const participantQueryService = new ParticipantQueryService(prisma);
const usecase = new GetParticipantsUsecase(participantQueryService);
const result = await usecase.do();
return new GetParticipantsResponse(result);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ParticipantDto } from '../../../domain/repository-interface/participant-repository';
import { ParticipantDto } from '../../../usecase/participant/query-service-interface/participant-query-service';

export class GetParticipantsResponse {
participants: Participant[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ParticipantRepository } from './participant-repository';
import { ParticipantQueryService } from './participant-query-service';
import { prisma } from '../../../../testUtils/prisma';
import { ParticipantDto } from '../../../domain/repository-interface/participant-repository';
import { ParticipantDto } from '../../../usecase/participant/query-service-interface/participant-query-service';

describe('ParticipantRepository', () => {
const participantRepository = new ParticipantRepository(prisma);
const participantRepository = new ParticipantQueryService(prisma);

afterEach(async () => {
// https://www.prisma.io/docs/concepts/components/prisma-client/crud#cascading-deletes-deleting-related-records
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { PrismaClient } from '@prisma/client';
import {
IParticipantRepository,
IParticipantQueryService,
ParticipantDto,
} from '../../../domain/repository-interface/participant-repository';
} from '../../../usecase/participant/query-service-interface/participant-query-service';

export class ParticipantRepository implements IParticipantRepository {
export class ParticipantQueryService implements IParticipantQueryService {
constructor(private prismaClient: PrismaClient) {}

async findAll(): Promise<ParticipantDto[]> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ParticipantDto } from '../../../domain/repository-interface/participant-repository';
import { ParticipantDto } from '../../participant/query-service-interface/participant-query-service';

export class PairDto {
public readonly id: string;
Expand Down
14 changes: 7 additions & 7 deletions backend/src/usecase/participant/get-participants-usecase.spec.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { GetParticipantsUsecase } from './get-participants-usecase';
import { ParticipantRepository } from '../../infra/db/repository/participant-repository';
import { ParticipantQueryService } from '../../infra/db/query-service/participant-query-service';
import { PrismaClient } from '@prisma/client';

jest.mock('@prisma/client');
jest.mock('../../infra/db/repository/participant-repository');
jest.mock('../../infra/db/query-service/participant-query-service');

describe('GetParticipantsUsecase', () => {
let mockRepository: jest.MockedObjectDeep<ParticipantRepository>;
let mockQueryService: jest.MockedObjectDeep<ParticipantQueryService>;

beforeAll(() => {
const prisma = new PrismaClient();
mockRepository = jest.mocked(new ParticipantRepository(prisma));
mockQueryService = jest.mocked(new ParticipantQueryService(prisma));
});

describe('do', () => {
it('正常系 ParticipantRepository.findAllを1回コールすること', async () => {
it('正常系 ParticipantQueryService.findAllを1回コールすること', async () => {
// Act
const usecase = new GetParticipantsUsecase(mockRepository);
const usecase = new GetParticipantsUsecase(mockQueryService);
await usecase.do();

// Assert
expect(mockRepository.findAll).toHaveBeenCalledTimes(1);
expect(mockQueryService.findAll).toHaveBeenCalledTimes(1);
});
});
});
6 changes: 3 additions & 3 deletions backend/src/usecase/participant/get-participants-usecase.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
IParticipantRepository,
IParticipantQueryService,
ParticipantDto,
} from '../../domain/repository-interface/participant-repository';
} from './query-service-interface/participant-query-service';

export class GetParticipantsUsecase {
constructor(private participantRepository: IParticipantRepository) {}
constructor(private participantRepository: IParticipantQueryService) {}

async do(): Promise<ParticipantDto[]> {
return await this.participantRepository.findAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ export class ParticipantDto {
}
}

export interface IParticipantRepository {
export interface IParticipantQueryService {
findAll(): Promise<ParticipantDto[]>;
}

0 comments on commit a8a4e8c

Please sign in to comment.