Continue work on brewery page, implement like system

This commit is contained in:
Aaron William Po
2023-04-23 17:25:39 -04:00
parent 9504da33d6
commit 58d30b605f
27 changed files with 699 additions and 125 deletions

View File

@@ -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;

View 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;