From 9fe86d4f8e394959325a541c8fe813ca03ce40b2 Mon Sep 17 00:00:00 2001 From: Nima Nakhostin Date: Sun, 9 Nov 2025 09:24:23 +0330 Subject: [PATCH] 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. --- cmd/web/docs/docs.go | 12 ++++++++++++ cmd/web/docs/swagger.json | 12 ++++++++++++ cmd/web/docs/swagger.yaml | 9 +++++++++ internal/cms/entity.go | 19 +++++++++++-------- internal/cms/form.go | 19 +++++++++++-------- internal/cms/service.go | 9 +++++++++ 6 files changed, 64 insertions(+), 16 deletions(-) diff --git a/cmd/web/docs/docs.go b/cmd/web/docs/docs.go index d0eaf04..b6d9b42 100644 --- a/cmd/web/docs/docs.go +++ b/cmd/web/docs/docs.go @@ -7744,9 +7744,17 @@ const docTemplate = `{ "chart": { "$ref": "#/definitions/cms.chartSectionForm" }, + "company_name": { + "type": "string", + "example": "Opplens" + }, "contact": { "$ref": "#/definitions/cms.contactSectionForm" }, + "country": { + "type": "string", + "example": "SWE" + }, "features": { "$ref": "#/definitions/cms.cardSectionForm" }, @@ -7759,6 +7767,10 @@ const docTemplate = `{ "key": { "type": "string", "example": "SW-001" + }, + "language": { + "type": "string", + "example": "en" } } }, diff --git a/cmd/web/docs/swagger.json b/cmd/web/docs/swagger.json index b0a0d9f..d4f518a 100644 --- a/cmd/web/docs/swagger.json +++ b/cmd/web/docs/swagger.json @@ -7736,9 +7736,17 @@ "chart": { "$ref": "#/definitions/cms.chartSectionForm" }, + "company_name": { + "type": "string", + "example": "Opplens" + }, "contact": { "$ref": "#/definitions/cms.contactSectionForm" }, + "country": { + "type": "string", + "example": "SWE" + }, "features": { "$ref": "#/definitions/cms.cardSectionForm" }, @@ -7751,6 +7759,10 @@ "key": { "type": "string", "example": "SW-001" + }, + "language": { + "type": "string", + "example": "en" } } }, diff --git a/cmd/web/docs/swagger.yaml b/cmd/web/docs/swagger.yaml index 3a949f7..dc4d5e6 100644 --- a/cmd/web/docs/swagger.yaml +++ b/cmd/web/docs/swagger.yaml @@ -30,8 +30,14 @@ definitions: $ref: '#/definitions/cms.cardSectionForm' chart: $ref: '#/definitions/cms.chartSectionForm' + company_name: + example: Opplens + type: string contact: $ref: '#/definitions/cms.contactSectionForm' + country: + example: SWE + type: string features: $ref: '#/definitions/cms.cardSectionForm' footer: @@ -41,6 +47,9 @@ definitions: key: example: SW-001 type: string + language: + example: en + type: string type: object cms.CMSListResponse: properties: diff --git a/internal/cms/entity.go b/internal/cms/entity.go index 6ca1e5f..c6706ff 100644 --- a/internal/cms/entity.go +++ b/internal/cms/entity.go @@ -9,14 +9,17 @@ import ( // CMS represents the content management system for the landing page type CMS struct { mongo.Model `bson:",inline"` - Key string `bson:"key" json:"key" validate:"required"` - Hero heroSection `bson:"hero" json:"hero"` - Chart chartSection `bson:"chart" json:"chart"` - Features cardSection `bson:"features" json:"features"` - Challenges cardSection `bson:"challenges" json:"challenges"` - Advantages cardSection `bson:"advantages" json:"advantages"` - Contact contactSection `bson:"contact" json:"contact"` - Footer footerSection `bson:"footer" json:"footer"` + Key string `bson:"key"` + Language string `bson:"language"` + CompanyName string `bson:"company_name"` + Country string `bson:"country"` + Hero heroSection `bson:"hero"` + Chart chartSection `bson:"chart"` + Features cardSection `bson:"features"` + Challenges cardSection `bson:"challenges"` + Advantages cardSection `bson:"advantages"` + Contact contactSection `bson:"contact"` + Footer footerSection `bson:"footer"` } // SetID sets the CMS ID (implements IDSetter interface) diff --git a/internal/cms/form.go b/internal/cms/form.go index ad64b27..122a12b 100644 --- a/internal/cms/form.go +++ b/internal/cms/form.go @@ -4,14 +4,17 @@ import "tm/pkg/response" // CMSForm represents the form for creating/updating the CMS type CMSForm struct { - Key string `json:"key" valid:"required,length(2|100)" example:"SW-001"` - Hero heroSectionForm `json:"hero" valid:"optional"` - Chart chartSectionForm `json:"chart" valid:"optional"` - Features cardSectionForm `json:"features" 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"` + Key string `json:"key" valid:"required,length(2|100)" example:"SW-001"` + Language string `json:"language" valid:"optional,length(2|100)" example:"en"` + CompanyName string `json:"company_name" valid:"optional,length(2|100)" example:"Opplens"` + Country string `json:"country" valid:"optional,length(3)" example:"SWE"` + Hero heroSectionForm `json:"hero" valid:"optional"` + Chart chartSectionForm `json:"chart" valid:"optional"` + Features cardSectionForm `json:"features" 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 diff --git a/internal/cms/service.go b/internal/cms/service.go index 5928f28..352cdca 100644 --- a/internal/cms/service.go +++ b/internal/cms/service.go @@ -236,6 +236,15 @@ func (s *cmsService) Search(ctx context.Context, form *SearchCMSForm, pagination // copyFormToEntity copies data from form to entity 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 if form.Hero.Title != "" { cms.Hero.Title = form.Hero.Title