From aef3f445c53a5866838c227bc904f5d6368cc590 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Sun, 28 Feb 2021 11:20:11 +0900 Subject: [PATCH] Add member repository --- frontend/repositories/member/api.ts | 36 +++++++++++++++++++++++ frontend/repositories/member/interface.ts | 19 ++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 frontend/repositories/member/api.ts create mode 100644 frontend/repositories/member/interface.ts diff --git a/frontend/repositories/member/api.ts b/frontend/repositories/member/api.ts new file mode 100644 index 00000000..269db0f8 --- /dev/null +++ b/frontend/repositories/member/api.ts @@ -0,0 +1,36 @@ +import ApiService from '@/services/api.service' +import { MemberItem } from '@/models/member' +import { MemberItemListRepository, MemberItemResponse } from './interface' + + +export class FromApiMemberItemListRepository implements MemberItemListRepository { + constructor( + private readonly request = ApiService + ) {} + + async list(projectId: string): Promise { + const url = `/projects/${projectId}/roles` + const response = await this.request.get(url) + const responseItems: MemberItemResponse[] = response.data + return responseItems.map(item => MemberItem.valueOf(item)) + } + + async create(projectId: string, item: MemberItem): Promise { + const url = `/projects/${projectId}/roles` + const response = await this.request.post(url, item.toObject()) + const responseItem: MemberItemResponse = response.data + return MemberItem.valueOf(responseItem) + } + + async update(projectId: string, item: MemberItem): Promise { + const url = `/projects/${projectId}/roles/${item.id}` + const response = await this.request.patch(url, item.toObject()) + const responseItem: MemberItemResponse = response.data + return MemberItem.valueOf(responseItem) + } + + async bulkDelete(projectId: string, labelIds: number[]): Promise { + const url = `/projects/${projectId}/roles` + await this.request.delete(url, { ids: labelIds }) + } +} diff --git a/frontend/repositories/member/interface.ts b/frontend/repositories/member/interface.ts new file mode 100644 index 00000000..1f5b0f63 --- /dev/null +++ b/frontend/repositories/member/interface.ts @@ -0,0 +1,19 @@ +import { MemberItem } from '@/models/member' + +export interface MemberItemResponse { + id: number, + user: number, + role: number, + username: string, + rolename: string +} + +export interface MemberItemListRepository { + list(projectId: string): Promise + + create(projectId: string, item: MemberItem): Promise + + update(projectId: string, item: MemberItem): Promise + + bulkDelete(projectId: string, memberIds: number[]): Promise +}