Note interface changed, Repo create fixed
This commit is contained in:
parent
bbd6f6635d
commit
02d5aa0263
2 changed files with 6 additions and 11 deletions
|
|
@ -19,12 +19,12 @@ export class StrapiNoteRepository implements NoteRepository {
|
||||||
private static apiNoteEndpoint: string = "http://localhost:1337/api/notes"
|
private static apiNoteEndpoint: string = "http://localhost:1337/api/notes"
|
||||||
|
|
||||||
public async getNotes(): Promise<Note[]>{
|
public async getNotes(): Promise<Note[]>{
|
||||||
const response = await StrapiNoteRepository.fetchStrapi("/", 'GET');
|
const response = await StrapiNoteRepository.fetchStrapiNoteEndpoint("/", 'GET');
|
||||||
return await response.json();
|
return await response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getNote(id: number): Promise<Note>{
|
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();
|
return await response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -36,20 +36,20 @@ export class StrapiNoteRepository implements NoteRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateNote(id: number, note: Partial<Note>): Promise<Note> {
|
public async updateNote(id: number, note: Partial<Note>): Promise<Note> {
|
||||||
const response = await StrapiNoteRepository.fetchStrapi("/" + id, 'PUT', note);
|
const response = await StrapiNoteRepository.fetchStrapiNoteEndpoint("/" + id, 'PUT', note);
|
||||||
return await response.json();
|
return await response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async createNote(note: Partial<Note> & Pick<Note, 'title'>): Promise<Note> {
|
public async createNote(note: Partial<Note> & Pick<Note, 'title'>): Promise<Note> {
|
||||||
const response = await StrapiNoteRepository.fetchStrapi("/", 'POST', note);
|
const response = await StrapiNoteRepository.fetchStrapiNoteEndpoint("/", 'POST', note);
|
||||||
return await response.json();
|
return await response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deleteNote(id: number): Promise<void> {
|
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: Partial<Note> | null = null): Promise<Response> {
|
private static async fetchStrapiNoteEndpoint(path: string, method: HttpMethod, body: Partial<Note> | null = null): Promise<Response> {
|
||||||
let requestInit: RequestInit = {
|
let requestInit: RequestInit = {
|
||||||
method: method,
|
method: method,
|
||||||
headers: {
|
headers: {
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,6 @@
|
||||||
export interface Note {
|
export interface Note {
|
||||||
id: number;
|
id: number;
|
||||||
attributes: Attribute;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Attribute {
|
|
||||||
title: string;
|
title: string;
|
||||||
content: string;
|
content: string;
|
||||||
|
|
||||||
lastViewed: Date;
|
lastViewed: Date;
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue