Value Services implementiert Teil 1
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"scpq-editor-server/models"
|
||||
"scpq-editor-server/repositories"
|
||||
)
|
||||
|
||||
type PropertytypesService struct {
|
||||
propertyTypesRepository *repositories.PropertyTypesRepository
|
||||
}
|
||||
|
||||
func NewPropertytypesService(propertyTypesRepository *repositories.PropertyTypesRepository) *PropertytypesService {
|
||||
return &PropertytypesService{
|
||||
propertyTypesRepository: propertyTypesRepository,
|
||||
}
|
||||
}
|
||||
|
||||
func (ls PropertytypesService) CreatePropertyType(propertyType *models.PropertyType) (*models.PropertyType, *models.ResponseError) {
|
||||
responseErr := validatePropertyType(propertyType)
|
||||
if responseErr != nil {
|
||||
return nil, responseErr
|
||||
}
|
||||
return ls.propertyTypesRepository.CreatePropertyType(propertyType)
|
||||
}
|
||||
|
||||
func (ls PropertytypesService) UpdatePropertyType(propertyType *models.PropertyType) *models.ResponseError {
|
||||
responseErr := validatePropertyType(propertyType)
|
||||
if responseErr != nil {
|
||||
return responseErr
|
||||
}
|
||||
return ls.propertyTypesRepository.UpdatePropertyType(propertyType)
|
||||
}
|
||||
|
||||
func (ls PropertytypesService) DeletePropertyType(propertyTypeId int) *models.ResponseError {
|
||||
return ls.propertyTypesRepository.DeletePropertyType(propertyTypeId)
|
||||
}
|
||||
|
||||
func (ls PropertytypesService) GetPropertyType(propertyTypeId int) (*models.PropertyType, *models.ResponseError) {
|
||||
return ls.propertyTypesRepository.GetPropertyType(propertyTypeId)
|
||||
}
|
||||
|
||||
func (ls PropertytypesService) GetAllPropertyTypes() ([]*models.PropertyType, *models.ResponseError) {
|
||||
return ls.propertyTypesRepository.GetAllPropertyTypes()
|
||||
}
|
||||
|
||||
func (ls PropertytypesService) GetAllPropertyTypesByPropertyGroupId(propertyGroupId int) ([]*models.PropertyType, *models.ResponseError) {
|
||||
return ls.propertyTypesRepository.GetAllPropertyTypesByPropertyGroupId(propertyGroupId)
|
||||
}
|
||||
|
||||
func validatePropertyType(propertyType *models.PropertyType) *models.ResponseError {
|
||||
if propertyType.Value == "" {
|
||||
return &models.ResponseError{
|
||||
Message: "Invalid PropertyType value",
|
||||
Status: http.StatusBadRequest,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
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
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"scpq-editor-server/models"
|
||||
"scpq-editor-server/repositories"
|
||||
)
|
||||
|
||||
type ValuecomplexitiesService struct {
|
||||
valuecomplexitiesRepository *repositories.ValuecomplexitiesRepository
|
||||
}
|
||||
|
||||
func NewValuecomplexitiesService(valuecomplexitiesRepository *repositories.ValuecomplexitiesRepository) *ValuecomplexitiesService {
|
||||
return &ValuecomplexitiesService{
|
||||
valuecomplexitiesRepository: valuecomplexitiesRepository,
|
||||
}
|
||||
}
|
||||
|
||||
func (vs ValuecomplexitiesService) GetAllValuecomplexities() ([]*models.Valuecomplexity, *models.ResponseError) {
|
||||
return vs.valuecomplexitiesRepository.GetAllValuecomplexities()
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"scpq-editor-server/models"
|
||||
"scpq-editor-server/repositories"
|
||||
)
|
||||
|
||||
type ValuetypesService struct {
|
||||
valuetypesRepository *repositories.ValuetypesRepository
|
||||
}
|
||||
|
||||
func NewValuetypesService(valuetypesRepository *repositories.ValuetypesRepository) *ValuetypesService {
|
||||
return &ValuetypesService{
|
||||
valuetypesRepository: valuetypesRepository,
|
||||
}
|
||||
}
|
||||
|
||||
func (vs ValuetypesService) GetValuetype(valuetypeId int) (*models.Valuetype, *models.ResponseError) {
|
||||
return vs.valuetypesRepository.GetValuetype(valuetypeId)
|
||||
}
|
||||
|
||||
func (vs ValuetypesService) GetAllValuetypes() ([]*models.Valuetype, *models.ResponseError) {
|
||||
return vs.valuetypesRepository.GetAllValuetypes()
|
||||
}
|
||||
Reference in New Issue
Block a user