From 19704fa89e50acfa02d51994218c4f859d071188 Mon Sep 17 00:00:00 2001 From: Thomas Sindt Date: Tue, 4 Aug 2026 22:51:10 +0200 Subject: [PATCH] PropertyTypes integriert --- .../src/api/language/propertyTypes.api.ts | 30 ++ .../src/components/PropertyTypesTableView.tsx | 108 +++++++ .../material-editor/src/data/propertyType.ts | 9 + .../src/pages/PropertyPage.tsx | 6 +- .../controller/propertytypesController.go | 125 ++++++++ .../scpq-editor-server/models/propertytype.go | 10 + .../repositories/propertyTypesRepository.go | 292 ++++++++++++++++++ ...tory copy.go => translationsRepository.go} | 0 .../scpq-editor-server/server/httpServer.go | 11 + .../services/propertytypesService.go | 59 ++++ ...Service copy.go => translationsService.go} | 0 11 files changed, 647 insertions(+), 3 deletions(-) create mode 100644 buildtime/client/material-editor/src/api/language/propertyTypes.api.ts create mode 100644 buildtime/client/material-editor/src/components/PropertyTypesTableView.tsx create mode 100644 buildtime/client/material-editor/src/data/propertyType.ts create mode 100644 buildtime/server/src/scpq-editor-server/controller/propertytypesController.go create mode 100644 buildtime/server/src/scpq-editor-server/models/propertytype.go create mode 100644 buildtime/server/src/scpq-editor-server/repositories/propertyTypesRepository.go rename buildtime/server/src/scpq-editor-server/repositories/{translationsRepository copy.go => translationsRepository.go} (100%) create mode 100644 buildtime/server/src/scpq-editor-server/services/propertytypesService.go rename buildtime/server/src/scpq-editor-server/services/{translationsService copy.go => translationsService.go} (100%) diff --git a/buildtime/client/material-editor/src/api/language/propertyTypes.api.ts b/buildtime/client/material-editor/src/api/language/propertyTypes.api.ts new file mode 100644 index 000000000..8050fa840 --- /dev/null +++ b/buildtime/client/material-editor/src/api/language/propertyTypes.api.ts @@ -0,0 +1,30 @@ +import ky from 'ky' +import type { PropertyType } from '../../data/propertyType' + +export const getPropertyTypes = async (): Promise => { + return ky.get(`http://localhost:8088/propertytypes`).json() +} + +export const getPropertyTypeById = async (id: number): Promise => { + return ky.get(`http://localhost:8088/propertytype/${id}`).json() +} + +export const createPropertyType = async (propertyType: PropertyType): Promise => { + return ky.post(`http://localhost:8088/propertytype`, { json: propertyType }).json() +} + +export const updatePropertyType = async (propertyType: PropertyType): Promise => { + return ky.put(`http://localhost:8088/propertytype`, { json: propertyType }).json() +} + +export const deletePropertyType = async (id: number): Promise => { + return ky.delete(`http://localhost:8088/propertytype/${id}`).json() +} + +export const getPropertyTypesByPropertyGroupId = async (propertyGroupId: number): Promise => { + return ky.get(`http://localhost:8088/propertytypes/${propertyGroupId}`).json() +} + +export const getAllPropertyTypes = async (): Promise => { + return ky.get(`http://localhost:8088/propertytypes`).json() +} diff --git a/buildtime/client/material-editor/src/components/PropertyTypesTableView.tsx b/buildtime/client/material-editor/src/components/PropertyTypesTableView.tsx new file mode 100644 index 000000000..bf6b6d075 --- /dev/null +++ b/buildtime/client/material-editor/src/components/PropertyTypesTableView.tsx @@ -0,0 +1,108 @@ +import * as React from 'react'; + +import type { propertyGroup } from '../data/propertyGroup'; +import type { PropertyType } from '../data/propertyType'; + +import Paper from '@mui/material/Paper'; +import DeleteIcon from '@mui/icons-material/Delete'; +import AddIcon from '@mui/icons-material/Add'; +import Tooltip from '@mui/material/Tooltip'; +import FileDownloadIcon from '@mui/icons-material/FileDownload'; + +import { Typography } from '@mui/material'; +import { DataGrid, Toolbar, ToolbarButton} from '@mui/x-data-grid'; +import { ExportCsv } from '@mui/x-data-grid'; + +import { getPropertyGroupById } from '../api/language/propertyGroup.api'; +import { updatePropertyType } from '../api/language/propertyTypes.api'; +import { getPropertyTypesByPropertyGroupId } from '../api/language/propertyTypes.api'; + +const PropertyTypesTableView = ({ selectedRow }: { selectedRow: number }) => { + const [propertyTypes, setPropertyTypes] = React.useState([]); + const [propertyGroup, setPropertyGroup] = React.useState(null); + + React.useEffect(() => { + getPropertyTypesByPropertyGroupId(selectedRow).then(setPropertyTypes); + }, [selectedRow]); + + React.useEffect(() => { + getPropertyGroupById(selectedRow).then(setPropertyGroup); + }, [selectedRow]); + + + function CustomToolbar() { + return ( + + + Property types for group {propertyGroup?.label}. + + + }> + + + + console.log('Delete Row clicked')}> + + + console.log('Add Row clicked')}> + + + + ) + } + + + return ( +
+ + { + updatePropertyType({ + id: updatedRow.id, + valueTypeId: updatedRow.valueTypeId, + propertyGroupId: updatedRow.propertyGroupId, + valueComplexityId: updatedRow.valueComplexityId, + value: updatedRow.value + } + ) + return updatedRow; + }} + getRowClassName={(params) => + params.indexRelativeToCurrentPage % 2 === 0 ? 'even-row' : 'odd-row' + } + showToolbar + /> + +
+ ); +}; + +export default PropertyTypesTableView; \ No newline at end of file diff --git a/buildtime/client/material-editor/src/data/propertyType.ts b/buildtime/client/material-editor/src/data/propertyType.ts new file mode 100644 index 000000000..284b28ecd --- /dev/null +++ b/buildtime/client/material-editor/src/data/propertyType.ts @@ -0,0 +1,9 @@ +export type PropertyType = { + id: number; + label: string; + valueTypeId: number; + propertyGroupId: number; + valueComplexityId: number; + value: string; +}; + diff --git a/buildtime/client/material-editor/src/pages/PropertyPage.tsx b/buildtime/client/material-editor/src/pages/PropertyPage.tsx index f29f4d8c8..ab3cf746a 100644 --- a/buildtime/client/material-editor/src/pages/PropertyPage.tsx +++ b/buildtime/client/material-editor/src/pages/PropertyPage.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useState } from 'react'; -import PropertyGroupsTableView from '../components/PropertyGroupsTableView'; -import TranslationsTableView from '../components/TranslationsTableView'; +import PropertyTypesTableView from '../components/PropertyTypesTableView'; +import PropertyGroupsTableView from '../components/PropertyGroupsTableView'; import Box from '@mui/material/Box'; import Typography from '@mui/material/Typography'; import type { propertyGroup } from '../data/propertyGroup'; @@ -28,7 +28,7 @@ const PropertyPage: React.FC = () => { }} > - + ); diff --git a/buildtime/server/src/scpq-editor-server/controller/propertytypesController.go b/buildtime/server/src/scpq-editor-server/controller/propertytypesController.go new file mode 100644 index 000000000..5e82864d5 --- /dev/null +++ b/buildtime/server/src/scpq-editor-server/controller/propertytypesController.go @@ -0,0 +1,125 @@ +package controller + +import ( + "encoding/json" + "io" + "log" + "net/http" + "scpq-editor-server/models" + "scpq-editor-server/services" + "strconv" + + "github.com/gin-gonic/gin" +) + +type PropertytypesController struct { + PropertytypesService *services.PropertytypesService +} + +func NewPropertytypesController(PropertytypesService *services.PropertytypesService) *PropertytypesController { + return &PropertytypesController{ + PropertytypesService: PropertytypesService, + } +} + +func (lc PropertytypesController) CreatePropertytype(ctx *gin.Context) { + body, err := io.ReadAll(ctx.Request.Body) + if err != nil { + log.Println("Error while reading create Translation request body", err) + ctx.AbortWithError(http.StatusInternalServerError, err) + return + } + var propertyType models.PropertyType + err = json.Unmarshal(body, &propertyType) + if err != nil { + log.Println("Error while unmarshaling create PropertyType request body", err) + ctx.AbortWithError(http.StatusInternalServerError, err) + return + } + response, responseErr := lc.PropertytypesService.CreatePropertyType(&propertyType) + if responseErr != nil { + ctx.AbortWithStatusJSON(responseErr.Status, responseErr) + return + } + ctx.JSON(http.StatusOK, response) +} + +func (lc PropertytypesController) UpdatePropertytype(ctx *gin.Context) { + body, err := io.ReadAll(ctx.Request.Body) + if err != nil { + log.Println("Error while reading update PropertyType request body", err) + ctx.AbortWithError(http.StatusInternalServerError, err) + return + } + var propertyType models.PropertyType + err = json.Unmarshal(body, &propertyType) + if err != nil { + log.Println("Error while unmarshaling update PropertyType request body", err) + ctx.AbortWithError(http.StatusInternalServerError, err) + return + } + responseErr := lc.PropertytypesService.UpdatePropertyType(&propertyType) + if responseErr != nil { + ctx.AbortWithStatusJSON(responseErr.Status, responseErr) + return + } + ctx.Status(http.StatusNoContent) +} + +func (lc PropertytypesController) DeletePropertytype(ctx *gin.Context) { + propertyTypeId := ctx.Param("id") + lId, err := strconv.Atoi(propertyTypeId) + if err != nil { + log.Println("Error propertyTypeId not int", err) + ctx.AbortWithError(http.StatusInternalServerError, err) + return + } + + responseErr := lc.PropertytypesService.DeletePropertyType(lId) + if responseErr != nil { + ctx.JSON(responseErr.Status, responseErr) + return + } + ctx.Status(http.StatusNoContent) +} + +func (lc PropertytypesController) GetPropertytype(ctx *gin.Context) { + propertyTypeId := ctx.Param("id") + lId, err := strconv.Atoi(propertyTypeId) + if err != nil { + log.Println("Error propertyTypeId not int", err) + ctx.AbortWithError(http.StatusInternalServerError, err) + return + } + response, responseErr := lc.PropertytypesService.GetPropertyType(lId) + if responseErr != nil { + ctx.JSON(responseErr.Status, responseErr) + return + } + ctx.JSON(http.StatusOK, response) +} + +func (lc PropertytypesController) GetAllPropertytypes(ctx *gin.Context) { + response, responseErr := lc.PropertytypesService.GetAllPropertyTypes() + if responseErr != nil { + ctx.JSON(responseErr.Status, responseErr) + return + } + ctx.JSON(http.StatusOK, response) +} + +func (lc PropertytypesController) GetAllPropertytypesByPropertyGroupId(ctx *gin.Context) { + propertyGroupId := ctx.Param("propertyGroupId") + lId, err := strconv.Atoi(propertyGroupId) + if err != nil { + log.Println("Error propertyGroupId not int", err) + ctx.AbortWithError(http.StatusInternalServerError, err) + return + } + response, responseErr := lc.PropertytypesService.GetAllPropertyTypesByPropertyGroupId(lId) + if responseErr != nil { + ctx.JSON(responseErr.Status, responseErr) + return + } + ctx.JSON(http.StatusOK, response) +} diff --git a/buildtime/server/src/scpq-editor-server/models/propertytype.go b/buildtime/server/src/scpq-editor-server/models/propertytype.go new file mode 100644 index 000000000..8ac9fcb15 --- /dev/null +++ b/buildtime/server/src/scpq-editor-server/models/propertytype.go @@ -0,0 +1,10 @@ +package models + +type PropertyType struct { + ID int `json:"id"` + Label string `json:"label"` + ValueTypeID int `json:"valueTypeId"` + PropertyGroupID int `json:"propertyGroupId"` + ValueComplexityId string `json:"valueComplexityId"` + Value string `json:"value"` +} diff --git a/buildtime/server/src/scpq-editor-server/repositories/propertyTypesRepository.go b/buildtime/server/src/scpq-editor-server/repositories/propertyTypesRepository.go new file mode 100644 index 000000000..41c443237 --- /dev/null +++ b/buildtime/server/src/scpq-editor-server/repositories/propertyTypesRepository.go @@ -0,0 +1,292 @@ +package repositories + +import ( + "database/sql" + "net/http" + "scpq-editor-server/models" + "strconv" +) + +type PropertyTypesRepository struct { + dbHandler *sql.DB +} + +func NewPropertyTypesRepository(dbHandler *sql.DB) *PropertyTypesRepository { + return &PropertyTypesRepository{ + dbHandler: dbHandler, + } +} + +func (rr PropertyTypesRepository) CreatePropertyType(PropertyType *models.PropertyType) (*models.PropertyType, *models.ResponseError) { + query := `INSERT INTO property_types(label, value_type_id, property_group_id, value_complexity_id, value) VALUES($1,$2,$3,$4,$5) RETURNING id` + rows, err := rr.dbHandler.Query(query, PropertyType.Label, PropertyType.ValueTypeID, PropertyType.PropertyGroupID, PropertyType.ValueComplexityId, PropertyType.Value) + if err != nil { + return nil, &models.ResponseError{ + Message: err.Error(), + Status: http.StatusInternalServerError, + } + } + + defer rows.Close() + var idstr string + for rows.Next() { + err := rows.Scan(&idstr) + if err != nil { + return nil, &models.ResponseError{ + Message: err.Error(), + Status: http.StatusInternalServerError, + } + } + } + if rows.Err() != nil { + return nil, &models.ResponseError{ + Message: err.Error(), + Status: http.StatusInternalServerError, + } + } + PropertyTypeId, err := strconv.Atoi(idstr) + if err != nil { + return nil, &models.ResponseError{ + Message: "PropertyType id not int", + Status: http.StatusInternalServerError, + } + } + + return &models.PropertyType{ + ID: PropertyTypeId, + Label: PropertyType.Label, + ValueTypeID: PropertyType.ValueTypeID, + PropertyGroupID: PropertyType.PropertyGroupID, + ValueComplexityId: PropertyType.ValueComplexityId, + Value: PropertyType.Value, + }, nil +} + +func (rr PropertyTypesRepository) UpdatePropertyType(PropertyType *models.PropertyType) *models.ResponseError { + query := `UPDATE property_types SET value_type_id=$1, property_group_id=$2, value_complexity_id=$3, value=$4 WHERE id=$5` + res, err := rr.dbHandler.Exec(query, PropertyType.ValueTypeID, PropertyType.PropertyGroupID, PropertyType.ValueComplexityId, PropertyType.Value, PropertyType.ID) + if err != nil { + return &models.ResponseError{ + Message: err.Error(), + Status: http.StatusInternalServerError, + } + } + + rowsAffeced, err := res.RowsAffected() + if err != nil { + return &models.ResponseError{ + Message: err.Error(), + Status: http.StatusInternalServerError, + } + } + if rowsAffeced == 0 { + return &models.ResponseError{ + Message: "No PropertyType found with the given id", + Status: http.StatusNotFound, + } + } + return nil +} +func (rr PropertyTypesRepository) DeletePropertyType(PropertyTypeId int) *models.ResponseError { + query := `DELETE FROM property_types WHERE id=$1` + res, err := rr.dbHandler.Exec(query, PropertyTypeId) + if err != nil { + return &models.ResponseError{ + Message: err.Error(), + Status: http.StatusInternalServerError, + } + } + + rowsAffeced, err := res.RowsAffected() + if err != nil { + return &models.ResponseError{ + Message: err.Error(), + Status: http.StatusInternalServerError, + } + } + if rowsAffeced == 0 { + return &models.ResponseError{ + Message: "No PropertyType found with the given id", + Status: http.StatusNotFound, + } + } + return nil +} + +func (rr PropertyTypesRepository) GetPropertyType(PropertyTypeId int) (*models.PropertyType, *models.ResponseError) { + query := `SELECT id, label, value_type_id, property_group_id, value_complexity_id, value FROM property_types WHERE id=$1` + rows, err := rr.dbHandler.Query(query, PropertyTypeId) + if err != nil { + return nil, &models.ResponseError{ + Message: err.Error(), + Status: http.StatusInternalServerError, + } + } + + defer rows.Close() + var idstr, label, value_type_id_str, property_group_id_str, value_complexity_id, value string + for rows.Next() { + err := rows.Scan(&idstr, &label, &value_type_id_str, &property_group_id_str, &value_complexity_id, &value) + if err != nil { + return nil, &models.ResponseError{ + Message: err.Error(), + Status: http.StatusInternalServerError, + } + } + } + if rows.Err() != nil { + return nil, &models.ResponseError{ + Message: err.Error(), + Status: http.StatusInternalServerError, + } + } + PropertyTypeId, err = strconv.Atoi(idstr) + if err != nil { + return nil, &models.ResponseError{ + Message: "PropertyType id not int", + Status: http.StatusInternalServerError, + } + } + PropertyGroupID, err := strconv.Atoi(property_group_id_str) + if err != nil { + return nil, &models.ResponseError{ + Message: "PropertyGroup id not int", + Status: http.StatusInternalServerError, + } + } + ValueTypeID, err := strconv.Atoi(value_type_id_str) + if err != nil { + return nil, &models.ResponseError{ + Message: "ValueType id not int", + Status: http.StatusInternalServerError, + } + } + + return &models.PropertyType{ + ID: PropertyTypeId, + Label: label, + ValueTypeID: ValueTypeID, + ValueComplexityId: value_complexity_id, + Value: value, + PropertyGroupID: PropertyGroupID, + }, nil +} + +func (rr PropertyTypesRepository) GetAllPropertyTypes() ([]*models.PropertyType, *models.ResponseError) { + query := "SELECT id, label, value_type_id, property_group_id, value_complexity_id, value FROM property_types" + rows, err := rr.dbHandler.Query(query) + if err != nil { + return nil, &models.ResponseError{ + Message: err.Error(), + Status: http.StatusInternalServerError, + } + } + + defer rows.Close() + PropertyTypes := make([]*models.PropertyType, 0) + var idstr, label, value_type_id_str, property_group_id_str, value_complexity_id, value string + for rows.Next() { + err := rows.Scan(&idstr, &label, &value_type_id_str, &property_group_id_str, &value_complexity_id, &value) + if err != nil { + return nil, &models.ResponseError{ + Message: err.Error(), + Status: http.StatusInternalServerError, + } + } + PropertyTypeId, err := strconv.Atoi(idstr) + if err != nil { + return nil, &models.ResponseError{ + Message: "PropertyType id not int", + Status: http.StatusInternalServerError, + } + } + PropertyGroupID, err := strconv.Atoi(property_group_id_str) + if err != nil { + return nil, &models.ResponseError{ + Message: "PropertyGroup id not int", + Status: http.StatusInternalServerError, + } + } + ValueTypeID, err := strconv.Atoi(value_type_id_str) + if err != nil { + return nil, &models.ResponseError{ + Message: "ValueType id not int", + Status: http.StatusInternalServerError, + } + } + + PropertyType := &models.PropertyType{ + ID: PropertyTypeId, + Label: label, + ValueTypeID: ValueTypeID, + ValueComplexityId: value_complexity_id, + Value: value, + PropertyGroupID: PropertyGroupID, + } + PropertyTypes = append(PropertyTypes, PropertyType) + + } + if rows.Err() != nil { + return nil, &models.ResponseError{ + Message: err.Error(), + Status: http.StatusInternalServerError, + } + } + return PropertyTypes, nil +} + +func (rr PropertyTypesRepository) GetAllPropertyTypesByPropertyGroupId(propertyGroupId int) ([]*models.PropertyType, *models.ResponseError) { + query := "SELECT id, label, value_type_id, property_group_id, value_complexity_id, value FROM property_types WHERE property_group_id=$1" + rows, err := rr.dbHandler.Query(query, propertyGroupId) + if err != nil { + return nil, &models.ResponseError{ + Message: err.Error(), + Status: http.StatusInternalServerError, + } + } + + defer rows.Close() + PropertyTypes := make([]*models.PropertyType, 0) + var idstr, label, value_type_id_str, property_group_id_str, value_complexity_id, value string + var ValueTypeID int + for rows.Next() { + err := rows.Scan(&idstr, &label, &value_type_id_str, &property_group_id_str, &value_complexity_id, &value) + if err != nil { + return nil, &models.ResponseError{ + Message: err.Error(), + Status: http.StatusInternalServerError, + } + } + PropertyTypeId, err := strconv.Atoi(idstr) + if err != nil { + return nil, &models.ResponseError{ + Message: "PropertyType id not int", + Status: http.StatusInternalServerError, + } + } + PropertyGroupID, err := strconv.Atoi(property_group_id_str) + if err != nil { + return nil, &models.ResponseError{ + Message: "PropertyGroup id not int", + Status: http.StatusInternalServerError, + } + } + PropertyType := &models.PropertyType{ + ID: PropertyTypeId, + Label: label, + ValueTypeID: ValueTypeID, + ValueComplexityId: value_complexity_id, + Value: value, + PropertyGroupID: PropertyGroupID, + } + PropertyTypes = append(PropertyTypes, PropertyType) + + } + if rows.Err() != nil { + return nil, &models.ResponseError{ + Message: err.Error(), + Status: http.StatusInternalServerError, + } + } + return PropertyTypes, nil +} diff --git a/buildtime/server/src/scpq-editor-server/repositories/translationsRepository copy.go b/buildtime/server/src/scpq-editor-server/repositories/translationsRepository.go similarity index 100% rename from buildtime/server/src/scpq-editor-server/repositories/translationsRepository copy.go rename to buildtime/server/src/scpq-editor-server/repositories/translationsRepository.go diff --git a/buildtime/server/src/scpq-editor-server/server/httpServer.go b/buildtime/server/src/scpq-editor-server/server/httpServer.go index c2960b267..540b217bb 100644 --- a/buildtime/server/src/scpq-editor-server/server/httpServer.go +++ b/buildtime/server/src/scpq-editor-server/server/httpServer.go @@ -30,10 +30,12 @@ func InitHttpServer(config *viper.Viper, dbHandler *sql.DB) HttpServer { valuetypesRepository := repositories.NewValuetypesRepository(dbHandler) valuecomplexitiesRepository := repositories.NewValuecomplexitiesRepository(dbHandler) translationsRepository := repositories.NewTranslationsRepository(dbHandler) + propertytypesRepository := repositories.NewPropertyTypesRepository(dbHandler) // service initialisation: languagesService := services.NewLanguagesService(languagesRepository) propertygroupsService := services.NewPropertygroupsService(propertygroupsRepository) + propertytypesService := services.NewPropertytypesService(propertytypesRepository) valuetypesService := services.NewValuetypesService(valuetypesRepository) valuecomplexitiesService := services.NewValuecomplexitiesService(valuecomplexitiesRepository) translationsService := services.NewTranslationsService(translationsRepository) @@ -41,6 +43,7 @@ func InitHttpServer(config *viper.Viper, dbHandler *sql.DB) HttpServer { // controller initialisation: languageController := controller.NewLanguagesController(languagesService) propertygroupsController := controller.NewPropertygroupsController(propertygroupsService) + propertytypesController := controller.NewPropertytypesController(propertytypesService) valuetypesController := controller.NewValuetypesController(valuetypesService) valuecomplexitiesController := controller.NewValuecomplexitiesController(valuecomplexitiesService) translationsController := controller.NewTranslationsController(translationsService) @@ -72,6 +75,14 @@ func InitHttpServer(config *viper.Viper, dbHandler *sql.DB) HttpServer { router.GET("/translations", translationsController.GetAllTranslations) router.GET("/translations/:languageId", translationsController.GetAllTranslationsByLanguageId) + // Property-Type centric routing + router.POST("/propertytype", propertytypesController.CreatePropertytype) + router.PUT("/propertytype", propertytypesController.UpdatePropertytype) + router.DELETE("/propertytype/:id", propertytypesController.DeletePropertytype) + router.GET("/propertytype/:id", propertytypesController.GetPropertytype) + router.GET("/propertytypes", propertytypesController.GetAllPropertytypes) + router.GET("/propertytypes/:propertyGroupId", propertytypesController.GetAllPropertytypesByPropertyGroupId) + // valuetype centric routing router.GET("/valuetype/:id", valuetypesController.GetValuetype) router.GET("/valuetypes", valuetypesController.GetAllValuetypes) diff --git a/buildtime/server/src/scpq-editor-server/services/propertytypesService.go b/buildtime/server/src/scpq-editor-server/services/propertytypesService.go new file mode 100644 index 000000000..aac8c2804 --- /dev/null +++ b/buildtime/server/src/scpq-editor-server/services/propertytypesService.go @@ -0,0 +1,59 @@ +package services + +import ( + "net/http" + "scpq-editor-server/models" + "scpq-editor-server/repositories" +) + +type PropertytypesService struct { + propertyTypesRepository *repositories.PropertyTypesRepository +} + +func NewPropertytypesService(propertyTypesRepository *repositories.PropertyTypesRepository) *PropertytypesService { + return &PropertytypesService{ + propertyTypesRepository: propertyTypesRepository, + } +} + +func (ls PropertytypesService) CreatePropertyType(propertyType *models.PropertyType) (*models.PropertyType, *models.ResponseError) { + responseErr := validatePropertyType(propertyType) + if responseErr != nil { + return nil, responseErr + } + return ls.propertyTypesRepository.CreatePropertyType(propertyType) +} + +func (ls PropertytypesService) UpdatePropertyType(propertyType *models.PropertyType) *models.ResponseError { + responseErr := validatePropertyType(propertyType) + if responseErr != nil { + return responseErr + } + return ls.propertyTypesRepository.UpdatePropertyType(propertyType) +} + +func (ls PropertytypesService) DeletePropertyType(propertyTypeId int) *models.ResponseError { + return ls.propertyTypesRepository.DeletePropertyType(propertyTypeId) +} + +func (ls PropertytypesService) GetPropertyType(propertyTypeId int) (*models.PropertyType, *models.ResponseError) { + return ls.propertyTypesRepository.GetPropertyType(propertyTypeId) +} + +func (ls PropertytypesService) GetAllPropertyTypes() ([]*models.PropertyType, *models.ResponseError) { + return ls.propertyTypesRepository.GetAllPropertyTypes() +} + +func (ls PropertytypesService) GetAllPropertyTypesByPropertyGroupId(propertyGroupId int) ([]*models.PropertyType, *models.ResponseError) { + return ls.propertyTypesRepository.GetAllPropertyTypesByPropertyGroupId(propertyGroupId) +} + +func validatePropertyType(propertyType *models.PropertyType) *models.ResponseError { + if propertyType.Value == "" { + return &models.ResponseError{ + Message: "Invalid PropertyType value", + Status: http.StatusBadRequest, + } + } + return nil +} diff --git a/buildtime/server/src/scpq-editor-server/services/translationsService copy.go b/buildtime/server/src/scpq-editor-server/services/translationsService.go similarity index 100% rename from buildtime/server/src/scpq-editor-server/services/translationsService copy.go rename to buildtime/server/src/scpq-editor-server/services/translationsService.go