-
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
1 parent
7271309
commit bcecbcd
Showing
7 changed files
with
126 additions
and
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// src/api/api.ts | ||
export async function fetchPublishers() { | ||
const response = await fetch('/api/publisher'); | ||
if (!response.ok) { | ||
throw new Error('Failed to fetch publishers'); | ||
} | ||
return response.json().then((data) => data.data); | ||
} | ||
|
||
export async function fetchRandomBooks() { | ||
const response = await fetch('/api/random?limit=12') | ||
if (!response.ok) { | ||
throw new Error('Failed to random'); | ||
} | ||
return response.json().then((data) => data.data); | ||
} | ||
|
||
export async function fetchRecentBooks(limit: number, offset: number) { | ||
const response = await fetch(`/api/recently?limit=${limit}&offset=${offset}`) | ||
if (!response.ok) { | ||
throw new Error('Failed to random'); | ||
} | ||
return response.json().then((data) => data.data); | ||
} | ||
|
||
export async function fetchBooks(filter: string[], limit: number, offset: number) { | ||
const response = await fetch('/api/search?q=', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
Filter: filter, | ||
Limit: limit, | ||
Offset: offset, | ||
}), | ||
}); | ||
if (!response.ok) { | ||
throw new Error('Failed to fetch books'); | ||
} | ||
return response.json().then((data) => data.data); | ||
} | ||
|
||
export async function deleteBook(bookId: number) { | ||
const response = await fetch(`/api/book/${bookId}/delete`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
if (!response.ok) { | ||
throw new Error('Failed to delete book'); | ||
} | ||
return response.json().then((data) => data.data); | ||
} | ||
|
||
export async function fetchBook(id: string) { | ||
try { | ||
const response = await fetch(`/api/book/${id}`); | ||
if (!response.ok) throw new Error('Network response was not ok'); | ||
return await response.json(); | ||
} catch (error) { | ||
console.error('There was a problem with the fetch operation:', error); | ||
throw error; | ||
} | ||
} |
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
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
Oops, something went wrong.