-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
85 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { CardDto } from '@tspark/common'; | ||
import { Card } from './card.entity'; | ||
|
||
export interface ICardService { | ||
getAll(): Promise<Card[]>; | ||
save(cardDto: CardDto): Promise<Card>; | ||
getById(id: number): Promise<CardDto | null>; | ||
getAll(): Promise<CardDto[]>; | ||
save(cardDto: CardDto): Promise<CardDto>; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { decorate, injectable } from 'inversify'; | ||
import { apiClient } from './api.client'; | ||
import { ICrudClient as IClient } from './crud.client.type'; | ||
|
||
@injectable() | ||
export abstract class CrudClient<T> implements IClient<T> { | ||
abstract readonly RESOURCE_NAME: string; | ||
|
||
async get(id: number): Promise<T | null> { | ||
try { | ||
const res = await apiClient.get(`${this.RESOURCE_NAME}/${id}`); | ||
return res.data; | ||
} catch (err) { | ||
console.error(err); | ||
return null; | ||
} | ||
} | ||
|
||
async getAll(): Promise<T[]> { | ||
try { | ||
const res = await apiClient.get(this.RESOURCE_NAME); | ||
return res.data; | ||
} catch (err) { | ||
console.error(err); | ||
return []; | ||
} | ||
} | ||
|
||
async create(item: T): Promise<void> { | ||
try { | ||
await apiClient.post(this.RESOURCE_NAME, item); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
|
||
async update(item: T): Promise<void> { | ||
try { | ||
await apiClient.put(this.RESOURCE_NAME, item); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
|
||
async delete(id: number): Promise<void> { | ||
try { | ||
await apiClient.delete(`${this.RESOURCE_NAME}/${id}`); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface ICrudClient<T> { | ||
get(id: number): Promise<T | null>; | ||
getAll(): Promise<T[]>; | ||
create(card: T): Promise<void>; | ||
update(card: T): Promise<void>; | ||
delete(id: number): Promise<void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,9 @@ | ||
import { CardDto } from '@tspark/common'; | ||
import { injectable } from 'inversify'; | ||
import { apiClient } from '../../core/api/api.client'; | ||
import { CrudClient } from '../../core/api-client/crud.client'; | ||
import { ICardClient } from './card.client.type'; | ||
|
||
@injectable() | ||
export class CardClient implements ICardClient { | ||
async getAll(): Promise<CardDto[]> { | ||
try { | ||
const res = await apiClient.get('card'); | ||
return res.data; | ||
} catch (err) { | ||
console.error(err); | ||
return []; | ||
} | ||
} | ||
|
||
async create(card: CardDto): Promise<void> { | ||
try { | ||
const res = await apiClient.post('card', card); | ||
return res.data; | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
export class CardClient extends CrudClient<CardDto> implements ICardClient { | ||
RESOURCE_NAME = 'card'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
import { CardDto } from '@tspark/common'; | ||
import { ICrudClient } from '../../core/api-client/crud.client.type'; | ||
|
||
export interface ICardClient { | ||
getAll(): Promise<CardDto[]>; | ||
create(card: CardDto): Promise<void>; | ||
} | ||
export interface ICardClient extends ICrudClient<CardDto> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters