feat: bootstrap temporserv project scaffold
Add the initial project blueprint, Go backend skeleton, frontend app shell, database schema draft, and local development/deployment files.
This commit is contained in:
66
apps/web/src/lib/api.ts
Normal file
66
apps/web/src/lib/api.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
export type User = {
|
||||
id: string
|
||||
username: string
|
||||
isAdmin: boolean
|
||||
}
|
||||
|
||||
export type HomePayload = {
|
||||
recentAlbums: Array<{
|
||||
id: string
|
||||
artistId: string
|
||||
artistName: string
|
||||
title: string
|
||||
year: number
|
||||
trackCount: number
|
||||
}>
|
||||
artists: Array<{
|
||||
id: string
|
||||
name: string
|
||||
albumCount: number
|
||||
}>
|
||||
}
|
||||
|
||||
export type Track = {
|
||||
id: string
|
||||
albumId: string
|
||||
artistId: string
|
||||
title: string
|
||||
artistName: string
|
||||
albumTitle: string
|
||||
trackNumber: number
|
||||
durationSeconds: number
|
||||
}
|
||||
|
||||
const API_BASE = import.meta.env.VITE_API_BASE ?? 'http://localhost:4040'
|
||||
|
||||
async function request<T>(path: string, init?: RequestInit): Promise<T> {
|
||||
const response = await fetch(`${API_BASE}${path}`, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...(init?.headers ?? {}),
|
||||
},
|
||||
...init,
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Request failed: ${response.status}`)
|
||||
}
|
||||
|
||||
return response.json() as Promise<T>
|
||||
}
|
||||
|
||||
export async function login(username: string, password: string) {
|
||||
return request<{ token: string; user: User }>('/api/auth/login', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ username, password }),
|
||||
})
|
||||
}
|
||||
|
||||
export async function fetchHome() {
|
||||
return request<HomePayload>('/api/home')
|
||||
}
|
||||
|
||||
export async function fetchTracks() {
|
||||
return request<{ items: Track[] }>('/api/tracks')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user