Restructure
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
# Database configuration
|
||||
# Connection string is in Go pq driver format:
|
||||
# host=<host> port=<port> user=<databaseUser>
|
||||
# password=<databaseUserPassword> dbname=<databaseName>
|
||||
|
||||
[database]
|
||||
connection_string = "host=localhost port=5432 user=tsindt password=XD14ko8d dbname=simply_cpq_master_data sslmode=disable"
|
||||
driver_name = "postgres"
|
||||
|
||||
################################################################
|
||||
# HTTP server configuration
|
||||
|
||||
[http]
|
||||
server_address = ":8088"
|
||||
|
||||
################################################################
|
||||
@@ -1,19 +0,0 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func InitConfig(fileName string) *viper.Viper {
|
||||
config := viper.New()
|
||||
config.SetConfigName(fileName)
|
||||
config.AddConfigPath(".")
|
||||
config.AddConfigPath("$HOME")
|
||||
err := config.ReadInConfig()
|
||||
if err != nil {
|
||||
log.Fatal("Error while parsing configuration file! ", err)
|
||||
}
|
||||
return config
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
"strconv"
|
||||
"net/http"
|
||||
"scpq-editor-server/models"
|
||||
"scpq-editor-server/services"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type LanguagesController struct {
|
||||
languagesService *services.LanguagesService
|
||||
}
|
||||
|
||||
func NewLanguagesController(languagesService *services.LanguagesService) *LanguagesController {
|
||||
return &LanguagesController{
|
||||
languagesService: languagesService,
|
||||
}
|
||||
}
|
||||
|
||||
func (lc LanguagesController) CreateLanguage(ctx *gin.Context) {
|
||||
body, err := io.ReadAll(ctx.Request.Body)
|
||||
if err != nil {
|
||||
log.Println("Error while reading create language request body", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
var language models.Language
|
||||
err = json.Unmarshal(body, &language)
|
||||
if err != nil {
|
||||
log.Println("Error while unmarshaling create runner request body",err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
response, responseErr := lc.languagesService.CreateLanguage(&language)
|
||||
if responseErr != nil {
|
||||
ctx.AbortWithStatusJSON(responseErr.Status,responseErr)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
func (lc LanguagesController) UpdateLanguage(ctx *gin.Context) {
|
||||
body, err := io.ReadAll(ctx.Request.Body)
|
||||
if err != nil {
|
||||
log.Println("Error while reading update language request body", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError,err)
|
||||
return
|
||||
}
|
||||
var language models.Language
|
||||
err = json.Unmarshal(body, &language)
|
||||
if err != nil {
|
||||
log.Println("Error while unmarshaling update language request body", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError,err)
|
||||
return
|
||||
}
|
||||
responseErr := lc.languagesService.UpdateLanguage(&language)
|
||||
if responseErr != nil {
|
||||
ctx.AbortWithStatusJSON(responseErr.Status,responseErr)
|
||||
return
|
||||
}
|
||||
ctx.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (lc LanguagesController) DeleteLanguage(ctx *gin.Context) {
|
||||
languageId := ctx.Param("id")
|
||||
lId, err := strconv.Atoi(languageId)
|
||||
if err != nil {
|
||||
log.Println("Error languageId not int", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError,err)
|
||||
return
|
||||
}
|
||||
|
||||
responseErr := lc.languagesService.DeleteLanguage(lId)
|
||||
if responseErr != nil {
|
||||
ctx.JSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (lc LanguagesController) GetLanguage(ctx *gin.Context) {
|
||||
languageId := ctx.Param("id")
|
||||
lId, err := strconv.Atoi(languageId)
|
||||
if err != nil {
|
||||
log.Println("Error languageId not int", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError,err)
|
||||
return
|
||||
}
|
||||
response, responseErr := lc.languagesService.GetLanguage(lId)
|
||||
if responseErr != nil {
|
||||
ctx.JSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
func (lc LanguagesController) GetAllLanguages(ctx *gin.Context) {
|
||||
response, responseErr := lc.languagesService.GetAllLanguages()
|
||||
if responseErr != nil {
|
||||
ctx.JSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"scpq-editor-server/models"
|
||||
"scpq-editor-server/services"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type ProductgroupsController struct {
|
||||
ProductgroupService *services.ProductgroupService
|
||||
}
|
||||
|
||||
func NewProductgroupsController(ProductgroupService *services.ProductgroupService) *ProductgroupsController {
|
||||
return &ProductgroupsController{
|
||||
ProductgroupService: ProductgroupService,
|
||||
}
|
||||
}
|
||||
|
||||
func (lc ProductgroupsController) CreateProductgroup(ctx *gin.Context) {
|
||||
|
||||
body, err := io.ReadAll(ctx.Request.Body)
|
||||
if err != nil {
|
||||
log.Println("Error while reading create Productgroup request body", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
var Productgroup models.Productgroup
|
||||
err = json.Unmarshal(body, &Productgroup)
|
||||
if err != nil {
|
||||
log.Println("Error while unmarshaling create Productgroup request body", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
response, responseErr := lc.ProductgroupService.CreateProductgroup(&Productgroup)
|
||||
if responseErr != nil {
|
||||
ctx.AbortWithStatusJSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
func (lc ProductgroupsController) UpdateProductgroup(ctx *gin.Context) {
|
||||
body, err := io.ReadAll(ctx.Request.Body)
|
||||
if err != nil {
|
||||
log.Println("Error while reading update Productgroup request body", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
var Productgroup models.Productgroup
|
||||
err = json.Unmarshal(body, &Productgroup)
|
||||
if err != nil {
|
||||
log.Println("Error while unmarshaling update Productgroup request body", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
responseErr := lc.ProductgroupService.UpdateProductgroup(&Productgroup)
|
||||
if responseErr != nil {
|
||||
ctx.AbortWithStatusJSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (lc ProductgroupsController) DeleteProductgroup(ctx *gin.Context) {
|
||||
ProductgroupId := ctx.Param("id")
|
||||
lId, err := strconv.Atoi(ProductgroupId)
|
||||
if err != nil {
|
||||
log.Println("Error ProductgroupId not int", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
responseErr := lc.ProductgroupService.DeleteProductgroup(lId)
|
||||
if responseErr != nil {
|
||||
ctx.JSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (lc ProductgroupsController) GetProductgroup(ctx *gin.Context) {
|
||||
ProductgroupId := ctx.Param("id")
|
||||
lId, err := strconv.Atoi(ProductgroupId)
|
||||
if err != nil {
|
||||
log.Println("Error ProductgroupId not int", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
response, responseErr := lc.ProductgroupService.GetProductgroup(lId)
|
||||
if responseErr != nil {
|
||||
ctx.JSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
func (lc ProductgroupsController) GetAllProductgroups(ctx *gin.Context) {
|
||||
response, responseErr := lc.ProductgroupService.GetAllProductgroups()
|
||||
if responseErr != nil {
|
||||
ctx.JSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"scpq-editor-server/models"
|
||||
"scpq-editor-server/services"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type PropertygroupsController struct {
|
||||
PropertygroupsService *services.PropertygroupsService
|
||||
}
|
||||
|
||||
func NewPropertygroupsController(PropertygroupsService *services.PropertygroupsService) *PropertygroupsController {
|
||||
return &PropertygroupsController{
|
||||
PropertygroupsService: PropertygroupsService,
|
||||
}
|
||||
}
|
||||
|
||||
func (lc PropertygroupsController) CreatePropertygroup(ctx *gin.Context) {
|
||||
|
||||
body, err := io.ReadAll(ctx.Request.Body)
|
||||
if err != nil {
|
||||
log.Println("Error while reading create 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 create runner request body", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
response, responseErr := lc.PropertygroupsService.CreatePropertygroup(&Propertygroup)
|
||||
if responseErr != nil {
|
||||
ctx.AbortWithStatusJSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
func (lc PropertygroupsController) UpdatePropertygroup(ctx *gin.Context) {
|
||||
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.UpdatePropertygroup(&Propertygroup)
|
||||
if responseErr != nil {
|
||||
ctx.AbortWithStatusJSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (lc PropertygroupsController) DeletePropertygroup(ctx *gin.Context) {
|
||||
PropertygroupId := ctx.Param("id")
|
||||
lId, err := strconv.Atoi(PropertygroupId)
|
||||
if err != nil {
|
||||
log.Println("Error PropertygroupId not int", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
responseErr := lc.PropertygroupsService.DeletePropertygroup(lId)
|
||||
if responseErr != nil {
|
||||
ctx.JSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (lc PropertygroupsController) GetPropertygroup(ctx *gin.Context) {
|
||||
PropertygroupId := ctx.Param("id")
|
||||
lId, err := strconv.Atoi(PropertygroupId)
|
||||
if err != nil {
|
||||
log.Println("Error PropertygroupId not int", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
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 {
|
||||
ctx.JSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"scpq-editor-server/models"
|
||||
"scpq-editor-server/services"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type TranslationsController struct {
|
||||
TranslationsService *services.TranslationsService
|
||||
}
|
||||
|
||||
func NewTranslationsController(TranslationsService *services.TranslationsService) *TranslationsController {
|
||||
return &TranslationsController{
|
||||
TranslationsService: TranslationsService,
|
||||
}
|
||||
}
|
||||
|
||||
func (lc TranslationsController) CreateTranslation(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 Translation models.Translation
|
||||
err = json.Unmarshal(body, &Translation)
|
||||
if err != nil {
|
||||
log.Println("Error while unmarshaling create runner request body", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
response, responseErr := lc.TranslationsService.CreateTranslation(&Translation)
|
||||
if responseErr != nil {
|
||||
ctx.AbortWithStatusJSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
func (lc TranslationsController) UpdateTranslation(ctx *gin.Context) {
|
||||
body, err := io.ReadAll(ctx.Request.Body)
|
||||
if err != nil {
|
||||
log.Println("Error while reading update Translation request body", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
var Translation models.Translation
|
||||
err = json.Unmarshal(body, &Translation)
|
||||
if err != nil {
|
||||
log.Println("Error while unmarshaling update Translation request body", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
responseErr := lc.TranslationsService.UpdateTranslation(&Translation)
|
||||
if responseErr != nil {
|
||||
ctx.AbortWithStatusJSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (lc TranslationsController) DeleteTranslation(ctx *gin.Context) {
|
||||
TranslationId := ctx.Param("id")
|
||||
lId, err := strconv.Atoi(TranslationId)
|
||||
if err != nil {
|
||||
log.Println("Error TranslationId not int", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
responseErr := lc.TranslationsService.DeleteTranslation(lId)
|
||||
if responseErr != nil {
|
||||
ctx.JSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (lc TranslationsController) GetTranslation(ctx *gin.Context) {
|
||||
TranslationId := ctx.Param("id")
|
||||
lId, err := strconv.Atoi(TranslationId)
|
||||
if err != nil {
|
||||
log.Println("Error TranslationId not int", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
response, responseErr := lc.TranslationsService.GetTranslation(lId)
|
||||
if responseErr != nil {
|
||||
ctx.JSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
func (lc TranslationsController) GetAllTranslations(ctx *gin.Context) {
|
||||
response, responseErr := lc.TranslationsService.GetAllTranslations()
|
||||
if responseErr != nil {
|
||||
ctx.JSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
func (lc TranslationsController) GetAllTranslationsByLanguageId(ctx *gin.Context) {
|
||||
languageId := ctx.Param("languageId")
|
||||
lId, err := strconv.Atoi(languageId)
|
||||
if err != nil {
|
||||
log.Println("Error languageId not int", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
response, responseErr := lc.TranslationsService.GetAllTranslationsByLanguageId(lId)
|
||||
if responseErr != nil {
|
||||
ctx.JSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
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
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
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
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
module scpq-editor-server
|
||||
|
||||
go 1.26.3
|
||||
|
||||
require (
|
||||
github.com/bytedance/gopkg v0.1.3 // indirect
|
||||
github.com/bytedance/sonic v1.15.0 // indirect
|
||||
github.com/bytedance/sonic/loader v0.5.0 // indirect
|
||||
github.com/cloudwego/base64x v0.1.6 // indirect
|
||||
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.12 // indirect
|
||||
github.com/gin-contrib/cors v1.7.7 // indirect
|
||||
github.com/gin-contrib/sse v1.1.0 // indirect
|
||||
github.com/gin-gonic/gin v1.12.0 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.30.1 // indirect
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
|
||||
github.com/goccy/go-json v0.10.5 // indirect
|
||||
github.com/goccy/go-yaml v1.19.2 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
github.com/lib/pq v1.12.3 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||
github.com/quic-go/qpack v0.6.0 // indirect
|
||||
github.com/quic-go/quic-go v0.59.0 // indirect
|
||||
github.com/sagikazarmark/locafero v0.11.0 // indirect
|
||||
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
|
||||
github.com/spf13/afero v1.15.0 // indirect
|
||||
github.com/spf13/cast v1.10.0 // indirect
|
||||
github.com/spf13/pflag v1.0.10 // indirect
|
||||
github.com/spf13/viper v1.21.0 // indirect
|
||||
github.com/subosito/gotenv v1.6.0 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.3.1 // indirect
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0 // indirect
|
||||
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
||||
golang.org/x/arch v0.23.0 // indirect
|
||||
golang.org/x/crypto v0.48.0 // indirect
|
||||
golang.org/x/net v0.51.0 // indirect
|
||||
golang.org/x/sys v0.41.0 // indirect
|
||||
golang.org/x/text v0.35.0 // indirect
|
||||
google.golang.org/protobuf v1.36.10 // indirect
|
||||
)
|
||||
@@ -1,110 +0,0 @@
|
||||
github.com/bytedance/gopkg v0.1.3 h1:TPBSwH8RsouGCBcMBktLt1AymVo2TVsBVCY4b6TnZ/M=
|
||||
github.com/bytedance/gopkg v0.1.3/go.mod h1:576VvJ+eJgyCzdjS+c4+77QF3p7ubbtiKARP3TxducM=
|
||||
github.com/bytedance/sonic v1.15.0 h1:/PXeWFaR5ElNcVE84U0dOHjiMHQOwNIx3K4ymzh/uSE=
|
||||
github.com/bytedance/sonic v1.15.0/go.mod h1:tFkWrPz0/CUCLEF4ri4UkHekCIcdnkqXw9VduqpJh0k=
|
||||
github.com/bytedance/sonic/loader v0.5.0 h1:gXH3KVnatgY7loH5/TkeVyXPfESoqSBSBEiDd5VjlgE=
|
||||
github.com/bytedance/sonic/loader v0.5.0/go.mod h1:AR4NYCk5DdzZizZ5djGqQ92eEhCCcdf5x77udYiSJRo=
|
||||
github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M=
|
||||
github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
|
||||
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
|
||||
github.com/gabriel-vasile/mimetype v1.4.12 h1:e9hWvmLYvtp846tLHam2o++qitpguFiYCKbn0w9jyqw=
|
||||
github.com/gabriel-vasile/mimetype v1.4.12/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
|
||||
github.com/gin-contrib/cors v1.7.7 h1:Oh9joP463x7Mw72vhvJ61YQm8ODh9b04YR7vsOErD0Q=
|
||||
github.com/gin-contrib/cors v1.7.7/go.mod h1:K5tW0RkzJtWSiOdikXloy8VEZlgdVNpHNw8FpjUPNrE=
|
||||
github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w=
|
||||
github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM=
|
||||
github.com/gin-gonic/gin v1.12.0 h1:b3YAbrZtnf8N//yjKeU2+MQsh2mY5htkZidOM7O0wG8=
|
||||
github.com/gin-gonic/gin v1.12.0/go.mod h1:VxccKfsSllpKshkBWgVgRniFFAzFb9csfngsqANjnLc=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||
github.com/go-playground/validator/v10 v10.30.1 h1:f3zDSN/zOma+w6+1Wswgd9fLkdwy06ntQJp0BBvFG0w=
|
||||
github.com/go-playground/validator/v10 v10.30.1/go.mod h1:oSuBIQzuJxL//3MelwSLD5hc2Tu889bF0Idm9Dg26cM=
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
|
||||
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
|
||||
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
|
||||
github.com/goccy/go-yaml v1.19.2 h1:PmFC1S6h8ljIz6gMRBopkjP1TVT7xuwrButHID66PoM=
|
||||
github.com/goccy/go-yaml v1.19.2/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
|
||||
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/lib/pq v1.12.3 h1:tTWxr2YLKwIvK90ZXEw8GP7UFHtcbTtty8zsI+YjrfQ=
|
||||
github.com/lib/pq v1.12.3/go.mod h1:/p+8NSbOcwzAEI7wiMXFlgydTwcgTr3OSKMsD2BitpA=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
|
||||
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8=
|
||||
github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII=
|
||||
github.com/quic-go/quic-go v0.59.0 h1:OLJkp1Mlm/aS7dpKgTc6cnpynnD2Xg7C1pwL6vy/SAw=
|
||||
github.com/quic-go/quic-go v0.59.0/go.mod h1:upnsH4Ju1YkqpLXC305eW3yDZ4NfnNbmQRCMWS58IKU=
|
||||
github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc=
|
||||
github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik=
|
||||
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw=
|
||||
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U=
|
||||
github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I=
|
||||
github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg=
|
||||
github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY=
|
||||
github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo=
|
||||
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
|
||||
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU=
|
||||
github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
|
||||
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||
github.com/ugorji/go/codec v1.3.1 h1:waO7eEiFDwidsBN6agj1vJQ4AG7lh2yqXyOXqhgQuyY=
|
||||
github.com/ugorji/go/codec v1.3.1/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0=
|
||||
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
|
||||
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||
golang.org/x/arch v0.22.0 h1:c/Zle32i5ttqRXjdLyyHZESLD/bB90DCU1g9l/0YBDI=
|
||||
golang.org/x/arch v0.22.0/go.mod h1:dNHoOeKiyja7GTvF9NJS1l3Z2yntpQNzgrjh1cU103A=
|
||||
golang.org/x/arch v0.23.0 h1:lKF64A2jF6Zd8L0knGltUnegD62JMFBiCPBmQpToHhg=
|
||||
golang.org/x/arch v0.23.0/go.mod h1:dNHoOeKiyja7GTvF9NJS1l3Z2yntpQNzgrjh1cU103A=
|
||||
golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts=
|
||||
golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos=
|
||||
golang.org/x/net v0.51.0 h1:94R/GTO7mt3/4wIKpcR5gkGmRLOuE/2hNGeWq/GBIFo=
|
||||
golang.org/x/net v0.51.0/go.mod h1:aamm+2QF5ogm02fjy5Bb7CQ0WMt1/WVM7FtyaTLlA9Y=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
|
||||
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
|
||||
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
|
||||
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
|
||||
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
|
||||
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
|
||||
golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8=
|
||||
golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA=
|
||||
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
|
||||
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
@@ -1,21 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
_ "github.com/lib/pq"
|
||||
"scpq-editor-server/config"
|
||||
"scpq-editor-server/server"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.Println("Starting Simply CPQ Editor Service")
|
||||
log.Println("Reading configuration")
|
||||
config := config.InitConfig("config")
|
||||
log.Println("Initializing database")
|
||||
dbHandler := server.InitDatabase(config)
|
||||
log.Println("Initializing HTTP server")
|
||||
httpServer := server.InitHttpServer(config, dbHandler)
|
||||
httpServer.Start()
|
||||
|
||||
log.Println("Service Stopped")
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package models
|
||||
|
||||
type Language struct {
|
||||
ID int `json:"id"`
|
||||
Locale string `json:"locale"`
|
||||
Language string `json:"language"`
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package models
|
||||
|
||||
type Product struct {
|
||||
ID int `json:"id"`
|
||||
Label string `json:"label"`
|
||||
ProductIdentifier string `json:"product_identifier"`
|
||||
Properties []Property `json:"properties"`
|
||||
Products []Product `json:"products"`
|
||||
ProductStructureNodes []ProductStructureNode `json:"productStructureNodes"`
|
||||
IsEqualPropertiesEqualValues bool `json:"isEqualPropertiesEqualValues"`
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package models
|
||||
|
||||
type ProductStructureNode struct {
|
||||
ID int `json:"id"`
|
||||
Label string `json:"label"`
|
||||
IsOneOfStructure bool `json:"isOneOfStructure"`
|
||||
Products []Product `json:"products"`
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package models
|
||||
|
||||
type Productgroup struct {
|
||||
ID int `json:"id"`
|
||||
Label string `json:"label"`
|
||||
ParentProductGroupID int `json:"parentProductGroupID"`
|
||||
IsVisible bool `json:"isVisible"`
|
||||
Path string `json:"path"`
|
||||
ChildProductGroups []Productgroup `json:"childProductGroups"`
|
||||
PropertyTypes []PropertyType `json:"propertyTypes"`
|
||||
Products []Product `json:"products"`
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package models
|
||||
|
||||
type Property struct {
|
||||
ID int `json:"id"`
|
||||
Value string `json:"value"`
|
||||
PropertyTypeId int `json:"propertyTypeID"`
|
||||
IsTerminal bool `json:"isTerminal"`
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package models
|
||||
|
||||
type Propertygroup struct {
|
||||
ID int `json:"id"`
|
||||
Label string `json:"label"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
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"`
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package models
|
||||
|
||||
type ResponseError struct {
|
||||
Message string `json:"message"`
|
||||
Status int `json:"-"`
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package models
|
||||
|
||||
type Translation struct {
|
||||
ID int `json:"id"`
|
||||
LanguageID int `json:"language_id"`
|
||||
Original string `json:"original"`
|
||||
Translated string `json:"translated"`
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package models
|
||||
|
||||
type Valuecomplexity struct {
|
||||
ID int `json:"id"`
|
||||
Complexity string `json:"complexity"`
|
||||
Valuedefinition string `json:"valuedefinition"`
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package models
|
||||
|
||||
type Valuetype struct {
|
||||
ID int `json:"id"`
|
||||
Label string `json:"label"`
|
||||
}
|
||||
@@ -1,196 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"net/http"
|
||||
"scpq-editor-server/models"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type LanguagesRepository struct {
|
||||
dbHandler *sql.DB
|
||||
}
|
||||
|
||||
func NewLanguagesRepository(dbHandler *sql.DB) *LanguagesRepository {
|
||||
return &LanguagesRepository{
|
||||
dbHandler: dbHandler,
|
||||
}
|
||||
}
|
||||
|
||||
func (rr LanguagesRepository) CreateLanguage(language *models.Language) (*models.Language, *models.ResponseError) {
|
||||
query := `INSERT INTO languages(locale, language) VALUES($1,$2) RETURNING id`
|
||||
rows, err := rr.dbHandler.Query(query, language.Locale, language.Language)
|
||||
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,
|
||||
}
|
||||
}
|
||||
languageId, err := strconv.Atoi(idstr)
|
||||
if err != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: "language id not int",
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
|
||||
return &models.Language{
|
||||
ID: languageId,
|
||||
Locale: language.Locale,
|
||||
Language: language.Language,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (rr LanguagesRepository) UpdateLanguage(language *models.Language) *models.ResponseError {
|
||||
query := `UPDATE languages SET locale=$1, language=$2 WHERE id=$3`
|
||||
res, err := rr.dbHandler.Exec(query, language.Locale, language.Language, language.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 language found with the given id",
|
||||
Status: http.StatusNotFound,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (rr LanguagesRepository) DeleteLanguage(languageId int) *models.ResponseError {
|
||||
query := `DELETE FROM languages WHERE id=$1`
|
||||
res, err := rr.dbHandler.Exec(query, languageId)
|
||||
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 language found with the given id",
|
||||
Status: http.StatusNotFound,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rr LanguagesRepository) GetLanguage(languageId int) (*models.Language, *models.ResponseError) {
|
||||
query := `SELECT id, locale, language FROM languages WHERE id=$1`
|
||||
rows, err := rr.dbHandler.Query(query, languageId)
|
||||
if err != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: err.Error(),
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
|
||||
defer rows.Close()
|
||||
var idstr, locale, language string
|
||||
for rows.Next() {
|
||||
err := rows.Scan(&idstr, &locale, &language)
|
||||
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,
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: "language id not int",
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
|
||||
return &models.Language{
|
||||
ID: languageId,
|
||||
Locale: locale,
|
||||
Language: language,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (rr LanguagesRepository) GetAllLanguages() ([]*models.Language, *models.ResponseError) {
|
||||
query := "SELECT id, locale, language FROM languages"
|
||||
rows, err := rr.dbHandler.Query(query)
|
||||
if err != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: err.Error(),
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
|
||||
defer rows.Close()
|
||||
languages := make([]*models.Language, 0)
|
||||
var idstr, locale, language string
|
||||
for rows.Next() {
|
||||
err := rows.Scan(&idstr, &locale, &language)
|
||||
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: "language id not int",
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
language := &models.Language{
|
||||
ID: id,
|
||||
Locale: locale,
|
||||
Language: language,
|
||||
}
|
||||
languages = append(languages, language)
|
||||
}
|
||||
if rows.Err() != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: err.Error(),
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
return languages, nil
|
||||
}
|
||||
@@ -1,460 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"log"
|
||||
"net/http"
|
||||
"scpq-editor-server/models"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type ProductgroupRepository struct {
|
||||
dbHandler *sql.DB
|
||||
propertyTypesRepository *PropertyTypesRepository
|
||||
m map[int]*models.Productgroup
|
||||
}
|
||||
|
||||
func NewProductgroupRepository(dbHandler *sql.DB, propertyTypesRepository *PropertyTypesRepository) *ProductgroupRepository {
|
||||
return &ProductgroupRepository{
|
||||
dbHandler: dbHandler,
|
||||
propertyTypesRepository: NewPropertyTypesRepository(dbHandler),
|
||||
m: make(map[int]*models.Productgroup),
|
||||
}
|
||||
}
|
||||
|
||||
func (rr ProductgroupRepository) CreateProductgroup(Productgroup *models.Productgroup) (*models.Productgroup, *models.ResponseError) {
|
||||
query := `INSERT INTO product_groups(label, parent_group_id, is_visible, path) VALUES($1,$2, $3, $4) RETURNING id`
|
||||
rows, err := rr.dbHandler.Query(query, Productgroup.Label, Productgroup.ParentProductGroupID, Productgroup.IsVisible, Productgroup.Path)
|
||||
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,
|
||||
}
|
||||
}
|
||||
ProductgroupId, err := strconv.Atoi(idstr)
|
||||
if err != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: "Productgroup id not int",
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
|
||||
pg := &models.Productgroup{
|
||||
ID: ProductgroupId,
|
||||
Label: Productgroup.Label,
|
||||
ParentProductGroupID: Productgroup.ParentProductGroupID,
|
||||
IsVisible: Productgroup.IsVisible,
|
||||
Path: Productgroup.Path,
|
||||
}
|
||||
|
||||
addToParentErr := rr.addToParentProductGroup(pg)
|
||||
if addToParentErr != nil {
|
||||
return nil, addToParentErr
|
||||
}
|
||||
|
||||
rr.m[pg.ID] = pg
|
||||
return pg, nil
|
||||
}
|
||||
|
||||
func (rr ProductgroupRepository) UpdateProductgroup(Productgroup *models.Productgroup) *models.ResponseError {
|
||||
query := `UPDATE product_groups SET label=$1, parent_group_id=$2, is_visible=$3, path=$4 WHERE id=$5`
|
||||
res, err := rr.dbHandler.Exec(query, Productgroup.Label, Productgroup.ParentProductGroupID, Productgroup.IsVisible, Productgroup.Path, Productgroup.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 Productgroup found with the given id",
|
||||
Status: http.StatusNotFound,
|
||||
}
|
||||
}
|
||||
rr.m[Productgroup.ID] = Productgroup
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rr ProductgroupRepository) DeleteProductgroup(ProductgroupId int) *models.ResponseError {
|
||||
|
||||
// get sub product groups
|
||||
subProductGroups, err2 := rr.GetSubProductgroups(ProductgroupId)
|
||||
if err2 != nil {
|
||||
return &models.ResponseError{
|
||||
Message: err2.Message,
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
for _, spg := range subProductGroups {
|
||||
rr.DeleteProductgroup(spg.ID)
|
||||
}
|
||||
|
||||
pg1, err2 := rr.GetProductgroup(ProductgroupId)
|
||||
if pg1 != nil {
|
||||
parentPG, _ := rr.GetProductgroup(pg1.ParentProductGroupID)
|
||||
rr.RemoveProductGroupFromParentGroup(parentPG, pg1)
|
||||
}
|
||||
|
||||
query := `DELETE FROM product_groups WHERE id=$1`
|
||||
res, err := rr.dbHandler.Exec(query, ProductgroupId)
|
||||
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 Productgroup found with the given id",
|
||||
Status: http.StatusNotFound,
|
||||
}
|
||||
}
|
||||
delete(rr.m, ProductgroupId)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rr ProductgroupRepository) GetProductgroup(ProductgroupId int) (*models.Productgroup, *models.ResponseError) {
|
||||
|
||||
if pg, exists := rr.m[ProductgroupId]; exists {
|
||||
return pg, nil
|
||||
}
|
||||
|
||||
query := `SELECT id, label, parent_group_id, is_visible, path FROM product_groups WHERE id=$1`
|
||||
rows, err := rr.dbHandler.Query(query, ProductgroupId)
|
||||
if err != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: err.Error(),
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
|
||||
defer rows.Close()
|
||||
var idstr, label, parentProductGroupIDstr, path string
|
||||
var isVisible bool
|
||||
for rows.Next() {
|
||||
err := rows.Scan(&idstr, &label, &parentProductGroupIDstr, &isVisible, &path)
|
||||
if err != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: err.Error(),
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
}
|
||||
if rows.Err() != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: "product group id not found",
|
||||
Status: http.StatusNotFound,
|
||||
}
|
||||
}
|
||||
id, err := strconv.Atoi(idstr)
|
||||
if err != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: "Productgroup id not int",
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
parentProductGroupID, err := strconv.Atoi(parentProductGroupIDstr)
|
||||
if err != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: "Parent Productgroup id not int",
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
|
||||
pg := &models.Productgroup{
|
||||
ID: id,
|
||||
Label: label,
|
||||
ParentProductGroupID: parentProductGroupID,
|
||||
IsVisible: isVisible,
|
||||
Path: path,
|
||||
}
|
||||
|
||||
// get sub product groups
|
||||
subProductGroups, err2 := rr.GetSubProductgroups(pg.ID)
|
||||
if err2 != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: err2.Message,
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
for _, spg := range subProductGroups {
|
||||
pg.ChildProductGroups = append(pg.ChildProductGroups, *spg)
|
||||
}
|
||||
|
||||
// get property types of this product group
|
||||
propertyTypes, err3 := rr.GetPropertyTypesByProductGroup(pg)
|
||||
if err3 != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: err3.Message,
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
for _, pt := range propertyTypes {
|
||||
pg.PropertyTypes = append(pg.PropertyTypes, *pt)
|
||||
}
|
||||
|
||||
// TODO: get products of this product group
|
||||
|
||||
rr.m[pg.ID] = pg
|
||||
return pg, nil
|
||||
}
|
||||
|
||||
func (rr ProductgroupRepository) GetPropertyTypesByProductGroup(productGroup *models.Productgroup) ([]*models.PropertyType, *models.ResponseError) {
|
||||
if productGroup.Label == "Simply CPQ" {
|
||||
return rr.GetPropertyTypesByProductGroupID(productGroup.ID)
|
||||
} else {
|
||||
PropertyTypesParent, err := rr.GetPropertyTypesByProductGroupID(productGroup.ParentProductGroupID)
|
||||
if err != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: err.Message,
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
PropertyTypesChild, err := rr.GetPropertyTypesByProductGroupID(productGroup.ID)
|
||||
if err != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: err.Message,
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
|
||||
return append(PropertyTypesParent, PropertyTypesChild...), nil
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (rr ProductgroupRepository) GetPropertyTypesByProductGroupID(productGroupID int) ([]*models.PropertyType, *models.ResponseError) {
|
||||
var propertyTypes []*models.PropertyType
|
||||
query := `SELECT property_type_id FROM product_group_property_types_list WHERE product_group_id=$1`
|
||||
rows, err := rr.dbHandler.Query(query, productGroupID)
|
||||
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,
|
||||
}
|
||||
}
|
||||
id, err := strconv.Atoi(idstr)
|
||||
if err != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: "PropertyType id not int " + idstr,
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
pt, err2 := rr.propertyTypesRepository.GetPropertyType(id)
|
||||
if err2 != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: "PropertyType not found with the given id " + idstr,
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
if pt != nil {
|
||||
propertyTypes = append(propertyTypes, pt)
|
||||
}
|
||||
}
|
||||
if rows.Err() != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: rows.Err().Error(),
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
|
||||
return propertyTypes, nil
|
||||
}
|
||||
|
||||
func (rr ProductgroupRepository) GetSubProductgroups(ProductgroupId int) ([]*models.Productgroup, *models.ResponseError) {
|
||||
var Productgroups []*models.Productgroup
|
||||
query := `SELECT id FROM product_groups WHERE parent_group_id=$1`
|
||||
|
||||
rows, err := rr.dbHandler.Query(query, ProductgroupId)
|
||||
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,
|
||||
}
|
||||
}
|
||||
id, err := strconv.Atoi(idstr)
|
||||
if err != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: "Productgroup id not int " + idstr,
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
pg, err2 := rr.GetProductgroup(id)
|
||||
if err2 != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: "Productgroup not found with the given id " + idstr,
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
if pg != nil {
|
||||
rr.m[pg.ID] = pg
|
||||
Productgroups = append(Productgroups, pg)
|
||||
}
|
||||
}
|
||||
if rows.Err() != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: rows.Err().Error(),
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
return Productgroups, nil
|
||||
}
|
||||
|
||||
func (rr ProductgroupRepository) GetAllProductgroups() ([]*models.Productgroup, *models.ResponseError) {
|
||||
var Productgroups []*models.Productgroup
|
||||
query := `SELECT id FROM product_groups`
|
||||
rows, err := rr.dbHandler.Query(query)
|
||||
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)
|
||||
log.Println("Productgroup id", idstr)
|
||||
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: "Productgroup id not int " + idstr,
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
pg, err2 := rr.GetProductgroup(id)
|
||||
if err2 != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: "Productgroup not found with the given id " + idstr,
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
if pg != nil {
|
||||
rr.m[pg.ID] = pg
|
||||
Productgroups = append(Productgroups, pg)
|
||||
}
|
||||
|
||||
}
|
||||
if rows.Err() != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: rows.Err().Error(),
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
return Productgroups, nil
|
||||
}
|
||||
|
||||
func (rr ProductgroupRepository) RemoveProductGroupFromParentGroup(parentProductGroup *models.Productgroup, childProductGroup *models.Productgroup) *models.ResponseError {
|
||||
query := `UPDATE product_groups SET parent_group_id=NULL WHERE id=$1`
|
||||
_, err := rr.dbHandler.Exec(query, childProductGroup.ID)
|
||||
if err != nil {
|
||||
return &models.ResponseError{
|
||||
Message: err.Error(),
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
// Remove child from parent's ChildProductGroups slice
|
||||
for i, cpg := range parentProductGroup.ChildProductGroups {
|
||||
if cpg.ID == childProductGroup.ID {
|
||||
parentProductGroup.ChildProductGroups = append(parentProductGroup.ChildProductGroups[:i], parentProductGroup.ChildProductGroups[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
rr.m[parentProductGroup.ID] = parentProductGroup
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rr ProductgroupRepository) addToParentProductGroup(ProductGroup *models.Productgroup) *models.ResponseError {
|
||||
Query := `UPDATE product_groups SET parent_group_id=$1 WHERE id=$2`
|
||||
_, err := rr.dbHandler.Exec(Query, ProductGroup.ParentProductGroupID, ProductGroup.ID)
|
||||
if err != nil {
|
||||
return &models.ResponseError{
|
||||
Message: err.Error(),
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
ParentProductGroup, err2 := rr.GetProductgroup(ProductGroup.ParentProductGroupID)
|
||||
if err2 != nil {
|
||||
return &models.ResponseError{
|
||||
Message: "Parent Productgroup not found with the given id " + strconv.Itoa(ProductGroup.ParentProductGroupID),
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
ParentProductGroup.ChildProductGroups = append(ParentProductGroup.ChildProductGroups, *ProductGroup)
|
||||
propertyTypes, err3 := rr.GetPropertyTypesByProductGroupID(ParentProductGroup.ID)
|
||||
if err3 != nil {
|
||||
return &models.ResponseError{
|
||||
Message: err3.Message,
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
for _, pt := range propertyTypes {
|
||||
ProductGroup.PropertyTypes = append(ProductGroup.PropertyTypes, *pt)
|
||||
}
|
||||
|
||||
rr.m[ParentProductGroup.ID] = ParentProductGroup
|
||||
return nil
|
||||
}
|
||||
@@ -1,299 +0,0 @@
|
||||
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,
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
@@ -1,234 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"log"
|
||||
"net/http"
|
||||
"scpq-editor-server/models"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type PropertygroupsRepository struct {
|
||||
dbHandler *sql.DB
|
||||
m map[int]*models.Propertygroup
|
||||
}
|
||||
|
||||
func NewPropertiesgroupsRepository(dbHandler *sql.DB) *PropertygroupsRepository {
|
||||
return &PropertygroupsRepository{
|
||||
dbHandler: dbHandler,
|
||||
m: make(map[int]*models.Propertygroup),
|
||||
}
|
||||
}
|
||||
|
||||
func (rr PropertygroupsRepository) CreatePropertygroup(Propertygroup *models.Propertygroup) (*models.Propertygroup, *models.ResponseError) {
|
||||
query := `INSERT INTO property_groups(label, description) VALUES($1,$2) RETURNING id`
|
||||
rows, err := rr.dbHandler.Query(query, Propertygroup.Label, Propertygroup.Description)
|
||||
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,
|
||||
}
|
||||
}
|
||||
PropertygroupId, err := strconv.Atoi(idstr)
|
||||
if err != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: "Propertygroup id not int",
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
|
||||
pg := &models.Propertygroup{
|
||||
ID: PropertygroupId,
|
||||
Label: Propertygroup.Label,
|
||||
Description: Propertygroup.Description,
|
||||
}
|
||||
|
||||
rr.m[pg.ID] = pg
|
||||
return pg, nil
|
||||
}
|
||||
|
||||
func (rr PropertygroupsRepository) UpdatePropertygroup(Propertygroup *models.Propertygroup) *models.ResponseError {
|
||||
query := `UPDATE property_groups SET label=$1, description=$2 WHERE id=$3`
|
||||
res, err := rr.dbHandler.Exec(query, Propertygroup.Label, Propertygroup.Description, 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,
|
||||
}
|
||||
}
|
||||
rr.m[Propertygroup.ID] = Propertygroup
|
||||
return nil
|
||||
}
|
||||
|
||||
func findIndex(slice []*models.Propertygroup, target models.Propertygroup) int {
|
||||
for i, v := range slice {
|
||||
if v.ID == target.ID {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func RemoveAt[T any](slice []T, index int) []T {
|
||||
return append(slice[:index], slice[index+1:]...)
|
||||
}
|
||||
|
||||
func (rr PropertygroupsRepository) DeletePropertygroup(PropertygroupId int) *models.ResponseError {
|
||||
query := `DELETE FROM property_groups WHERE id=$1`
|
||||
res, err := rr.dbHandler.Exec(query, PropertygroupId)
|
||||
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,
|
||||
}
|
||||
}
|
||||
rr.m[PropertygroupId] = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rr PropertygroupsRepository) GetPropertygroup(PropertygroupId int) (*models.Propertygroup, *models.ResponseError) {
|
||||
|
||||
if pg, exists := rr.m[PropertygroupId]; exists {
|
||||
return pg, nil
|
||||
}
|
||||
|
||||
query := `SELECT id, label, description FROM property_groups WHERE 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()
|
||||
var idstr, label, description string
|
||||
for rows.Next() {
|
||||
err := rows.Scan(&idstr, &label, &description)
|
||||
if err != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: err.Error(),
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
}
|
||||
if rows.Err() != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: "property group id not found",
|
||||
Status: http.StatusNotFound,
|
||||
}
|
||||
}
|
||||
id, err := strconv.Atoi(idstr)
|
||||
if err != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: "Propertygroup id not int",
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
|
||||
pg := &models.Propertygroup{
|
||||
ID: id,
|
||||
Label: label,
|
||||
Description: description,
|
||||
}
|
||||
|
||||
rr.m[pg.ID] = pg
|
||||
return pg, nil
|
||||
}
|
||||
|
||||
func (rr PropertygroupsRepository) GetAllPropertygroups() ([]*models.Propertygroup, *models.ResponseError) {
|
||||
var Propertygroups []*models.Propertygroup
|
||||
query := `SELECT id FROM property_groups`
|
||||
rows, err := rr.dbHandler.Query(query)
|
||||
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)
|
||||
log.Println("Propertygroup id", idstr)
|
||||
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: "Propertygroup id not int " + idstr,
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
pg, err2 := rr.GetPropertygroup(id)
|
||||
if err2 != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: "Propertygroup not found with the given id " + idstr,
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
if pg != nil {
|
||||
rr.m[pg.ID] = pg
|
||||
Propertygroups = append(Propertygroups, pg)
|
||||
}
|
||||
|
||||
}
|
||||
if rows.Err() != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: rows.Err().Error(),
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
return Propertygroups, nil
|
||||
}
|
||||
@@ -1,254 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"net/http"
|
||||
"scpq-editor-server/models"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type TranslationsRepository struct {
|
||||
dbHandler *sql.DB
|
||||
}
|
||||
|
||||
func NewTranslationsRepository(dbHandler *sql.DB) *TranslationsRepository {
|
||||
return &TranslationsRepository{
|
||||
dbHandler: dbHandler,
|
||||
}
|
||||
}
|
||||
|
||||
func (rr TranslationsRepository) CreateTranslation(Translation *models.Translation) (*models.Translation, *models.ResponseError) {
|
||||
query := `INSERT INTO Translations(language_id, original, translated ) VALUES($1,$2,$3) RETURNING id`
|
||||
rows, err := rr.dbHandler.Query(query, Translation.LanguageID, Translation.Original, Translation.Translated)
|
||||
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,
|
||||
}
|
||||
}
|
||||
TranslationId, err := strconv.Atoi(idstr)
|
||||
if err != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: "Translation id not int",
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
|
||||
return &models.Translation{
|
||||
ID: TranslationId,
|
||||
LanguageID: Translation.LanguageID,
|
||||
Original: Translation.Original,
|
||||
Translated: Translation.Translated,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (rr TranslationsRepository) UpdateTranslation(Translation *models.Translation) *models.ResponseError {
|
||||
query := `UPDATE Translations SET language_id=$1, original=$2, translated=$3 WHERE id=$4`
|
||||
res, err := rr.dbHandler.Exec(query, Translation.LanguageID, Translation.Original, Translation.Translated, Translation.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 Translation found with the given id",
|
||||
Status: http.StatusNotFound,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (rr TranslationsRepository) DeleteTranslation(TranslationId int) *models.ResponseError {
|
||||
query := `DELETE FROM Translations WHERE id=$1`
|
||||
res, err := rr.dbHandler.Exec(query, TranslationId)
|
||||
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 Translation found with the given id",
|
||||
Status: http.StatusNotFound,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rr TranslationsRepository) GetTranslation(TranslationId int) (*models.Translation, *models.ResponseError) {
|
||||
query := `SELECT id, language_id, original, translated FROM Translations WHERE id=$1`
|
||||
rows, err := rr.dbHandler.Query(query, TranslationId)
|
||||
if err != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: err.Error(),
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
|
||||
defer rows.Close()
|
||||
var idstr, language_id_str, original, translated string
|
||||
for rows.Next() {
|
||||
err := rows.Scan(&idstr, &language_id_str, &original, &translated)
|
||||
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,
|
||||
}
|
||||
}
|
||||
languageId, err := strconv.Atoi(language_id_str)
|
||||
if err != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: "Translation id not int",
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
|
||||
return &models.Translation{
|
||||
ID: TranslationId,
|
||||
LanguageID: languageId,
|
||||
Original: original,
|
||||
Translated: translated,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (rr TranslationsRepository) GetAllTranslations() ([]*models.Translation, *models.ResponseError) {
|
||||
query := "SELECT id, language_id, original, translated FROM Translations"
|
||||
rows, err := rr.dbHandler.Query(query)
|
||||
if err != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: err.Error(),
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
|
||||
defer rows.Close()
|
||||
Translations := make([]*models.Translation, 0)
|
||||
var idstr, language_id_str, original, translated string
|
||||
for rows.Next() {
|
||||
err := rows.Scan(&idstr, &language_id_str, &original, &translated)
|
||||
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: "Translation id not int",
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
languageId, err := strconv.Atoi(language_id_str)
|
||||
if err != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: "Translation id not int",
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
Translation := &models.Translation{
|
||||
ID: id,
|
||||
LanguageID: languageId,
|
||||
Original: original,
|
||||
Translated: translated,
|
||||
}
|
||||
Translations = append(Translations, Translation)
|
||||
|
||||
}
|
||||
if rows.Err() != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: err.Error(),
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
return Translations, nil
|
||||
}
|
||||
|
||||
func (rr TranslationsRepository) GetAllTranslationsByLanguageID(languageId int) ([]*models.Translation, *models.ResponseError) {
|
||||
query := "SELECT id, original, translated FROM Translations WHERE language_id=$1"
|
||||
rows, err := rr.dbHandler.Query(query, languageId)
|
||||
if err != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: err.Error(),
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
|
||||
defer rows.Close()
|
||||
Translations := make([]*models.Translation, 0)
|
||||
var idstr, original, translated string
|
||||
for rows.Next() {
|
||||
err := rows.Scan(&idstr, &original, &translated)
|
||||
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: "Translation id not int",
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
Translation := &models.Translation{
|
||||
ID: id,
|
||||
LanguageID: languageId,
|
||||
Original: original,
|
||||
Translated: translated,
|
||||
}
|
||||
Translations = append(Translations, Translation)
|
||||
|
||||
}
|
||||
if rows.Err() != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: err.Error(),
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
return Translations, nil
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
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
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
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
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"log"
|
||||
"database/sql"
|
||||
"github.com/spf13/viper"
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
func InitDatabase(config *viper.Viper) *sql.DB {
|
||||
connectionString := config.GetString("database.connection_string")
|
||||
driverName := config.GetString("database.driver_name")
|
||||
if connectionString == "" {
|
||||
log.Fatalf("Database connection string is missing")
|
||||
}
|
||||
dbHandler, err := sql.Open(driverName, connectionString)
|
||||
if err != nil {
|
||||
log.Fatalf("Error while initializing database: %v", err)
|
||||
}
|
||||
err = dbHandler.Ping()
|
||||
if err != nil {
|
||||
dbHandler.Close()
|
||||
log.Fatalf("Error while validating database: %v", err)
|
||||
}
|
||||
return dbHandler
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"log"
|
||||
"net/http"
|
||||
"scpq-editor-server/controller"
|
||||
"scpq-editor-server/repositories"
|
||||
"scpq-editor-server/services"
|
||||
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type HttpServer struct {
|
||||
config *viper.Viper
|
||||
router *gin.Engine
|
||||
dbHandler *sql.DB
|
||||
languageController *controller.LanguagesController
|
||||
propertygroupsController *controller.PropertygroupsController
|
||||
valuetypesController *controller.ValuetypesController
|
||||
}
|
||||
|
||||
func InitHttpServer(config *viper.Viper, dbHandler *sql.DB) HttpServer {
|
||||
|
||||
// repository initialisation:
|
||||
languagesRepository := repositories.NewLanguagesRepository(dbHandler)
|
||||
propertygroupsRepository := repositories.NewPropertiesgroupsRepository(dbHandler)
|
||||
valuetypesRepository := repositories.NewValuetypesRepository(dbHandler)
|
||||
valuecomplexitiesRepository := repositories.NewValuecomplexitiesRepository(dbHandler)
|
||||
translationsRepository := repositories.NewTranslationsRepository(dbHandler)
|
||||
propertytypesRepository := repositories.NewPropertyTypesRepository(dbHandler)
|
||||
productgroupRepository := repositories.NewProductgroupRepository(dbHandler, propertytypesRepository)
|
||||
|
||||
// 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)
|
||||
productgroupService := services.NewProductgroupService(productgroupRepository)
|
||||
|
||||
// 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)
|
||||
productgroupsController := controller.NewProductgroupsController(productgroupService)
|
||||
|
||||
// Service API
|
||||
router := gin.Default()
|
||||
router.Use(cors.Default())
|
||||
router.GET("/test", Test)
|
||||
|
||||
// language centric routing
|
||||
router.POST("/language", languageController.CreateLanguage)
|
||||
router.PUT("/language", languageController.UpdateLanguage)
|
||||
router.DELETE("/language/:id", languageController.DeleteLanguage)
|
||||
router.GET("/language/:id", languageController.GetLanguage)
|
||||
router.GET("/languages", languageController.GetAllLanguages)
|
||||
|
||||
// propertygroup centric routing
|
||||
router.POST("/propertygroup", propertygroupsController.CreatePropertygroup)
|
||||
router.PUT("/propertygroup", propertygroupsController.UpdatePropertygroup)
|
||||
router.DELETE("/propertygroup/:id", propertygroupsController.DeletePropertygroup)
|
||||
router.GET("/propertygroup/:id", propertygroupsController.GetPropertygroup)
|
||||
router.GET("/propertygroups", propertygroupsController.GetAllPropertygroups)
|
||||
|
||||
// productgroup centric routing
|
||||
router.POST("/productgroup", productgroupsController.CreateProductgroup)
|
||||
router.PUT("/productgroup", productgroupsController.UpdateProductgroup)
|
||||
router.DELETE("/productgroup/:id", productgroupsController.DeleteProductgroup)
|
||||
router.GET("/productgroup/:id", productgroupsController.GetProductgroup)
|
||||
router.GET("/productgroups", productgroupsController.GetAllProductgroups)
|
||||
|
||||
// translation centric routing
|
||||
router.POST("/translation", translationsController.CreateTranslation)
|
||||
router.PUT("/translation", translationsController.UpdateTranslation)
|
||||
router.DELETE("/translation/:id", translationsController.DeleteTranslation)
|
||||
router.GET("/translation/:id", translationsController.GetTranslation)
|
||||
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)
|
||||
|
||||
// valuecomplexities centric routing
|
||||
router.GET("/valuecomplexities", valuecomplexitiesController.GetAllValuecomplexities)
|
||||
|
||||
// server
|
||||
return HttpServer{
|
||||
config: config,
|
||||
router: router,
|
||||
dbHandler: dbHandler,
|
||||
}
|
||||
}
|
||||
|
||||
func (hs HttpServer) Start() {
|
||||
err := hs.router.Run(hs.config.GetString("http.server_address"))
|
||||
if err != nil {
|
||||
log.Fatalf("Error while starting HTTP server: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func Test(ctx *gin.Context) {
|
||||
ctx.JSON(http.StatusOK, gin.H{
|
||||
"message": "Test",
|
||||
})
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"scpq-editor-server/models"
|
||||
"scpq-editor-server/repositories"
|
||||
)
|
||||
|
||||
type LanguagesService struct {
|
||||
languagesRepository *repositories.LanguagesRepository
|
||||
}
|
||||
|
||||
func NewLanguagesService(languagesRepository *repositories.LanguagesRepository) *LanguagesService {
|
||||
return &LanguagesService {
|
||||
languagesRepository: languagesRepository,
|
||||
}
|
||||
}
|
||||
|
||||
func (ls LanguagesService) CreateLanguage(language *models.Language) (*models.Language, *models.ResponseError) {
|
||||
responseErr := validateLanguage(language)
|
||||
if responseErr != nil {
|
||||
return nil, responseErr
|
||||
}
|
||||
return ls.languagesRepository.CreateLanguage(language)
|
||||
}
|
||||
|
||||
func (ls LanguagesService) UpdateLanguage(language *models.Language) *models.ResponseError {
|
||||
responseErr := validateLanguage(language)
|
||||
if responseErr != nil {
|
||||
return responseErr
|
||||
}
|
||||
return ls.languagesRepository.UpdateLanguage(language)
|
||||
}
|
||||
|
||||
func (ls LanguagesService) DeleteLanguage(languageId int) *models.ResponseError {
|
||||
return ls.languagesRepository.DeleteLanguage(languageId)
|
||||
}
|
||||
|
||||
func (ls LanguagesService) GetLanguage(languageId int) (*models.Language, *models.ResponseError) {
|
||||
return ls.languagesRepository.GetLanguage(languageId)
|
||||
}
|
||||
|
||||
func (ls LanguagesService) GetAllLanguages() ([]*models.Language, *models.ResponseError) {
|
||||
return ls.languagesRepository.GetAllLanguages()
|
||||
}
|
||||
|
||||
func validateLanguage(language *models.Language) *models.ResponseError {
|
||||
if language.Locale == "" {
|
||||
return &models.ResponseError{
|
||||
Message: "Invalid locale",
|
||||
Status: http.StatusBadRequest,
|
||||
}
|
||||
}
|
||||
if language.Language == "" {
|
||||
return &models.ResponseError{
|
||||
Message: "Invalid language label",
|
||||
Status: http.StatusBadRequest,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"scpq-editor-server/models"
|
||||
"scpq-editor-server/repositories"
|
||||
)
|
||||
|
||||
type ProductgroupService struct {
|
||||
ProductgroupRepository *repositories.ProductgroupRepository
|
||||
}
|
||||
|
||||
func NewProductgroupService(ProductgroupRepository *repositories.ProductgroupRepository) *ProductgroupService {
|
||||
return &ProductgroupService{
|
||||
ProductgroupRepository: ProductgroupRepository,
|
||||
}
|
||||
}
|
||||
|
||||
func (ls ProductgroupService) CreateProductgroup(Productgroup *models.Productgroup) (*models.Productgroup, *models.ResponseError) {
|
||||
responseErr := validateProductgroup(Productgroup)
|
||||
if responseErr != nil {
|
||||
return nil, responseErr
|
||||
}
|
||||
return ls.ProductgroupRepository.CreateProductgroup(Productgroup)
|
||||
}
|
||||
|
||||
func (ls ProductgroupService) UpdateProductgroup(Productgroup *models.Productgroup) *models.ResponseError {
|
||||
responseErr := validateProductgroup(Productgroup)
|
||||
if responseErr != nil {
|
||||
return responseErr
|
||||
}
|
||||
return ls.ProductgroupRepository.UpdateProductgroup(Productgroup)
|
||||
}
|
||||
|
||||
func (ls ProductgroupService) DeleteProductgroup(ProductgroupId int) *models.ResponseError {
|
||||
return ls.ProductgroupRepository.DeleteProductgroup(ProductgroupId)
|
||||
}
|
||||
|
||||
func (ls ProductgroupService) GetProductgroup(ProductgroupId int) (*models.Productgroup, *models.ResponseError) {
|
||||
return ls.ProductgroupRepository.GetProductgroup(ProductgroupId)
|
||||
}
|
||||
|
||||
func (ls ProductgroupService) GetAllProductgroups() ([]*models.Productgroup, *models.ResponseError) {
|
||||
return ls.ProductgroupRepository.GetAllProductgroups()
|
||||
}
|
||||
|
||||
func validateProductgroup(Productgroup *models.Productgroup) *models.ResponseError {
|
||||
if Productgroup.Label == "" {
|
||||
return &models.ResponseError{
|
||||
Message: "Invalid label",
|
||||
Status: http.StatusBadRequest,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"scpq-editor-server/models"
|
||||
"scpq-editor-server/repositories"
|
||||
)
|
||||
|
||||
type PropertygroupsService struct {
|
||||
PropertygroupsRepository *repositories.PropertygroupsRepository
|
||||
}
|
||||
|
||||
func NewPropertygroupsService(PropertygroupsRepository *repositories.PropertygroupsRepository) *PropertygroupsService {
|
||||
return &PropertygroupsService{
|
||||
PropertygroupsRepository: PropertygroupsRepository,
|
||||
}
|
||||
}
|
||||
|
||||
func (ls PropertygroupsService) CreatePropertygroup(Propertygroup *models.Propertygroup) (*models.Propertygroup, *models.ResponseError) {
|
||||
responseErr := validatePropertygroup(Propertygroup)
|
||||
if responseErr != nil {
|
||||
return nil, responseErr
|
||||
}
|
||||
return ls.PropertygroupsRepository.CreatePropertygroup(Propertygroup)
|
||||
}
|
||||
|
||||
func (ls PropertygroupsService) UpdatePropertygroup(Propertygroup *models.Propertygroup) *models.ResponseError {
|
||||
responseErr := validatePropertygroup(Propertygroup)
|
||||
if responseErr != nil {
|
||||
return responseErr
|
||||
}
|
||||
return ls.PropertygroupsRepository.UpdatePropertygroup(Propertygroup)
|
||||
}
|
||||
|
||||
func (ls PropertygroupsService) DeletePropertygroup(PropertygroupId int) *models.ResponseError {
|
||||
return ls.PropertygroupsRepository.DeletePropertygroup(PropertygroupId)
|
||||
}
|
||||
|
||||
func (ls PropertygroupsService) GetPropertygroup(PropertygroupId int) (*models.Propertygroup, *models.ResponseError) {
|
||||
return ls.PropertygroupsRepository.GetPropertygroup(PropertygroupId)
|
||||
}
|
||||
|
||||
func (ls PropertygroupsService) GetAllPropertygroups() ([]*models.Propertygroup, *models.ResponseError) {
|
||||
return ls.PropertygroupsRepository.GetAllPropertygroups()
|
||||
}
|
||||
|
||||
func validatePropertygroup(Propertygroup *models.Propertygroup) *models.ResponseError {
|
||||
if Propertygroup.Label == "" {
|
||||
return &models.ResponseError{
|
||||
Message: "Invalid label",
|
||||
Status: http.StatusBadRequest,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
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
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"scpq-editor-server/models"
|
||||
"scpq-editor-server/repositories"
|
||||
)
|
||||
|
||||
type TranslationsService struct {
|
||||
translationsRepository *repositories.TranslationsRepository
|
||||
}
|
||||
|
||||
func NewTranslationsService(TranslationsRepository *repositories.TranslationsRepository) *TranslationsService {
|
||||
return &TranslationsService{
|
||||
translationsRepository: TranslationsRepository,
|
||||
}
|
||||
}
|
||||
|
||||
func (ls TranslationsService) CreateTranslation(translation *models.Translation) (*models.Translation, *models.ResponseError) {
|
||||
responseErr := validateTranslation(translation)
|
||||
if responseErr != nil {
|
||||
return nil, responseErr
|
||||
}
|
||||
return ls.translationsRepository.CreateTranslation(translation)
|
||||
}
|
||||
|
||||
func (ls TranslationsService) UpdateTranslation(Translation *models.Translation) *models.ResponseError {
|
||||
responseErr := validateTranslation(Translation)
|
||||
if responseErr != nil {
|
||||
return responseErr
|
||||
}
|
||||
return ls.translationsRepository.UpdateTranslation(Translation)
|
||||
}
|
||||
|
||||
func (ls TranslationsService) DeleteTranslation(TranslationId int) *models.ResponseError {
|
||||
return ls.translationsRepository.DeleteTranslation(TranslationId)
|
||||
}
|
||||
|
||||
func (ls TranslationsService) GetTranslation(TranslationId int) (*models.Translation, *models.ResponseError) {
|
||||
return ls.translationsRepository.GetTranslation(TranslationId)
|
||||
}
|
||||
|
||||
func (ls TranslationsService) GetAllTranslations() ([]*models.Translation, *models.ResponseError) {
|
||||
return ls.translationsRepository.GetAllTranslations()
|
||||
}
|
||||
|
||||
func (ls TranslationsService) GetAllTranslationsByLanguageId(languageId int) ([]*models.Translation, *models.ResponseError) {
|
||||
return ls.translationsRepository.GetAllTranslationsByLanguageID(languageId)
|
||||
}
|
||||
|
||||
func validateTranslation(Translation *models.Translation) *models.ResponseError {
|
||||
if Translation.Original == "" {
|
||||
return &models.ResponseError{
|
||||
Message: "Invalid Translation original",
|
||||
Status: http.StatusBadRequest,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
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()
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
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()
|
||||
}
|
||||
Reference in New Issue
Block a user