Produktmanagement hinzugefügt und kleinere Bug behoben
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import ky from 'ky'
|
||||
import type { Product } from '../data/product'
|
||||
import type { Property } from '../data/property';
|
||||
|
||||
const API_BASE_URL = 'http://localhost:8088'
|
||||
|
||||
export async function createProduct(product: Product): Promise<Product> {
|
||||
const response = await ky
|
||||
.post(`${API_BASE_URL}/createProduct`, { json: product })
|
||||
.json<{ status: string; data: Product }>()
|
||||
|
||||
return response.data
|
||||
}
|
||||
|
||||
export async function updateProduct(product: Product): Promise<void> {
|
||||
await ky.put(`${API_BASE_URL}/updateProduct`, { json: product })
|
||||
}
|
||||
|
||||
export async function deleteProduct(id: number): Promise<void> {
|
||||
await ky.delete(`${API_BASE_URL}/deleteProduct/${id}`)
|
||||
}
|
||||
|
||||
export async function getProduct(id: number): Promise<Product> {
|
||||
const response = await ky
|
||||
.get(`${API_BASE_URL}/getProduct/${id}`)
|
||||
.json<{ status: string; product: Product }>()
|
||||
|
||||
return response.product
|
||||
}
|
||||
|
||||
export async function getProductsByGroupId(groupId: number): Promise<Product[]> {
|
||||
const response = await ky
|
||||
.get(`${API_BASE_URL}/getProductsByGroupId/${groupId}`)
|
||||
.json<{ status: string; groupId: number; products: Product[] }>()
|
||||
|
||||
// the backend returns null instead of [] when there are no matching products
|
||||
return response.products ?? []
|
||||
}
|
||||
|
||||
// note: the registered route only carries :productId, propertyId is sent in the body
|
||||
export async function addPropertyToProductId(productId: number, propertyId: number): Promise<void> {
|
||||
await ky.post(`${API_BASE_URL}/addPropertyToProductId/${productId}`, { json: { propertyId } })
|
||||
}
|
||||
|
||||
// note: the registered route only carries :productId, propertyId is sent in the body
|
||||
export async function deletePropertyFromProductId(productId: number, propertyId: number): Promise<void> {
|
||||
await ky.delete(`${API_BASE_URL}/deletePropertyFromProductId/${productId}`, { json: { propertyId } })
|
||||
}
|
||||
|
||||
export async function getPropertiesFromProductId(productId: number): Promise<Property[]> {
|
||||
const response = await ky
|
||||
.get(`${API_BASE_URL}/getPropertiesFromProductId/${productId}`)
|
||||
.json<{ status: string; productId: number; properties: Property[] }>()
|
||||
return response.properties ?? []
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import ky from 'ky'
|
||||
import type { ProductGroup } from '../data/productGroup'
|
||||
import type { Property } from '../data/property'
|
||||
|
||||
type ApiResponse<T> = {
|
||||
message: string;
|
||||
data: T;
|
||||
}
|
||||
|
||||
const API_BASE_URL = 'http://localhost:8088'
|
||||
|
||||
export async function createProductGroup(productGroup: ProductGroup): Promise<ProductGroup> {
|
||||
const response = await ky
|
||||
.post(`${API_BASE_URL}/createProductGroup`, { json: productGroup })
|
||||
.json<ApiResponse<ProductGroup>>()
|
||||
|
||||
return response.data
|
||||
}
|
||||
|
||||
export async function updateProductGroup(productGroup: ProductGroup): Promise<ProductGroup> {
|
||||
const response = await ky
|
||||
.put(`${API_BASE_URL}/updateProductGroup`, { json: productGroup })
|
||||
.json<ApiResponse<ProductGroup>>()
|
||||
|
||||
return response.data
|
||||
}
|
||||
|
||||
export async function deleteProductGroup(id: number): Promise<void> {
|
||||
await ky.delete(`${API_BASE_URL}/deleteProductGroup/${id}`)
|
||||
}
|
||||
|
||||
export async function getProductGroup(id: number): Promise<ProductGroup> {
|
||||
const response = await ky
|
||||
.get(`${API_BASE_URL}/getProductGroup/${id}`)
|
||||
.json<ApiResponse<ProductGroup>>()
|
||||
|
||||
return response.data
|
||||
}
|
||||
|
||||
export async function getProductGroupsByParentId(parentId: number): Promise<ProductGroup[]> {
|
||||
const response = await ky
|
||||
.get(`${API_BASE_URL}/getProductGroupsByParentId/${parentId}`)
|
||||
.json<ApiResponse<ProductGroup[]>>()
|
||||
|
||||
// the backend returns null instead of [] when there are no matching product groups
|
||||
return response.data ?? []
|
||||
}
|
||||
|
||||
export async function deleteProductFromProductGroupId(productId: number): Promise<void> {
|
||||
await ky.delete(`${API_BASE_URL}/deleteProductFromProductGroupId/${productId}`)
|
||||
}
|
||||
|
||||
export async function getPropertiesFromProductGroupId(productGroupId: number): Promise<Property[]> {
|
||||
const response = await ky
|
||||
.post(`${API_BASE_URL}/getPropertiesFromProductGroupId/${productGroupId}`)
|
||||
.json<ApiResponse<Property[]>>()
|
||||
|
||||
// the backend returns null instead of [] when there are no matching properties
|
||||
return response.data ?? []
|
||||
}
|
||||
|
||||
export async function deletePropertyFromProductGroupId(propertyId: number, productGroupId: number): Promise<void> {
|
||||
await ky.delete(`${API_BASE_URL}/deletePropertyFromProductGroupId/${propertyId}/${productGroupId}`)
|
||||
}
|
||||
|
||||
export async function createPropertyToProductGroupId(propertyTypeId: number, productGroupId: number): Promise<Property> {
|
||||
const response = await ky
|
||||
.get(`${API_BASE_URL}/createPropertyToProductGroupId/${propertyTypeId}/${productGroupId}`)
|
||||
.json<ApiResponse<Property>>()
|
||||
|
||||
return response.data
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user