Update CMS Entity and Forms to Include New Fields
- Added new fields to the CMS entity: CompanyName, Country, and Language, enhancing the data structure for better content management. - Updated the CMSForm to include validation and examples for the new fields, ensuring proper input handling. - Modified the copyFormToEntity method in the CMS service to map the new fields from the form to the entity, maintaining data integrity. - Enhanced Swagger documentation to reflect the changes in the CMS API, providing clear examples for the new fields.
This commit is contained in:
@@ -7744,9 +7744,17 @@ const docTemplate = `{
|
|||||||
"chart": {
|
"chart": {
|
||||||
"$ref": "#/definitions/cms.chartSectionForm"
|
"$ref": "#/definitions/cms.chartSectionForm"
|
||||||
},
|
},
|
||||||
|
"company_name": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "Opplens"
|
||||||
|
},
|
||||||
"contact": {
|
"contact": {
|
||||||
"$ref": "#/definitions/cms.contactSectionForm"
|
"$ref": "#/definitions/cms.contactSectionForm"
|
||||||
},
|
},
|
||||||
|
"country": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "SWE"
|
||||||
|
},
|
||||||
"features": {
|
"features": {
|
||||||
"$ref": "#/definitions/cms.cardSectionForm"
|
"$ref": "#/definitions/cms.cardSectionForm"
|
||||||
},
|
},
|
||||||
@@ -7759,6 +7767,10 @@ const docTemplate = `{
|
|||||||
"key": {
|
"key": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "SW-001"
|
"example": "SW-001"
|
||||||
|
},
|
||||||
|
"language": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "en"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -7736,9 +7736,17 @@
|
|||||||
"chart": {
|
"chart": {
|
||||||
"$ref": "#/definitions/cms.chartSectionForm"
|
"$ref": "#/definitions/cms.chartSectionForm"
|
||||||
},
|
},
|
||||||
|
"company_name": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "Opplens"
|
||||||
|
},
|
||||||
"contact": {
|
"contact": {
|
||||||
"$ref": "#/definitions/cms.contactSectionForm"
|
"$ref": "#/definitions/cms.contactSectionForm"
|
||||||
},
|
},
|
||||||
|
"country": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "SWE"
|
||||||
|
},
|
||||||
"features": {
|
"features": {
|
||||||
"$ref": "#/definitions/cms.cardSectionForm"
|
"$ref": "#/definitions/cms.cardSectionForm"
|
||||||
},
|
},
|
||||||
@@ -7751,6 +7759,10 @@
|
|||||||
"key": {
|
"key": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "SW-001"
|
"example": "SW-001"
|
||||||
|
},
|
||||||
|
"language": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "en"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -30,8 +30,14 @@ definitions:
|
|||||||
$ref: '#/definitions/cms.cardSectionForm'
|
$ref: '#/definitions/cms.cardSectionForm'
|
||||||
chart:
|
chart:
|
||||||
$ref: '#/definitions/cms.chartSectionForm'
|
$ref: '#/definitions/cms.chartSectionForm'
|
||||||
|
company_name:
|
||||||
|
example: Opplens
|
||||||
|
type: string
|
||||||
contact:
|
contact:
|
||||||
$ref: '#/definitions/cms.contactSectionForm'
|
$ref: '#/definitions/cms.contactSectionForm'
|
||||||
|
country:
|
||||||
|
example: SWE
|
||||||
|
type: string
|
||||||
features:
|
features:
|
||||||
$ref: '#/definitions/cms.cardSectionForm'
|
$ref: '#/definitions/cms.cardSectionForm'
|
||||||
footer:
|
footer:
|
||||||
@@ -41,6 +47,9 @@ definitions:
|
|||||||
key:
|
key:
|
||||||
example: SW-001
|
example: SW-001
|
||||||
type: string
|
type: string
|
||||||
|
language:
|
||||||
|
example: en
|
||||||
|
type: string
|
||||||
type: object
|
type: object
|
||||||
cms.CMSListResponse:
|
cms.CMSListResponse:
|
||||||
properties:
|
properties:
|
||||||
|
|||||||
+11
-8
@@ -9,14 +9,17 @@ import (
|
|||||||
// CMS represents the content management system for the landing page
|
// CMS represents the content management system for the landing page
|
||||||
type CMS struct {
|
type CMS struct {
|
||||||
mongo.Model `bson:",inline"`
|
mongo.Model `bson:",inline"`
|
||||||
Key string `bson:"key" json:"key" validate:"required"`
|
Key string `bson:"key"`
|
||||||
Hero heroSection `bson:"hero" json:"hero"`
|
Language string `bson:"language"`
|
||||||
Chart chartSection `bson:"chart" json:"chart"`
|
CompanyName string `bson:"company_name"`
|
||||||
Features cardSection `bson:"features" json:"features"`
|
Country string `bson:"country"`
|
||||||
Challenges cardSection `bson:"challenges" json:"challenges"`
|
Hero heroSection `bson:"hero"`
|
||||||
Advantages cardSection `bson:"advantages" json:"advantages"`
|
Chart chartSection `bson:"chart"`
|
||||||
Contact contactSection `bson:"contact" json:"contact"`
|
Features cardSection `bson:"features"`
|
||||||
Footer footerSection `bson:"footer" json:"footer"`
|
Challenges cardSection `bson:"challenges"`
|
||||||
|
Advantages cardSection `bson:"advantages"`
|
||||||
|
Contact contactSection `bson:"contact"`
|
||||||
|
Footer footerSection `bson:"footer"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetID sets the CMS ID (implements IDSetter interface)
|
// SetID sets the CMS ID (implements IDSetter interface)
|
||||||
|
|||||||
+11
-8
@@ -4,14 +4,17 @@ import "tm/pkg/response"
|
|||||||
|
|
||||||
// CMSForm represents the form for creating/updating the CMS
|
// CMSForm represents the form for creating/updating the CMS
|
||||||
type CMSForm struct {
|
type CMSForm struct {
|
||||||
Key string `json:"key" valid:"required,length(2|100)" example:"SW-001"`
|
Key string `json:"key" valid:"required,length(2|100)" example:"SW-001"`
|
||||||
Hero heroSectionForm `json:"hero" valid:"optional"`
|
Language string `json:"language" valid:"optional,length(2|100)" example:"en"`
|
||||||
Chart chartSectionForm `json:"chart" valid:"optional"`
|
CompanyName string `json:"company_name" valid:"optional,length(2|100)" example:"Opplens"`
|
||||||
Features cardSectionForm `json:"features" valid:"optional"`
|
Country string `json:"country" valid:"optional,length(3)" example:"SWE"`
|
||||||
Challenges cardSectionForm `json:"challenges" valid:"optional"`
|
Hero heroSectionForm `json:"hero" valid:"optional"`
|
||||||
Advantages cardSectionForm `json:"advantages" valid:"optional"`
|
Chart chartSectionForm `json:"chart" valid:"optional"`
|
||||||
Contact contactSectionForm `json:"contact" valid:"optional"`
|
Features cardSectionForm `json:"features" valid:"optional"`
|
||||||
Footer footerSectionForm `json:"footer" valid:"optional"`
|
Challenges cardSectionForm `json:"challenges" valid:"optional"`
|
||||||
|
Advantages cardSectionForm `json:"advantages" valid:"optional"`
|
||||||
|
Contact contactSectionForm `json:"contact" valid:"optional"`
|
||||||
|
Footer footerSectionForm `json:"footer" valid:"optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// heroSectionForm represents the form for creating/updating the hero section
|
// heroSectionForm represents the form for creating/updating the hero section
|
||||||
|
|||||||
@@ -236,6 +236,15 @@ func (s *cmsService) Search(ctx context.Context, form *SearchCMSForm, pagination
|
|||||||
|
|
||||||
// copyFormToEntity copies data from form to entity
|
// copyFormToEntity copies data from form to entity
|
||||||
func (s *cmsService) copyFormToEntity(form *CMSForm, cms *CMS) {
|
func (s *cmsService) copyFormToEntity(form *CMSForm, cms *CMS) {
|
||||||
|
if form.Language != "" {
|
||||||
|
cms.Language = form.Language
|
||||||
|
}
|
||||||
|
if form.CompanyName != "" {
|
||||||
|
cms.CompanyName = form.CompanyName
|
||||||
|
}
|
||||||
|
if form.Country != "" {
|
||||||
|
cms.Country = form.Country
|
||||||
|
}
|
||||||
// Hero section
|
// Hero section
|
||||||
if form.Hero.Title != "" {
|
if form.Hero.Title != "" {
|
||||||
cms.Hero.Title = form.Hero.Title
|
cms.Hero.Title = form.Hero.Title
|
||||||
|
|||||||
Reference in New Issue
Block a user