Files
agologum/client/src/api/UsersApi.ts
Blitblank b1865afced
All checks were successful
Build and Deploy Frontend / build-and-deploy (push) Successful in 6s
Build and Deploy API / build-and-deploy (push) Successful in 11s
dev configuration for api
2026-03-10 22:58:21 -05:00

26 lines
1.0 KiB
TypeScript

// services are kinda whatever, but in general its a good idea for all api calls to be within a service (at least thats how angular handles it)
// this user service will handle all to <-> from the server when handling user objects
// should be injected with the http client (I think its axios ?)
import axios from "axios";
import type {AxiosResponse } from "axios";
import type { User } from "../models/User.ts";
const API_URL: string = "/users";
const baseUrl: string = import.meta.env.DEV ? import.meta.env.VITE_DEV_API_URL : import.meta.env.VITE_PROD_API_URL; // TODO: overarching api service
const api = axios.create({
baseURL: baseUrl
});
export const getUsers = () => api.get<User[]>(`${API_URL}`);
export const getUser = (id: number) => api.get<User>(`${API_URL}/${id}`);
export const createUser = (data: User) => api.post<User>(`${API_URL}`, data);
export const updateUser = (id: number, data: User) => api.put<User>(`${API_URL}/${id}`, data);
export const deleteUser = (id: number) => api.delete<User>(`${API_URL}/${id}`);