mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-15 10:04:44 +00:00
Add brewery location query endpoints
This commit is contained in:
@@ -37,6 +37,12 @@ export interface Brewery {
|
||||
location: BreweryLocation | null;
|
||||
}
|
||||
|
||||
export interface SimplifiedBrewery {
|
||||
breweryPostId: string;
|
||||
breweryName: string;
|
||||
location: BreweryLocation | null;
|
||||
}
|
||||
|
||||
const fetchApi = async (path: string): Promise<Response> => {
|
||||
try {
|
||||
return await fetch(`${API_BASE_URL}${path}`);
|
||||
@@ -66,6 +72,20 @@ export const getBreweries = async (limit?: number, offset?: number): Promise<Bre
|
||||
return body.payload;
|
||||
};
|
||||
|
||||
export const getBreweryLocations = async (): Promise<SimplifiedBrewery[]> => {
|
||||
const res = await fetchApi('/api/brewery/locations');
|
||||
|
||||
if (!res.ok) {
|
||||
throw data(`Failed to load brewery locations (${res.status}).`, {
|
||||
status: res.status,
|
||||
statusText: res.statusText,
|
||||
});
|
||||
}
|
||||
|
||||
const body: ApiResponse<SimplifiedBrewery[]> = await res.json();
|
||||
return body.payload;
|
||||
};
|
||||
|
||||
export const getBreweryById = async (id: string): Promise<Brewery | null> => {
|
||||
const res = await fetchApi(`/api/brewery/${encodeURIComponent(id)}`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user