feat: initial prototype works

I can log in and create a book! Woo!
This commit is contained in:
2026-02-04 12:17:05 -08:00
parent e167a17bd9
commit b6d66d34cb
44 changed files with 3695 additions and 493 deletions
@@ -0,0 +1,54 @@
/**
* @copyright 2026 NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { environment } from '../../environments/environment';
@Injectable({
providedIn: 'root'
})
export class ApiService {
private readonly apiUrl = environment.apiUrl;
constructor(private http: HttpClient) {}
private getHeaders(): HttpHeaders {
// Auth token is sent as httpOnly cookie, no need to add manually
return new HttpHeaders({
'Content-Type': 'application/json'
});
}
get<T>(endpoint: string): Observable<T> {
return this.http.get<T>(`${this.apiUrl}${endpoint}`, {
headers: this.getHeaders(),
withCredentials: true // Important for cookies
});
}
post<T>(endpoint: string, body: any): Observable<T> {
return this.http.post<T>(`${this.apiUrl}${endpoint}`, body, {
headers: this.getHeaders(),
withCredentials: true
});
}
put<T>(endpoint: string, body: any): Observable<T> {
return this.http.put<T>(`${this.apiUrl}${endpoint}`, body, {
headers: this.getHeaders(),
withCredentials: true
});
}
delete<T>(endpoint: string): Observable<T> {
return this.http.delete<T>(`${this.apiUrl}${endpoint}`, {
headers: this.getHeaders(),
withCredentials: true
});
}
}