mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
Continue work on brewery page, implement like system
This commit is contained in:
@@ -1,12 +1,8 @@
|
||||
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
|
||||
|
||||
const sendLikeRequest = async (beerPostId: string) => {
|
||||
const sendBeerPostLikeRequest = async (beerPostId: string) => {
|
||||
const response = await fetch(`/api/beers/${beerPostId}/like`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: '',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -26,4 +22,4 @@ const sendLikeRequest = async (beerPostId: string) => {
|
||||
return { success, message };
|
||||
};
|
||||
|
||||
export default sendLikeRequest;
|
||||
export default sendBeerPostLikeRequest;
|
||||
25
src/requests/sendBreweryPostLikeRequest.ts
Normal file
25
src/requests/sendBreweryPostLikeRequest.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
|
||||
|
||||
const sendBreweryPostLikeRequest = async (breweryPostId: string) => {
|
||||
const response = await fetch(`/api/breweries/${breweryPostId}/like`, {
|
||||
method: 'POST',
|
||||
});
|
||||
|
||||
const json = await response.json();
|
||||
|
||||
const parsed = APIResponseValidationSchema.safeParse(json);
|
||||
|
||||
if (!parsed.success) {
|
||||
throw new Error('Invalid API response.');
|
||||
}
|
||||
|
||||
if (!parsed.success) {
|
||||
throw new Error('Invalid API response.');
|
||||
}
|
||||
|
||||
const { success, message } = parsed.data;
|
||||
|
||||
return { success, message };
|
||||
};
|
||||
|
||||
export default sendBreweryPostLikeRequest;
|
||||
Reference in New Issue
Block a user