Value Services implementiert Teil 1
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
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)
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
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)
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
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)
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"scpq-editor-server/models"
|
||||
"scpq-editor-server/services"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type PropertytypesController struct {
|
||||
PropertytypesService *services.PropertytypesService
|
||||
}
|
||||
|
||||
func NewPropertytypesController(PropertytypesService *services.PropertytypesService) *PropertytypesController {
|
||||
return &PropertytypesController{
|
||||
PropertytypesService: PropertytypesService,
|
||||
}
|
||||
}
|
||||
|
||||
func (lc PropertytypesController) CreatePropertytype(ctx *gin.Context) {
|
||||
body, err := io.ReadAll(ctx.Request.Body)
|
||||
if err != nil {
|
||||
log.Println("Error while reading create Translation request body", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
var propertyType models.PropertyType
|
||||
err = json.Unmarshal(body, &propertyType)
|
||||
if err != nil {
|
||||
log.Println("Error while unmarshaling create PropertyType request body", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
response, responseErr := lc.PropertytypesService.CreatePropertyType(&propertyType)
|
||||
if responseErr != nil {
|
||||
ctx.AbortWithStatusJSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
func (lc PropertytypesController) UpdatePropertytype(ctx *gin.Context) {
|
||||
body, err := io.ReadAll(ctx.Request.Body)
|
||||
if err != nil {
|
||||
log.Println("Error while reading update PropertyType request body", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
var propertyType models.PropertyType
|
||||
err = json.Unmarshal(body, &propertyType)
|
||||
if err != nil {
|
||||
log.Println("Error while unmarshaling update PropertyType request body", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
responseErr := lc.PropertytypesService.UpdatePropertyType(&propertyType)
|
||||
if responseErr != nil {
|
||||
ctx.AbortWithStatusJSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (lc PropertytypesController) DeletePropertytype(ctx *gin.Context) {
|
||||
propertyTypeId := ctx.Param("id")
|
||||
lId, err := strconv.Atoi(propertyTypeId)
|
||||
if err != nil {
|
||||
log.Println("Error propertyTypeId not int", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
responseErr := lc.PropertytypesService.DeletePropertyType(lId)
|
||||
if responseErr != nil {
|
||||
ctx.JSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (lc PropertytypesController) GetPropertytype(ctx *gin.Context) {
|
||||
propertyTypeId := ctx.Param("id")
|
||||
lId, err := strconv.Atoi(propertyTypeId)
|
||||
if err != nil {
|
||||
log.Println("Error propertyTypeId not int", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
response, responseErr := lc.PropertytypesService.GetPropertyType(lId)
|
||||
if responseErr != nil {
|
||||
ctx.JSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
func (lc PropertytypesController) GetAllPropertytypes(ctx *gin.Context) {
|
||||
response, responseErr := lc.PropertytypesService.GetAllPropertyTypes()
|
||||
if responseErr != nil {
|
||||
ctx.JSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
func (lc PropertytypesController) GetAllPropertytypesByPropertyGroupId(ctx *gin.Context) {
|
||||
propertyGroupId := ctx.Param("propertyGroupId")
|
||||
lId, err := strconv.Atoi(propertyGroupId)
|
||||
if err != nil {
|
||||
log.Println("Error propertyGroupId not int", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
response, responseErr := lc.PropertytypesService.GetAllPropertyTypesByPropertyGroupId(lId)
|
||||
if responseErr != nil {
|
||||
ctx.JSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"scpq-editor-server/models"
|
||||
"scpq-editor-server/services"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type 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)
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"scpq-editor-server/services"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type ValuecomplexitiesController struct {
|
||||
ValuecomplexitiesService *services.ValuecomplexitiesService
|
||||
}
|
||||
|
||||
func NewValuecomplexitiesController(ValuecomplexitiesService *services.ValuecomplexitiesService) *ValuecomplexitiesController {
|
||||
return &ValuecomplexitiesController{
|
||||
ValuecomplexitiesService: ValuecomplexitiesService,
|
||||
}
|
||||
}
|
||||
|
||||
func (vc ValuecomplexitiesController) GetAllValuecomplexities(ctx *gin.Context) {
|
||||
response, responseErr := vc.ValuecomplexitiesService.GetAllValuecomplexities()
|
||||
if responseErr != nil {
|
||||
ctx.JSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, response)
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"scpq-editor-server/services"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type ValuetypesController struct {
|
||||
ValuetypesService *services.ValuetypesService
|
||||
}
|
||||
|
||||
func NewValuetypesController(ValuetypesService *services.ValuetypesService) *ValuetypesController {
|
||||
return &ValuetypesController{
|
||||
ValuetypesService: ValuetypesService,
|
||||
}
|
||||
}
|
||||
|
||||
func (vc ValuetypesController) GetValuetype(ctx *gin.Context) {
|
||||
ValuetypeId := ctx.Param("id")
|
||||
lId, err := strconv.Atoi(ValuetypeId)
|
||||
if err != nil {
|
||||
log.Println("Error ValuetypeId not int", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
response, responseErr := vc.ValuetypesService.GetValuetype(lId)
|
||||
if responseErr != nil {
|
||||
ctx.JSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
func (vc ValuetypesController) GetAllValuetypes(ctx *gin.Context) {
|
||||
response, responseErr := vc.ValuetypesService.GetAllValuetypes()
|
||||
if responseErr != nil {
|
||||
ctx.JSON(responseErr.Status, responseErr)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, response)
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user