React API für PropertyTypes und Values hinzugefügt

This commit is contained in:
2026-08-19 10:56:13 +02:00
parent 4fe9756920
commit 2f328e9355
6 changed files with 428 additions and 1 deletions
@@ -0,0 +1,71 @@
import ky from 'ky'
import type { PropertyType } from '../data/propertyType'
const API_BASE_URL = 'http://localhost:8088'
type ApiResponse<T> = {
message: string;
data: T;
}
type BackendPropertyType = {
id: number;
label: string;
description: string;
propertyTypeGroupId: number;
}
function toBackendPropertyType(propertyType: PropertyType): BackendPropertyType {
return {
id: propertyType.id,
label: propertyType.label,
description: propertyType.description,
propertyTypeGroupId: propertyType.propertyGroupId,
}
}
function toClientPropertyType(propertyType: BackendPropertyType): PropertyType {
return {
id: propertyType.id,
label: propertyType.label,
description: propertyType.description,
propertyGroupId: propertyType.propertyTypeGroupId,
}
}
export async function createPropertyType(propertyType: PropertyType): Promise<PropertyType> {
const response = await ky
.post(`${API_BASE_URL}/createPropertyType`, { json: toBackendPropertyType(propertyType) })
.json<ApiResponse<BackendPropertyType>>()
return toClientPropertyType(response.data)
}
export async function updatePropertyType(propertyType: PropertyType): Promise<PropertyType> {
const response = await ky
.put(`${API_BASE_URL}/updatePropertyType`, { json: toBackendPropertyType(propertyType) })
.json<ApiResponse<BackendPropertyType>>()
return toClientPropertyType(response.data)
}
export async function deletePropertyType(id: number): Promise<void> {
await ky.delete(`${API_BASE_URL}/deletePropertyType/${id}`)
}
export async function getPropertyType(id: number): Promise<PropertyType> {
const response = await ky
.get(`${API_BASE_URL}/getPropertyType/${id}`)
.json<ApiResponse<BackendPropertyType>>()
return toClientPropertyType(response.data)
}
export async function getPropertyTypesByGroupId(groupId: number): Promise<PropertyType[]> {
const response = await ky
.get(`${API_BASE_URL}/getPropertyTypesByGroupId/${groupId}`)
.json<ApiResponse<BackendPropertyType[]>>()
return response.data.map(toClientPropertyType)
}
@@ -0,0 +1,53 @@
import ky from 'ky'
import type { Value } from '../data/value'
const API_BASE_URL = 'http://localhost:8088'
type ApiResponse<T> = {
message: string;
data: T;
}
export async function createValueForPropertyTypeId(propertyTypeId: number, value: Value): Promise<Value> {
const response = await ky
.post(`${API_BASE_URL}/createValueForPropertyTypeId/${propertyTypeId}`, { json: value })
.json<ApiResponse<Value>>()
return response.data
}
export async function deleteValueFromPropertyTypeId(propertyTypeId: number): Promise<void> {
await ky.delete(`${API_BASE_URL}/deleteValueFromPropertyTypeId/${propertyTypeId}`)
}
export async function getValuesFromPropertyTypeId(propertyTypeId: number): Promise<Value[]> {
const response = await ky
.get(`${API_BASE_URL}/getValuesFromPropertyTypeId/${propertyTypeId}`)
.json<ApiResponse<Value[]>>()
return response.data
}
export async function getValuesFromPropertyId(propertyId: number): Promise<Value[]> {
const response = await ky
.get(`${API_BASE_URL}/getValuesFromPropertyId/${propertyId}`)
.json<ApiResponse<Value[]>>()
return response.data
}
export async function deleteValueFromPropertyId(valueId: number, propertyId: number): Promise<void> {
await ky.delete(`${API_BASE_URL}/deleteValueFromPropertyId/${valueId}/${propertyId}`)
}
export async function getValue(id: number): Promise<Value> {
const response = await ky
.get(`${API_BASE_URL}/getValue/${id}`)
.json<ApiResponse<Value>>()
return response.data
}
export async function setTerminalValueForProperty(propertyId: number, value: string): Promise<void> {
await ky.post(`${API_BASE_URL}/SetTerminalValueForProperty/${propertyId}/${value}`)
}
@@ -0,0 +1,6 @@
export type Value = {
id: number;
label: string;
description: string;
propertyId: number;
};