Merge branch 'develop' into listing
This commit is contained in:
commit
93f9979259
5 changed files with 35 additions and 16 deletions
|
|
@ -4,7 +4,7 @@ export interface NoteRepository {
|
|||
getNotes(): Promise<Note[]>;
|
||||
getNote(id: number): Promise<Note>;
|
||||
getCurrentNote(): Promise<Note | void>;
|
||||
updateNote(id: number, note: Note): Promise<Note>;
|
||||
updateNote(id: number, note: Partial<Note>): Promise<Note>;
|
||||
deleteNote(id: number): void;
|
||||
createNote(note: Note): Promise<Note>;
|
||||
createNote(note: Partial<Note> & Pick<Note, 'title'>): Promise<Note>;
|
||||
}
|
||||
|
|
@ -19,12 +19,12 @@ export class StrapiNoteRepository implements NoteRepository {
|
|||
private static apiNoteEndpoint: string = "http://localhost:1337/api/notes"
|
||||
|
||||
public async getNotes(): Promise<Note[]>{
|
||||
const response = await StrapiNoteRepository.fetchStrapi("/", 'GET');
|
||||
const response = await StrapiNoteRepository.fetchStrapiNoteEndpoint("/", 'GET');
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
public async getNote(id: number): Promise<Note>{
|
||||
const response = await StrapiNoteRepository.fetchStrapi("/" + id, 'GET');
|
||||
const response = await StrapiNoteRepository.fetchStrapiNoteEndpoint("/" + id, 'GET');
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
|
|
@ -35,21 +35,21 @@ export class StrapiNoteRepository implements NoteRepository {
|
|||
return await this.getNote(this.currentNoteId);
|
||||
}
|
||||
|
||||
public async updateNote(id: number, note: Note): Promise<Note> {
|
||||
const response = await StrapiNoteRepository.fetchStrapi("/" + id, 'PUT', note);
|
||||
public async updateNote(id: number, note: Partial<Note>): Promise<Note> {
|
||||
const response = await StrapiNoteRepository.fetchStrapiNoteEndpoint("/" + id, 'PUT', note);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
public async createNote(note: Note): Promise<Note> {
|
||||
const response = await StrapiNoteRepository.fetchStrapi("/", 'POST', note);
|
||||
public async createNote(note: Partial<Note> & Pick<Note, 'title'>): Promise<Note> {
|
||||
const response = await StrapiNoteRepository.fetchStrapiNoteEndpoint("/", 'POST', note);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
public async deleteNote(id: number): Promise<void> {
|
||||
await StrapiNoteRepository.fetchStrapi("/" + id, 'DELETE');
|
||||
await StrapiNoteRepository.fetchStrapiNoteEndpoint("/" + id, 'DELETE');
|
||||
}
|
||||
|
||||
private static async fetchStrapi(path: string, method: HttpMethod, body: Note | null = null): Promise<Response> {
|
||||
private static async fetchStrapiNoteEndpoint(path: string, method: HttpMethod, body: Partial<Note> | null = null): Promise<Response> {
|
||||
let requestInit: RequestInit = {
|
||||
method: method,
|
||||
headers: {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,5 @@ export interface Note {
|
|||
id: number;
|
||||
title: string;
|
||||
content: string;
|
||||
|
||||
lastViewed: Date;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue