/** * This file is part of Sharenet. * * Sharenet is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. * * You may obtain a copy of the license at: * https://creativecommons.org/licenses/by-nc-sa/4.0/ * * Copyright (c) 2024 Continuist */ import axios from 'axios'; const API_HOST = process.env.NEXT_PUBLIC_API_HOST || '127.0.0.1'; const API_PORT = process.env.NEXT_PUBLIC_API_PORT || '3001'; const API_BASE_URL = `http://${API_HOST}:${API_PORT}`; export interface User { id: string; username: string; email: string; created_at: string; updated_at: string; } export interface Product { id: string; name: string; description: string; created_at: string; updated_at: string; } const api = axios.create({ baseURL: API_BASE_URL, }); export const userApi = { getAll: () => api.get('/users'), getById: (id: string) => api.get(`/users/${id}`), create: (data: Omit) => api.post('/users', data), update: (id: string, data: Partial>) => api.put(`/users/${id}`, data), delete: (id: string) => api.delete(`/users/${id}`), }; export const productApi = { getAll: () => api.get('/products'), getById: (id: string) => api.get(`/products/${id}`), create: (data: Omit) => api.post('/products', data), update: (id: string, data: Partial>) => api.put(`/products/${id}`, data), delete: (id: string) => api.delete(`/products/${id}`), };