52 lines
No EOL
1.7 KiB
TypeScript
52 lines
No EOL
1.7 KiB
TypeScript
/**
|
|
* 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 <continuist02@gmail.com>
|
|
*/
|
|
|
|
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<User[]>('/users'),
|
|
getById: (id: string) => api.get<User>(`/users/${id}`),
|
|
create: (data: Omit<User, 'id' | 'created_at' | 'updated_at'>) => api.post<User>('/users', data),
|
|
update: (id: string, data: Partial<Omit<User, 'id' | 'created_at' | 'updated_at'>>) => api.put<User>(`/users/${id}`, data),
|
|
delete: (id: string) => api.delete(`/users/${id}`),
|
|
};
|
|
|
|
export const productApi = {
|
|
getAll: () => api.get<Product[]>('/products'),
|
|
getById: (id: string) => api.get<Product>(`/products/${id}`),
|
|
create: (data: Omit<Product, 'id' | 'created_at' | 'updated_at'>) => api.post<Product>('/products', data),
|
|
update: (id: string, data: Partial<Omit<Product, 'id' | 'created_at' | 'updated_at'>>) => api.put<Product>(`/products/${id}`, data),
|
|
delete: (id: string) => api.delete(`/products/${id}`),
|
|
};
|