Vereinfachung des Datenmodells und Anpassen der UI
This commit is contained in:
@@ -1,22 +1,18 @@
|
|||||||
import {useState, useEffect} from 'react';
|
|
||||||
import Tooltip from '@mui/material/Tooltip';
|
import Tooltip from '@mui/material/Tooltip';
|
||||||
import { ExportCsv } from '@mui/x-data-grid';
|
import { ExportCsv } from '@mui/x-data-grid';
|
||||||
import type {Language} from '../data/language';
|
import type {Language} from '../data/language';
|
||||||
|
|
||||||
import { DataGrid, Toolbar, ToolbarButton, useGridApiRef } from '@mui/x-data-grid';
|
import { DataGrid, Toolbar, ToolbarButton} from '@mui/x-data-grid';
|
||||||
import Paper from '@mui/material/Paper';
|
import Paper from '@mui/material/Paper';
|
||||||
import DeleteIcon from '@mui/icons-material/Delete';
|
import DeleteIcon from '@mui/icons-material/Delete';
|
||||||
import AddIcon from '@mui/icons-material/Add';
|
import AddIcon from '@mui/icons-material/Add';
|
||||||
import FileDownloadIcon from '@mui/icons-material/FileDownload';
|
import FileDownloadIcon from '@mui/icons-material/FileDownload';
|
||||||
|
|
||||||
import {getLanguages} from '../api/language/languages.api';
|
|
||||||
import {updateLanguage} from '../api/language/languages.api';
|
import {updateLanguage} from '../api/language/languages.api';
|
||||||
|
import type { GridSelectionModel } from '@mui/x-data-grid';
|
||||||
import { Typography } from '@mui/material';
|
import { Typography } from '@mui/material';
|
||||||
|
|
||||||
const LanguagesTableView = () => {
|
const LanguagesTableView = ({ languages, setSelectedRow }: { languages: Language[]; setSelectedRow: (id: number) => void }) => {
|
||||||
const [languages, setLanguages] = useState<Language[]>([]);
|
// const [languages, setLanguages] = useState<Language[]>([]);
|
||||||
|
|
||||||
const apiRef = useGridApiRef();
|
|
||||||
|
|
||||||
function CustomToolbar() {
|
function CustomToolbar() {
|
||||||
return (
|
return (
|
||||||
@@ -38,14 +34,23 @@ const LanguagesTableView = () => {
|
|||||||
</Toolbar>
|
</Toolbar>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
useEffect(() => {
|
|
||||||
getLanguages().then(setLanguages);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Paper sx={{ height: 600, width: '50%' }}>
|
<Paper sx={{ height: 600, width: '100%' }}>
|
||||||
<DataGrid
|
<DataGrid
|
||||||
|
sx={{ border: 1, borderRadius: 2,
|
||||||
|
boxShadow: 2,
|
||||||
|
borderColor: 'primary.main',
|
||||||
|
'& .MuiDataGrid-cell:hover': { color: 'primary.main' },
|
||||||
|
'& .even-row': { backgroundColor: 'rgba(0, 0, 1, 0.02)' },
|
||||||
|
'& .odd-row': { backgroundColor: 'rgba(0, 0, 20, 0.04)' },
|
||||||
|
}}
|
||||||
|
|
||||||
|
columnHeaderHeight={36}
|
||||||
|
rowHeight={25}
|
||||||
|
rowSpacingType="margin"
|
||||||
initialState={{
|
initialState={{
|
||||||
sorting: {
|
sorting: {
|
||||||
sortModel: [{ field: 'language', sort: 'asc' }],
|
sortModel: [{ field: 'language', sort: 'asc' }],
|
||||||
@@ -53,19 +58,26 @@ const LanguagesTableView = () => {
|
|||||||
}}
|
}}
|
||||||
rows={languages}
|
rows={languages}
|
||||||
columns={[
|
columns={[
|
||||||
{ field: 'id', headerName: 'ID', width: 100 ,align: 'right'},
|
{ field: 'id', headerName: 'ID', width: 100 ,align: 'right', headerAlign: 'right', editable: false},
|
||||||
{ field: 'locale', headerName: 'Locale', width: 200, editable: true },
|
{ field: 'locale', headerName: 'Locale', width: 200, editable: true },
|
||||||
{ field: 'language', headerName: 'Language', width: 200 , editable: true},
|
{ field: 'language', headerName: 'Language', width: 200 , editable: true},
|
||||||
]}
|
]}
|
||||||
slots={{
|
slots={{
|
||||||
toolbar: CustomToolbar,
|
toolbar: CustomToolbar,
|
||||||
}}
|
}}
|
||||||
pageSize={5}
|
|
||||||
rowsPerPageOptions={[5]}
|
|
||||||
processRowUpdate={(updatedRow, originalRow) => {
|
processRowUpdate={(updatedRow, originalRow) => {
|
||||||
updateLanguage({id: updatedRow.id, locale: updatedRow.locale, language: updatedRow.language});
|
updateLanguage({id: updatedRow.id, locale: updatedRow.locale, language: updatedRow.language});
|
||||||
return updatedRow;
|
return updatedRow;
|
||||||
}}
|
}}
|
||||||
|
getRowClassName={(params) =>
|
||||||
|
params.indexRelativeToCurrentPage % 2 === 0 ? 'even-row' : 'odd-row'
|
||||||
|
}
|
||||||
|
onCellClick={(params) => {
|
||||||
|
const selectedRowId = params.id as number;
|
||||||
|
const selectedRow = languages.find((row) => row.id === selectedRowId);
|
||||||
|
setSelectedRow(selectedRow ? selectedRow.id : 0);
|
||||||
|
}}
|
||||||
|
|
||||||
showToolbar
|
showToolbar
|
||||||
/>
|
/>
|
||||||
</Paper>
|
</Paper>
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
import Tooltip from '@mui/material/Tooltip';
|
||||||
|
import { ExportCsv } from '@mui/x-data-grid';
|
||||||
|
import type {Language} from '../data/language';
|
||||||
|
|
||||||
|
import { DataGrid, Toolbar, ToolbarButton} from '@mui/x-data-grid';
|
||||||
|
import Paper from '@mui/material/Paper';
|
||||||
|
import DeleteIcon from '@mui/icons-material/Delete';
|
||||||
|
import AddIcon from '@mui/icons-material/Add';
|
||||||
|
import FileDownloadIcon from '@mui/icons-material/FileDownload';
|
||||||
|
import {updateLanguage} from '../api/language/languages.api';
|
||||||
|
import type { GridSelectionModel } from '@mui/x-data-grid';
|
||||||
|
import { Typography } from '@mui/material';
|
||||||
|
|
||||||
|
const TranslationsTableView = ({ selectedRow }: { selectedRow: number }) => {
|
||||||
|
// const [languages, setLanguages] = useState<Language[]>([]);
|
||||||
|
|
||||||
|
function CustomToolbar() {
|
||||||
|
return (
|
||||||
|
<Toolbar>
|
||||||
|
<Typography variant="body1" component="div" sx={{ flexGrow: 1 }}>
|
||||||
|
Here you see all your available languages for translations.
|
||||||
|
</Typography>
|
||||||
|
<Tooltip title="Download as CSV">
|
||||||
|
<ExportCsv render={<ToolbarButton />}>
|
||||||
|
<FileDownloadIcon fontSize="small" />
|
||||||
|
</ExportCsv>
|
||||||
|
</Tooltip>
|
||||||
|
<ToolbarButton onClick={() => console.log('Delete Row clicked')}>
|
||||||
|
<DeleteIcon fontSize="small" sx={{ ml: 'auto' }} />
|
||||||
|
</ToolbarButton>
|
||||||
|
<ToolbarButton onClick={() => console.log('Add Row clicked')}>
|
||||||
|
<AddIcon fontSize="small" sx={{ ml: 'auto' }} />
|
||||||
|
</ToolbarButton>
|
||||||
|
</Toolbar>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Paper sx={{ height: 600, width: '100%' }}>{selectedRow}</Paper>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
/*{ <DataGrid
|
||||||
|
sx={{ border: 1, borderRadius: 2,
|
||||||
|
boxShadow: 2,
|
||||||
|
borderColor: 'primary.main',
|
||||||
|
'& .MuiDataGrid-cell:hover': { color: 'primary.main' },
|
||||||
|
'& .even-row': { backgroundColor: 'rgba(0, 0, 1, 0.02)' },
|
||||||
|
'& .odd-row': { backgroundColor: 'rgba(0, 0, 20, 0.04)' },
|
||||||
|
}}
|
||||||
|
|
||||||
|
columnHeaderHeight={36}
|
||||||
|
rowHeight={25}
|
||||||
|
rowSpacingType="margin"
|
||||||
|
initialState={{
|
||||||
|
sorting: {
|
||||||
|
sortModel: [{ field: 'language', sort: 'asc' }],
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
rows={languages}
|
||||||
|
columns={[
|
||||||
|
{ field: 'id', headerName: 'ID', width: 100 ,align: 'right', headerAlign: 'right', editable: false},
|
||||||
|
{ field: 'locale', headerName: 'Locale', width: 200, editable: true },
|
||||||
|
{ field: 'language', headerName: 'Language', width: 200 , editable: true},
|
||||||
|
]}
|
||||||
|
slots={{
|
||||||
|
toolbar: CustomToolbar,
|
||||||
|
}}
|
||||||
|
processRowUpdate={(updatedRow, originalRow) => {
|
||||||
|
updateLanguage({id: updatedRow.id, locale: updatedRow.locale, language: updatedRow.language});
|
||||||
|
return updatedRow;
|
||||||
|
}}
|
||||||
|
getRowClassName={(params) =>
|
||||||
|
params.indexRelativeToCurrentPage % 2 === 0 ? 'even-row' : 'odd-row'
|
||||||
|
}
|
||||||
|
onSelectionModelChange={(newSelection) => {
|
||||||
|
const selectedRowId = newSelection[0];
|
||||||
|
const selectedRow = languages.find((row) => row.id === selectedRowId);
|
||||||
|
setSelectedRow(selectedRow ? selectedRow.id : 0);
|
||||||
|
}}
|
||||||
|
|
||||||
|
showToolbar
|
||||||
|
/> }
|
||||||
|
</Paper>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};*/
|
||||||
|
|
||||||
|
export default TranslationsTableView;
|
||||||
@@ -1,15 +1,35 @@
|
|||||||
import React from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import LanguagesTableView from '../components/LanguagesTableView';
|
import LanguagesTableView from '../components/LanguagesTableView';
|
||||||
|
import TranslationsTableView from '../components/TranslationsTableView';
|
||||||
import Box from '@mui/material/Box';
|
import Box from '@mui/material/Box';
|
||||||
import Typography from '@mui/material/Typography';
|
import Typography from '@mui/material/Typography';
|
||||||
|
import Grid from '@mui/material/Grid';
|
||||||
|
import type { Language } from '../data/language';
|
||||||
|
import { getLanguages } from '../api/language/languages.api';
|
||||||
|
|
||||||
const LanguagesPage: React.FC = () => {
|
const LanguagesPage: React.FC = () => {
|
||||||
|
const [languages, setLanguages] = useState<Language[]>([]);
|
||||||
|
const [selectedRow, setSelectedRow] = useState(0);
|
||||||
|
useEffect(() => {
|
||||||
|
getLanguages().then(setLanguages);
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box component="section" sx={{ p: 2, border: '1px dashed grey' }}>
|
<Box component="section" sx={{ p: 2, border: '1px dashed grey' }}>
|
||||||
<Typography variant="h3">
|
<Typography variant="h3">
|
||||||
Language Management
|
Language Management
|
||||||
</Typography>
|
</Typography>
|
||||||
<LanguagesTableView />
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: "flex", // Arrange children in a row
|
||||||
|
flexDirection: "row",
|
||||||
|
p: 2, // Padding around the flex container
|
||||||
|
bgcolor: "#f5f5f5"
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<LanguagesTableView languages={languages} setSelectedRow={setSelectedRow} />
|
||||||
|
<TranslationsTableView selectedRow={selectedRow} />
|
||||||
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import Box from '@mui/material/Box';
|
||||||
|
import Typography from '@mui/material/Typography';
|
||||||
|
|
||||||
const PropertyPage: React.FC = () => {
|
const PropertyPage: React.FC = () => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<Box component="section" sx={{ p: 2, border: '1px dashed grey' }}>
|
||||||
<h1>Welcome to the Property Page</h1>
|
<Typography variant="h3">
|
||||||
<p>This is the main landing page for Property handling.</p>
|
Property Management
|
||||||
</div>
|
</Typography>
|
||||||
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -24,19 +24,6 @@ func NewPropertygroupsController(PropertygroupsService *services.PropertygroupsS
|
|||||||
|
|
||||||
func (lc PropertygroupsController) CreatePropertygroup(ctx *gin.Context) {
|
func (lc PropertygroupsController) CreatePropertygroup(ctx *gin.Context) {
|
||||||
|
|
||||||
PropertygroupParentId := ctx.Param("parentid")
|
|
||||||
lId, err := strconv.Atoi(PropertygroupParentId)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("Error PropertygroupId not int", err)
|
|
||||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
parent, responseErr := lc.PropertygroupsService.GetPropertygroup(lId, 1)
|
|
||||||
if responseErr != nil {
|
|
||||||
ctx.JSON(responseErr.Status, responseErr)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
body, err := io.ReadAll(ctx.Request.Body)
|
body, err := io.ReadAll(ctx.Request.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error while reading create Propertygroup request body", err)
|
log.Println("Error while reading create Propertygroup request body", err)
|
||||||
@@ -51,7 +38,7 @@ func (lc PropertygroupsController) CreatePropertygroup(ctx *gin.Context) {
|
|||||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
response, responseErr := lc.PropertygroupsService.CreatePropertygroup(&Propertygroup, parent)
|
response, responseErr := lc.PropertygroupsService.CreatePropertygroup(&Propertygroup)
|
||||||
if responseErr != nil {
|
if responseErr != nil {
|
||||||
ctx.AbortWithStatusJSON(responseErr.Status, responseErr)
|
ctx.AbortWithStatusJSON(responseErr.Status, responseErr)
|
||||||
return
|
return
|
||||||
@@ -81,54 +68,6 @@ func (lc PropertygroupsController) UpdatePropertygroup(ctx *gin.Context) {
|
|||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lc PropertygroupsController) ChangePropertygroupParent(ctx *gin.Context) {
|
|
||||||
params := ctx.Request.URL.Query()
|
|
||||||
oldPropertygroupParentId := params.Get("oldparentid")
|
|
||||||
lId, err := strconv.Atoi(oldPropertygroupParentId)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("Error PropertygroupId not int", err)
|
|
||||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
oldparent, responseErr := lc.PropertygroupsService.GetPropertygroup(lId, 1)
|
|
||||||
if responseErr != nil {
|
|
||||||
ctx.JSON(responseErr.Status, responseErr)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
newPropertygroupParentId := params.Get("newparentid")
|
|
||||||
lId, err = strconv.Atoi(newPropertygroupParentId)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("Error PropertygroupId not int", err)
|
|
||||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
newparent, responseErr := lc.PropertygroupsService.GetPropertygroup(lId, 1)
|
|
||||||
if responseErr != nil {
|
|
||||||
ctx.JSON(responseErr.Status, responseErr)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
body, err := io.ReadAll(ctx.Request.Body)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("Error while reading update Propertygroup request body", err)
|
|
||||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var Propertygroup models.Propertygroup
|
|
||||||
err = json.Unmarshal(body, &Propertygroup)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("Error while unmarshaling update Propertygroup request body", err)
|
|
||||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
responseErr = lc.PropertygroupsService.ChangePropertygroupParent(&Propertygroup, oldparent, newparent)
|
|
||||||
if responseErr != nil {
|
|
||||||
ctx.AbortWithStatusJSON(responseErr.Status, responseErr)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ctx.Status(http.StatusNoContent)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (lc PropertygroupsController) DeletePropertygroup(ctx *gin.Context) {
|
func (lc PropertygroupsController) DeletePropertygroup(ctx *gin.Context) {
|
||||||
PropertygroupId := ctx.Param("id")
|
PropertygroupId := ctx.Param("id")
|
||||||
lId, err := strconv.Atoi(PropertygroupId)
|
lId, err := strconv.Atoi(PropertygroupId)
|
||||||
@@ -148,21 +87,23 @@ func (lc PropertygroupsController) DeletePropertygroup(ctx *gin.Context) {
|
|||||||
|
|
||||||
func (lc PropertygroupsController) GetPropertygroup(ctx *gin.Context) {
|
func (lc PropertygroupsController) GetPropertygroup(ctx *gin.Context) {
|
||||||
PropertygroupId := ctx.Param("id")
|
PropertygroupId := ctx.Param("id")
|
||||||
LangId := ctx.Param("langid")
|
|
||||||
lId, err := strconv.Atoi(PropertygroupId)
|
lId, err := strconv.Atoi(PropertygroupId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error PropertygroupId not int", err)
|
log.Println("Error PropertygroupId not int", err)
|
||||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
languageId, err := strconv.Atoi(LangId)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("Error LangId not int", err)
|
|
||||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
response, responseErr := lc.PropertygroupsService.GetPropertygroup(lId, languageId)
|
response, responseErr := lc.PropertygroupsService.GetPropertygroup(lId)
|
||||||
|
if responseErr != nil {
|
||||||
|
ctx.JSON(responseErr.Status, responseErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.JSON(http.StatusOK, response)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lc PropertygroupsController) GetAllPropertygroups(ctx *gin.Context) {
|
||||||
|
response, responseErr := lc.PropertygroupsService.GetAllPropertygroups()
|
||||||
if responseErr != nil {
|
if responseErr != nil {
|
||||||
ctx.JSON(responseErr.Status, responseErr)
|
ctx.JSON(responseErr.Status, responseErr)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"scpq-editor-server/services"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ValuecomplexitiesController struct {
|
||||||
|
ValuecomplexitiesService *services.ValuecomplexitiesService
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewValuecomplexitiesController(ValuecomplexitiesService *services.ValuecomplexitiesService) *ValuecomplexitiesController {
|
||||||
|
return &ValuecomplexitiesController{
|
||||||
|
ValuecomplexitiesService: ValuecomplexitiesService,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (vc ValuecomplexitiesController) GetAllValuecomplexities(ctx *gin.Context) {
|
||||||
|
response, responseErr := vc.ValuecomplexitiesService.GetAllValuecomplexities()
|
||||||
|
if responseErr != nil {
|
||||||
|
ctx.JSON(responseErr.Status, responseErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.JSON(http.StatusOK, response)
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"scpq-editor-server/services"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ValuetypesController struct {
|
||||||
|
ValuetypesService *services.ValuetypesService
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewValuetypesController(ValuetypesService *services.ValuetypesService) *ValuetypesController {
|
||||||
|
return &ValuetypesController{
|
||||||
|
ValuetypesService: ValuetypesService,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (vc ValuetypesController) GetValuetype(ctx *gin.Context) {
|
||||||
|
ValuetypeId := ctx.Param("id")
|
||||||
|
lId, err := strconv.Atoi(ValuetypeId)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Error ValuetypeId not int", err)
|
||||||
|
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response, responseErr := vc.ValuetypesService.GetValuetype(lId)
|
||||||
|
if responseErr != nil {
|
||||||
|
ctx.JSON(responseErr.Status, responseErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.JSON(http.StatusOK, response)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (vc ValuetypesController) GetAllValuetypes(ctx *gin.Context) {
|
||||||
|
response, responseErr := vc.ValuetypesService.GetAllValuetypes()
|
||||||
|
if responseErr != nil {
|
||||||
|
ctx.JSON(responseErr.Status, responseErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.JSON(http.StatusOK, response)
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -3,8 +3,5 @@ package models
|
|||||||
type Propertygroup struct {
|
type Propertygroup struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
Label string `json:"label"`
|
Label string `json:"label"`
|
||||||
LabelTranslation string `json:"labelTranslation"`
|
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
DescriptionTranslation string `json:"descriptionTranslationKey"`
|
|
||||||
SubPropertygroups []*Propertygroup `json:"subPropertygroups"`
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
type Valuecomplexity struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Complexity string `json:"complexity"`
|
||||||
|
Valuedefinition string `json:"valuedefinition"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
type Valuetype struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Label string `json:"label"`
|
||||||
|
}
|
||||||
@@ -20,9 +20,9 @@ func NewPropertiesgroupsRepository(dbHandler *sql.DB) *PropertygroupsRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rr PropertygroupsRepository) CreatePropertygroup(Propertygroup *models.Propertygroup, parent *models.Propertygroup) (*models.Propertygroup, *models.ResponseError) {
|
func (rr PropertygroupsRepository) CreatePropertygroup(Propertygroup *models.Propertygroup) (*models.Propertygroup, *models.ResponseError) {
|
||||||
query := `INSERT INTO property_groups(label, description, parent_property_group_id) VALUES($1,$2,$2) RETURNING id`
|
query := `INSERT INTO property_groups(label, description) VALUES($1,$2) RETURNING id`
|
||||||
rows, err := rr.dbHandler.Query(query, Propertygroup.Label, Propertygroup.Description, parent.ID)
|
rows, err := rr.dbHandler.Query(query, Propertygroup.Label, Propertygroup.Description)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, &models.ResponseError{
|
return nil, &models.ResponseError{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
@@ -59,12 +59,8 @@ func (rr PropertygroupsRepository) CreatePropertygroup(Propertygroup *models.Pro
|
|||||||
ID: PropertygroupId,
|
ID: PropertygroupId,
|
||||||
Label: Propertygroup.Label,
|
Label: Propertygroup.Label,
|
||||||
Description: Propertygroup.Description,
|
Description: Propertygroup.Description,
|
||||||
SubPropertygroups: []*models.Propertygroup{},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if parent != nil {
|
|
||||||
parent.SubPropertygroups = append(parent.SubPropertygroups, pg)
|
|
||||||
}
|
|
||||||
rr.m[pg.ID] = pg
|
rr.m[pg.ID] = pg
|
||||||
return pg, nil
|
return pg, nil
|
||||||
}
|
}
|
||||||
@@ -96,39 +92,6 @@ func (rr PropertygroupsRepository) UpdatePropertygroup(Propertygroup *models.Pro
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rr PropertygroupsRepository) ChangePropertygroupParent(Propertygroup *models.Propertygroup, opPropertygroup *models.Propertygroup, npPropertygroup *models.Propertygroup) *models.ResponseError {
|
|
||||||
query := `UPDATE property_groups SET parent=$1 WHERE id=$2`
|
|
||||||
res, err := rr.dbHandler.Exec(query, npPropertygroup.ID, Propertygroup.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 Propertygroup found with the given id",
|
|
||||||
Status: http.StatusNotFound,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
index := findIndex(opPropertygroup.SubPropertygroups, *Propertygroup)
|
|
||||||
if index != -1 {
|
|
||||||
opPropertygroup.SubPropertygroups = RemoveAt(opPropertygroup.SubPropertygroups, index)
|
|
||||||
}
|
|
||||||
npPropertygroup.SubPropertygroups = append(npPropertygroup.SubPropertygroups, Propertygroup)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func findIndex(slice []*models.Propertygroup, target models.Propertygroup) int {
|
func findIndex(slice []*models.Propertygroup, target models.Propertygroup) int {
|
||||||
for i, v := range slice {
|
for i, v := range slice {
|
||||||
if v.ID == target.ID {
|
if v.ID == target.ID {
|
||||||
@@ -169,7 +132,7 @@ func (rr PropertygroupsRepository) DeletePropertygroup(PropertygroupId int) *mod
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rr PropertygroupsRepository) GetPropertygroup(PropertygroupId int, langId int) (*models.Propertygroup, *models.ResponseError) {
|
func (rr PropertygroupsRepository) GetPropertygroup(PropertygroupId int) (*models.Propertygroup, *models.ResponseError) {
|
||||||
|
|
||||||
if pg, exists := rr.m[PropertygroupId]; exists {
|
if pg, exists := rr.m[PropertygroupId]; exists {
|
||||||
return pg, nil
|
return pg, nil
|
||||||
@@ -197,8 +160,8 @@ func (rr PropertygroupsRepository) GetPropertygroup(PropertygroupId int, langId
|
|||||||
}
|
}
|
||||||
if rows.Err() != nil {
|
if rows.Err() != nil {
|
||||||
return nil, &models.ResponseError{
|
return nil, &models.ResponseError{
|
||||||
Message: err.Error(),
|
Message: "property group id not found",
|
||||||
Status: http.StatusInternalServerError,
|
Status: http.StatusNotFound,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
id, err := strconv.Atoi(idstr)
|
id, err := strconv.Atoi(idstr)
|
||||||
@@ -209,61 +172,22 @@ func (rr PropertygroupsRepository) GetPropertygroup(PropertygroupId int, langId
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// translate label and description based on langId
|
|
||||||
translation_query := `SELECT translation FROM property_group_translations WHERE property_group_id=$1 AND language_id=$2`
|
|
||||||
translation_rows, err := rr.dbHandler.Query(translation_query, id, langId)
|
|
||||||
if err != nil {
|
|
||||||
return nil, &models.ResponseError{
|
|
||||||
Message: err.Error(),
|
|
||||||
Status: http.StatusInternalServerError,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
defer translation_rows.Close()
|
|
||||||
var translation string
|
|
||||||
for translation_rows.Next() {
|
|
||||||
err := translation_rows.Scan(&translation)
|
|
||||||
if err != nil {
|
|
||||||
return nil, &models.ResponseError{
|
|
||||||
Message: err.Error(),
|
|
||||||
Status: http.StatusInternalServerError,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if translation_rows.Err() != nil {
|
|
||||||
return nil, &models.ResponseError{
|
|
||||||
Message: err.Error(),
|
|
||||||
Status: http.StatusInternalServerError,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if translation == "" {
|
|
||||||
translation = label
|
|
||||||
}
|
|
||||||
pg := &models.Propertygroup{
|
pg := &models.Propertygroup{
|
||||||
ID: id,
|
ID: id,
|
||||||
Label: label,
|
Label: label,
|
||||||
LabelTranslation: translation,
|
|
||||||
Description: description,
|
Description: description,
|
||||||
}
|
}
|
||||||
|
|
||||||
err2 := rr.GetSubPropertygroups(pg, langId)
|
|
||||||
if err2 != nil {
|
|
||||||
return nil, &models.ResponseError{
|
|
||||||
Message: "Error reading sub propertygroups for propertygroup with id " + strconv.Itoa(pg.ID) + " : " + err2.Message,
|
|
||||||
Status: http.StatusInternalServerError,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rr.m[pg.ID] = pg
|
rr.m[pg.ID] = pg
|
||||||
return pg, nil
|
return pg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rr PropertygroupsRepository) GetSubPropertygroups(Propertygroup *models.Propertygroup, langId int) *models.ResponseError {
|
func (rr PropertygroupsRepository) GetAllPropertygroups() ([]*models.Propertygroup, *models.ResponseError) {
|
||||||
query := `SELECT id FROM property_groups WHERE parent_property_group_id=$1`
|
var Propertygroups []*models.Propertygroup
|
||||||
rows, err := rr.dbHandler.Query(query, Propertygroup.ID)
|
query := `SELECT id FROM property_groups`
|
||||||
|
rows, err := rr.dbHandler.Query(query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &models.ResponseError{
|
return nil, &models.ResponseError{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
Status: http.StatusInternalServerError,
|
Status: http.StatusInternalServerError,
|
||||||
}
|
}
|
||||||
@@ -273,38 +197,38 @@ func (rr PropertygroupsRepository) GetSubPropertygroups(Propertygroup *models.Pr
|
|||||||
var idstr string
|
var idstr string
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
err := rows.Scan(&idstr)
|
err := rows.Scan(&idstr)
|
||||||
log.Println("Sub Propertygroup id", idstr)
|
log.Println("Propertygroup id", idstr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &models.ResponseError{
|
return nil, &models.ResponseError{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
Status: http.StatusInternalServerError,
|
Status: http.StatusInternalServerError,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
id, err := strconv.Atoi(idstr)
|
id, err := strconv.Atoi(idstr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &models.ResponseError{
|
return nil, &models.ResponseError{
|
||||||
Message: "Sub Propertygroup id not int " + idstr,
|
Message: "Propertygroup id not int " + idstr,
|
||||||
Status: http.StatusInternalServerError,
|
Status: http.StatusInternalServerError,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pg, err2 := rr.GetPropertygroup(id, langId)
|
pg, err2 := rr.GetPropertygroup(id)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
return &models.ResponseError{
|
return nil, &models.ResponseError{
|
||||||
Message: "SubPropertygroup not found with the given id " + idstr,
|
Message: "Propertygroup not found with the given id " + idstr,
|
||||||
Status: http.StatusInternalServerError,
|
Status: http.StatusInternalServerError,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if pg != nil {
|
if pg != nil {
|
||||||
rr.m[pg.ID] = pg
|
rr.m[pg.ID] = pg
|
||||||
Propertygroup.SubPropertygroups = append(Propertygroup.SubPropertygroups, pg)
|
Propertygroups = append(Propertygroups, pg)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if rows.Err() != nil {
|
if rows.Err() != nil {
|
||||||
return &models.ResponseError{
|
return nil, &models.ResponseError{
|
||||||
Message: rows.Err().Error(),
|
Message: rows.Err().Error(),
|
||||||
Status: http.StatusInternalServerError,
|
Status: http.StatusInternalServerError,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return Propertygroups, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package repositories
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"net/http"
|
||||||
|
"scpq-editor-server/models"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ValuecomplexitiesRepository struct {
|
||||||
|
dbHandler *sql.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewValuecomplexitiesRepository(dbHandler *sql.DB) *ValuecomplexitiesRepository {
|
||||||
|
return &ValuecomplexitiesRepository{
|
||||||
|
dbHandler: dbHandler,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rr ValuecomplexitiesRepository) GetAllValuecomplexities() ([]*models.Valuecomplexity, *models.ResponseError) {
|
||||||
|
query := "SELECT id, complexity, value_definition FROM value_complexities"
|
||||||
|
rows, err := rr.dbHandler.Query(query)
|
||||||
|
if err != nil {
|
||||||
|
return nil, &models.ResponseError{
|
||||||
|
Message: err.Error(),
|
||||||
|
Status: http.StatusInternalServerError,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defer rows.Close()
|
||||||
|
valuecomplexities := make([]*models.Valuecomplexity, 0)
|
||||||
|
var idstr, complexity, valuedefinition string
|
||||||
|
for rows.Next() {
|
||||||
|
err := rows.Scan(&idstr, &complexity, &valuedefinition)
|
||||||
|
if err != nil {
|
||||||
|
return nil, &models.ResponseError{
|
||||||
|
Message: err.Error(),
|
||||||
|
Status: http.StatusInternalServerError,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
id, err := strconv.Atoi(idstr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, &models.ResponseError{
|
||||||
|
Message: "value complexity id not int",
|
||||||
|
Status: http.StatusInternalServerError,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
valuecomplexity := &models.Valuecomplexity{
|
||||||
|
ID: id,
|
||||||
|
Complexity: complexity,
|
||||||
|
Valuedefinition: valuedefinition,
|
||||||
|
}
|
||||||
|
valuecomplexities = append(valuecomplexities, valuecomplexity)
|
||||||
|
}
|
||||||
|
if rows.Err() != nil {
|
||||||
|
return nil, &models.ResponseError{
|
||||||
|
Message: "error iterating over value complexities rows: " + rows.Err().Error(),
|
||||||
|
Status: http.StatusInternalServerError,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return valuecomplexities, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package repositories
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"net/http"
|
||||||
|
"scpq-editor-server/models"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ValuetypesRepository struct {
|
||||||
|
dbHandler *sql.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewValuetypesRepository(dbHandler *sql.DB) *ValuetypesRepository {
|
||||||
|
return &ValuetypesRepository{
|
||||||
|
dbHandler: dbHandler,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rr ValuetypesRepository) GetValuetype(valuetypeId int) (*models.Valuetype, *models.ResponseError) {
|
||||||
|
query := `SELECT id, name FROM value_types WHERE id=$1`
|
||||||
|
rows, err := rr.dbHandler.Query(query, valuetypeId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, &models.ResponseError{
|
||||||
|
Message: err.Error(),
|
||||||
|
Status: http.StatusInternalServerError,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defer rows.Close()
|
||||||
|
var idstr, label string
|
||||||
|
for rows.Next() {
|
||||||
|
err := rows.Scan(&idstr, &label)
|
||||||
|
if err != nil {
|
||||||
|
return nil, &models.ResponseError{
|
||||||
|
Message: err.Error(),
|
||||||
|
Status: http.StatusInternalServerError,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if rows.Err() != nil {
|
||||||
|
return nil, &models.ResponseError{
|
||||||
|
Message: "value type id not found",
|
||||||
|
Status: http.StatusNotFound,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &models.Valuetype{
|
||||||
|
ID: valuetypeId,
|
||||||
|
Label: label,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rr ValuetypesRepository) GetAllValuetypes() ([]*models.Valuetype, *models.ResponseError) {
|
||||||
|
query := "SELECT id, label FROM value_types"
|
||||||
|
rows, err := rr.dbHandler.Query(query)
|
||||||
|
if err != nil {
|
||||||
|
return nil, &models.ResponseError{
|
||||||
|
Message: err.Error(),
|
||||||
|
Status: http.StatusInternalServerError,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defer rows.Close()
|
||||||
|
valuetypes := make([]*models.Valuetype, 0)
|
||||||
|
var idstr, label string
|
||||||
|
for rows.Next() {
|
||||||
|
err := rows.Scan(&idstr, &label)
|
||||||
|
if err != nil {
|
||||||
|
return nil, &models.ResponseError{
|
||||||
|
Message: err.Error(),
|
||||||
|
Status: http.StatusInternalServerError,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
id, err := strconv.Atoi(idstr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, &models.ResponseError{
|
||||||
|
Message: "value type id not int",
|
||||||
|
Status: http.StatusInternalServerError,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
valuetype := &models.Valuetype{
|
||||||
|
ID: id,
|
||||||
|
Label: label,
|
||||||
|
}
|
||||||
|
valuetypes = append(valuetypes, valuetype)
|
||||||
|
}
|
||||||
|
if rows.Err() != nil {
|
||||||
|
return nil, &models.ResponseError{
|
||||||
|
Message: "error iterating over value types",
|
||||||
|
Status: http.StatusInternalServerError,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return valuetypes, nil
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@ type HttpServer struct {
|
|||||||
dbHandler *sql.DB
|
dbHandler *sql.DB
|
||||||
languageController *controller.LanguagesController
|
languageController *controller.LanguagesController
|
||||||
propertygroupsController *controller.PropertygroupsController
|
propertygroupsController *controller.PropertygroupsController
|
||||||
|
valuetypesController *controller.ValuetypesController
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitHttpServer(config *viper.Viper, dbHandler *sql.DB) HttpServer {
|
func InitHttpServer(config *viper.Viper, dbHandler *sql.DB) HttpServer {
|
||||||
@@ -26,14 +27,20 @@ func InitHttpServer(config *viper.Viper, dbHandler *sql.DB) HttpServer {
|
|||||||
// repository initialisation:
|
// repository initialisation:
|
||||||
languagesRepository := repositories.NewLanguagesRepository(dbHandler)
|
languagesRepository := repositories.NewLanguagesRepository(dbHandler)
|
||||||
propertygroupsRepository := repositories.NewPropertiesgroupsRepository(dbHandler)
|
propertygroupsRepository := repositories.NewPropertiesgroupsRepository(dbHandler)
|
||||||
|
valuetypesRepository := repositories.NewValuetypesRepository(dbHandler)
|
||||||
|
valuecomplexitiesRepository := repositories.NewValuecomplexitiesRepository(dbHandler)
|
||||||
|
|
||||||
// service initialisation:
|
// service initialisation:
|
||||||
languagesService := services.NewLanguagesService(languagesRepository)
|
languagesService := services.NewLanguagesService(languagesRepository)
|
||||||
propertygroupsService := services.NewPropertygroupsService(propertygroupsRepository)
|
propertygroupsService := services.NewPropertygroupsService(propertygroupsRepository)
|
||||||
|
valuetypesService := services.NewValuetypesService(valuetypesRepository)
|
||||||
|
valuecomplexitiesService := services.NewValuecomplexitiesService(valuecomplexitiesRepository)
|
||||||
|
|
||||||
// controller initialisation:
|
// controller initialisation:
|
||||||
languageController := controller.NewLanguagesController(languagesService)
|
languageController := controller.NewLanguagesController(languagesService)
|
||||||
propertygroupsController := controller.NewPropertygroupsController(propertygroupsService)
|
propertygroupsController := controller.NewPropertygroupsController(propertygroupsService)
|
||||||
|
valuetypesController := controller.NewValuetypesController(valuetypesService)
|
||||||
|
valuecomplexitiesController := controller.NewValuecomplexitiesController(valuecomplexitiesService)
|
||||||
|
|
||||||
// Service API
|
// Service API
|
||||||
router := gin.Default()
|
router := gin.Default()
|
||||||
@@ -48,11 +55,18 @@ func InitHttpServer(config *viper.Viper, dbHandler *sql.DB) HttpServer {
|
|||||||
router.GET("/languages", languageController.GetAllLanguages)
|
router.GET("/languages", languageController.GetAllLanguages)
|
||||||
|
|
||||||
// propertygroup centric routing
|
// propertygroup centric routing
|
||||||
router.POST("/propertygroup/:parentid", propertygroupsController.CreatePropertygroup)
|
router.POST("/propertygroup", propertygroupsController.CreatePropertygroup)
|
||||||
router.PUT("/propertygroup", propertygroupsController.UpdatePropertygroup)
|
router.PUT("/propertygroup", propertygroupsController.UpdatePropertygroup)
|
||||||
router.PUT("/propertygroup/:id/change-parent/:newparentid", propertygroupsController.ChangePropertygroupParent)
|
|
||||||
router.DELETE("/propertygroup/:id", propertygroupsController.DeletePropertygroup)
|
router.DELETE("/propertygroup/:id", propertygroupsController.DeletePropertygroup)
|
||||||
router.GET("/propertygroup/:id/lang/:langid", propertygroupsController.GetPropertygroup)
|
router.GET("/propertygroup/:id", propertygroupsController.GetPropertygroup)
|
||||||
|
router.GET("/propertygroups", propertygroupsController.GetAllPropertygroups)
|
||||||
|
|
||||||
|
// valuetype centric routing
|
||||||
|
router.GET("/valuetype/:id", valuetypesController.GetValuetype)
|
||||||
|
router.GET("/valuetypes", valuetypesController.GetAllValuetypes)
|
||||||
|
|
||||||
|
// valuecomplexities centric routing
|
||||||
|
router.GET("/valuecomplexities", valuecomplexitiesController.GetAllValuecomplexities)
|
||||||
|
|
||||||
// server
|
// server
|
||||||
return HttpServer{
|
return HttpServer{
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ func NewPropertygroupsService(PropertygroupsRepository *repositories.Propertygro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ls PropertygroupsService) CreatePropertygroup(Propertygroup *models.Propertygroup, parent *models.Propertygroup) (*models.Propertygroup, *models.ResponseError) {
|
func (ls PropertygroupsService) CreatePropertygroup(Propertygroup *models.Propertygroup) (*models.Propertygroup, *models.ResponseError) {
|
||||||
responseErr := validatePropertygroup(Propertygroup)
|
responseErr := validatePropertygroup(Propertygroup)
|
||||||
if responseErr != nil {
|
if responseErr != nil {
|
||||||
return nil, responseErr
|
return nil, responseErr
|
||||||
}
|
}
|
||||||
return ls.PropertygroupsRepository.CreatePropertygroup(Propertygroup, parent)
|
return ls.PropertygroupsRepository.CreatePropertygroup(Propertygroup)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ls PropertygroupsService) UpdatePropertygroup(Propertygroup *models.Propertygroup) *models.ResponseError {
|
func (ls PropertygroupsService) UpdatePropertygroup(Propertygroup *models.Propertygroup) *models.ResponseError {
|
||||||
@@ -32,20 +32,16 @@ func (ls PropertygroupsService) UpdatePropertygroup(Propertygroup *models.Proper
|
|||||||
return ls.PropertygroupsRepository.UpdatePropertygroup(Propertygroup)
|
return ls.PropertygroupsRepository.UpdatePropertygroup(Propertygroup)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ls PropertygroupsService) ChangePropertygroupParent(Propertygroup *models.Propertygroup, opPropertygroup *models.Propertygroup, npPropertygroup *models.Propertygroup) *models.ResponseError {
|
|
||||||
responseErr := validatePropertygroup(Propertygroup)
|
|
||||||
if responseErr != nil {
|
|
||||||
return responseErr
|
|
||||||
}
|
|
||||||
return ls.PropertygroupsRepository.ChangePropertygroupParent(Propertygroup, opPropertygroup, npPropertygroup)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ls PropertygroupsService) DeletePropertygroup(PropertygroupId int) *models.ResponseError {
|
func (ls PropertygroupsService) DeletePropertygroup(PropertygroupId int) *models.ResponseError {
|
||||||
return ls.PropertygroupsRepository.DeletePropertygroup(PropertygroupId)
|
return ls.PropertygroupsRepository.DeletePropertygroup(PropertygroupId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ls PropertygroupsService) GetPropertygroup(PropertygroupId int, langId int) (*models.Propertygroup, *models.ResponseError) {
|
func (ls PropertygroupsService) GetPropertygroup(PropertygroupId int) (*models.Propertygroup, *models.ResponseError) {
|
||||||
return ls.PropertygroupsRepository.GetPropertygroup(PropertygroupId, langId)
|
return ls.PropertygroupsRepository.GetPropertygroup(PropertygroupId)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ls PropertygroupsService) GetAllPropertygroups() ([]*models.Propertygroup, *models.ResponseError) {
|
||||||
|
return ls.PropertygroupsRepository.GetAllPropertygroups()
|
||||||
}
|
}
|
||||||
|
|
||||||
func validatePropertygroup(Propertygroup *models.Propertygroup) *models.ResponseError {
|
func validatePropertygroup(Propertygroup *models.Propertygroup) *models.ResponseError {
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"scpq-editor-server/models"
|
||||||
|
"scpq-editor-server/repositories"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ValuecomplexitiesService struct {
|
||||||
|
valuecomplexitiesRepository *repositories.ValuecomplexitiesRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewValuecomplexitiesService(valuecomplexitiesRepository *repositories.ValuecomplexitiesRepository) *ValuecomplexitiesService {
|
||||||
|
return &ValuecomplexitiesService{
|
||||||
|
valuecomplexitiesRepository: valuecomplexitiesRepository,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (vs ValuecomplexitiesService) GetAllValuecomplexities() ([]*models.Valuecomplexity, *models.ResponseError) {
|
||||||
|
return vs.valuecomplexitiesRepository.GetAllValuecomplexities()
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"scpq-editor-server/models"
|
||||||
|
"scpq-editor-server/repositories"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ValuetypesService struct {
|
||||||
|
valuetypesRepository *repositories.ValuetypesRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewValuetypesService(valuetypesRepository *repositories.ValuetypesRepository) *ValuetypesService {
|
||||||
|
return &ValuetypesService{
|
||||||
|
valuetypesRepository: valuetypesRepository,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (vs ValuetypesService) GetValuetype(valuetypeId int) (*models.Valuetype, *models.ResponseError) {
|
||||||
|
return vs.valuetypesRepository.GetValuetype(valuetypeId)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (vs ValuetypesService) GetAllValuetypes() ([]*models.Valuetype, *models.ResponseError) {
|
||||||
|
return vs.valuetypesRepository.GetAllValuetypes()
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user