Move next js project to archive (#207)

This commit is contained in:
Aaron Po
2026-04-20 02:30:25 -04:00
committed by GitHub
parent 92ec16ce93
commit d47e3ed7f0
347 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,118 @@
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
import CommentQueryResult from '@/services/schema/CommentSchema/CommentQueryResult';
import {
SendCreateBeerCommentRequest,
SendDeleteBeerPostCommentRequest,
SendEditBeerPostCommentRequest,
} from './types';
/**
* Sends an api request to edit a beer post comment.
*
* @param params - The parameters for the request.
* @param params.body - The body of the request.
* @param params.body.content - The content of the comment.
* @param params.body.rating - The rating of the beer.
* @param params.commentId - The id of the comment to edit.
* @param params.beerPostId - The id of the beer post the comment belongs to.
* @returns The JSON response from the server.
* @throws An error if the request fails or the response is invalid.
*/
export const editBeerPostCommentRequest: SendEditBeerPostCommentRequest = async ({
body,
commentId,
beerPostId,
}) => {
const response = await fetch(`/api/beers/${beerPostId}/comments/${commentId}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
});
if (!response.ok) {
throw new Error('Failed to edit comment');
}
const json = await response.json();
const parsed = APIResponseValidationSchema.safeParse(json);
if (!parsed.success) {
throw new Error(parsed.error.message);
}
return parsed.data;
};
/**
* Sends an api request to delete a beer post comment.
*
* @param params - The parameters for the request.
* @param params.commentId - The id of the comment to delete.
* @param params.beerPostId - The id of the beer post the comment belongs to.
* @returns The JSON response from the server.
* @throws An error if the request fails or the response is invalid.
*/
export const deleteBeerPostCommentRequest: SendDeleteBeerPostCommentRequest = async ({
commentId,
beerPostId,
}) => {
const response = await fetch(`/api/beers/${beerPostId}/comments/${commentId}`, {
method: 'DELETE',
});
if (!response.ok) {
throw new Error('Failed to delete comment');
}
const json = await response.json();
const parsed = APIResponseValidationSchema.safeParse(json);
if (!parsed.success) {
throw new Error(parsed.error.message);
}
return parsed.data;
};
/**
* Send an api request to create a comment on a beer post.
*
* @param params - The parameters for the request.
* @param params.beerPostId - The id of the beer post to create the comment on.
* @param params.body - The body of the request.
* @param params.body.content - The content of the comment.
* @param params.body.rating - The rating of the beer.
* @returns The created comment.
* @throws An error if the request fails or the response is invalid.
*/
export const sendCreateBeerCommentRequest: SendCreateBeerCommentRequest = async ({
beerPostId,
body: { content, rating },
}) => {
const response = await fetch(`/api/beers/${beerPostId}/comments`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ beerPostId, content, rating }),
});
if (!response.ok) {
throw new Error(response.statusText);
}
const data = await response.json();
const parsedResponse = APIResponseValidationSchema.safeParse(data);
if (!parsedResponse.success) {
throw new Error('Invalid API response');
}
const parsedPayload = CommentQueryResult.safeParse(parsedResponse.data.payload);
if (!parsedPayload.success) {
throw new Error('Invalid API response payload');
}
return parsedPayload.data;
};
export default sendCreateBeerCommentRequest;

View File

@@ -0,0 +1,19 @@
import CommentQueryResult from '@/services/schema/CommentSchema/CommentQueryResult';
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
import { z } from 'zod';
export type SendEditBeerPostCommentRequest = (args: {
body: { content: string; rating: number };
commentId: string;
beerPostId: string;
}) => Promise<z.infer<typeof APIResponseValidationSchema>>;
export type SendDeleteBeerPostCommentRequest = (args: {
commentId: string;
beerPostId: string;
}) => Promise<z.infer<typeof APIResponseValidationSchema>>;
export type SendCreateBeerCommentRequest = (args: {
beerPostId: string;
body: { content: string; rating: number };
}) => Promise<z.infer<typeof CommentQueryResult>>;

View File

@@ -0,0 +1,117 @@
import CommentQueryResult from '@/services/schema/CommentSchema/CommentQueryResult';
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
import {
SendCreateBeerStyleCommentRequest,
SendDeleteBeerStyleCommentRequest,
SendEditBeerStyleCommentRequest,
} from './types';
/**
* Sends an api request to edit a beer style comment.
*
* @param params - The parameters for the request.
* @param params.body - The body of the request.
* @param params.body.content - The content of the comment.
* @param params.body.rating - The rating of the beer.
* @param params.beerStyleId - The id of the beer style the comment belongs to.
* @param params.commentId - The id of the comment to edit.
* @returns The JSON response from the server.
* @throws An error if the request fails or the response is invalid.
*/
export const sendEditBeerStyleCommentRequest: SendEditBeerStyleCommentRequest = async ({
commentId,
body: { content, rating },
beerStyleId,
}) => {
const response = await fetch(`/api/beers/styles/${beerStyleId}/comments/${commentId}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ content, rating }),
});
if (!response.ok) {
throw new Error(response.statusText);
}
const json = await response.json();
const parsed = APIResponseValidationSchema.safeParse(json);
if (!parsed.success) {
throw new Error('Invalid API response');
}
return parsed.data;
};
/**
* Sends an api request to delete a beer style comment.
*
* @param params - The parameters for the request.
* @param params.beerStyleId - The id of the beer style the comment belongs to.
* @param params.commentId - The id of the comment to delete.
* @returns The json response from the server.
* @throws An error if the request fails or the response is invalid.
*/
export const sendDeleteBeerStyleCommentRequest: SendDeleteBeerStyleCommentRequest =
async ({ beerStyleId, commentId }) => {
const response = await fetch(
`/api/beers/styles/${beerStyleId}/comments/${commentId}`,
{
method: 'DELETE',
},
);
if (!response.ok) {
throw new Error(response.statusText);
}
const json = await response.json();
const parsed = APIResponseValidationSchema.safeParse(json);
if (!parsed.success) {
throw new Error('Invalid API response');
}
return parsed.data;
};
/**
* Sends an api request to create a beer style comment.
*
* @param params - The parameters for the request.
* @param params.body - The body of the request.
* @param params.body.content - The content of the comment.
* @param params.body.rating - The rating of the beer.
* @param params.beerStyleId - The id of the beer style the comment belongs to.
* @returns The created comment.
* @throws An error if the request fails or the response is invalid.
*/
export const sendCreateBeerStyleCommentRequest: SendCreateBeerStyleCommentRequest =
async ({ beerStyleId, body: { content, rating } }) => {
const response = await fetch(`/api/beers/styles/${beerStyleId}/comments`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ beerStyleId, content, rating }),
});
if (!response.ok) {
throw new Error(response.statusText);
}
const data = await response.json();
const parsedResponse = APIResponseValidationSchema.safeParse(data);
if (!parsedResponse.success) {
throw new Error('Invalid API response');
}
const parsedPayload = CommentQueryResult.safeParse(parsedResponse.data.payload);
if (!parsedPayload.success) {
throw new Error('Invalid API response payload');
}
return parsedPayload.data;
};

View File

@@ -0,0 +1,19 @@
import CommentQueryResult from '@/services/schema/CommentSchema/CommentQueryResult';
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
import { z } from 'zod';
export type SendEditBeerStyleCommentRequest = (args: {
body: { content: string; rating: number };
commentId: string;
beerStyleId: string;
}) => Promise<z.infer<typeof APIResponseValidationSchema>>;
export type SendDeleteBeerStyleCommentRequest = (args: {
commentId: string;
beerStyleId: string;
}) => Promise<z.infer<typeof APIResponseValidationSchema>>;
export type SendCreateBeerStyleCommentRequest = (args: {
beerStyleId: string;
body: { content: string; rating: number };
}) => Promise<z.infer<typeof CommentQueryResult>>;

View File

@@ -0,0 +1,109 @@
import CommentQueryResult from '@/services/schema/CommentSchema/CommentQueryResult';
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
import {
SendCreateBreweryPostCommentRequest,
SendDeleteBreweryPostCommentRequest,
SendEditBreweryPostCommentRequest,
} from './types';
/**
* Sends an api request to edit a brewery comment.
*
* @param params - The parameters for the request.
* @param params.breweryId - The id of the brewery the comment belongs to.
* @param params.commentId - The id of the comment to edit.
* @param params.body - The body of the request.
* @param params.body.content - The content of the comment.
* @param params.body.rating - The rating of the beer.
*/
export const sendEditBreweryPostCommentRequest: SendEditBreweryPostCommentRequest =
async ({ body: { content, rating }, breweryPostId, commentId }) => {
const response = await fetch(
`/api/breweries/${breweryPostId}/comments/${commentId}`,
{
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ content, rating }),
},
);
if (!response.ok) {
throw new Error(response.statusText);
}
const json = await response.json();
const parsed = APIResponseValidationSchema.safeParse(json);
if (!parsed.success) {
throw new Error(parsed.error.message);
}
return parsed.data;
};
/**
* Sends an api request to delete a brewery comment.
*
* @param params - The parameters for the request.
* @param params.breweryId - The id of the brewery the comment belongs to.
* @param params.commentId - The id of the comment to delete.
* @returns The JSON response from the server.
* @throws An error if the request fails or the response is invalid.
*/
export const sendDeleteBreweryPostCommentRequest: SendDeleteBreweryPostCommentRequest =
async ({ breweryPostId, commentId }) => {
const response = await fetch(
`/api/breweries/${breweryPostId}/comments/${commentId}`,
{
method: 'DELETE',
},
);
if (!response.ok) {
throw new Error(response.statusText);
}
const json = await response.json();
const parsed = APIResponseValidationSchema.safeParse(json);
if (!parsed.success) {
throw new Error(parsed.error.message);
}
return parsed.data;
};
/**
* Sends an api request to create a brewery comment.
*
* @param params - The parameters for the request.
* @param params.body - The body of the request.
* @param params.body.content - The content of the comment.
* @param params.body.rating - The rating of the beer.
* @param params.breweryId - The id of the brewery the comment belongs to.
* @returns The created comment.
* @throws An error if the request fails or the response is invalid.
*/
export const sendCreateBreweryCommentRequest: SendCreateBreweryPostCommentRequest =
async ({ body: { content, rating }, breweryPostId }) => {
const response = await fetch(`/api/breweries/${breweryPostId}/comments`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ content, rating }),
});
if (!response.ok) {
throw new Error(response.statusText);
}
const data = await response.json();
const parsedResponse = APIResponseValidationSchema.safeParse(data);
if (!parsedResponse.success) {
throw new Error('Invalid API response');
}
const parsedPayload = CommentQueryResult.safeParse(parsedResponse.data.payload);
if (!parsedPayload.success) {
throw new Error('Invalid API response payload');
}
return parsedPayload.data;
};

View File

@@ -0,0 +1,39 @@
import CommentQueryResult from '@/services/schema/CommentSchema/CommentQueryResult';
import CreateCommentValidationSchema from '@/services/schema/CommentSchema/CreateCommentValidationSchema';
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
import { z } from 'zod';
const BreweryCommentValidationSchemaWithId = CreateCommentValidationSchema.extend({
breweryPostId: z.string(),
});
const sendCreateBreweryCommentRequest = async ({
content,
rating,
breweryPostId,
}: z.infer<typeof BreweryCommentValidationSchemaWithId>) => {
const response = await fetch(`/api/breweries/${breweryPostId}/comments`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ content, rating }),
});
if (!response.ok) {
throw new Error(response.statusText);
}
const data = await response.json();
const parsedResponse = APIResponseValidationSchema.safeParse(data);
if (!parsedResponse.success) {
throw new Error('Invalid API response');
}
const parsedPayload = CommentQueryResult.safeParse(parsedResponse.data.payload);
if (!parsedPayload.success) {
throw new Error('Invalid API response payload');
}
return parsedPayload.data;
};
export default sendCreateBreweryCommentRequest;

View File

@@ -0,0 +1,19 @@
import CommentQueryResult from '@/services/schema/CommentSchema/CommentQueryResult';
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
import { z } from 'zod';
export type SendEditBreweryPostCommentRequest = (args: {
body: { content: string; rating: number };
commentId: string;
breweryPostId: string;
}) => Promise<z.infer<typeof APIResponseValidationSchema>>;
export type SendDeleteBreweryPostCommentRequest = (args: {
commentId: string;
breweryPostId: string;
}) => Promise<z.infer<typeof APIResponseValidationSchema>>;
export type SendCreateBreweryPostCommentRequest = (args: {
breweryPostId: string;
body: { content: string; rating: number };
}) => Promise<z.infer<typeof CommentQueryResult>>;