Files
tm_back/internal/cms/entity.go
T
Nima Nakhostin a363078d6f Enhance CMS Entity and Forms with Type Field
- Added a new Type field to the CMS entity to differentiate between Company and Organization types, improving data categorization.
- Updated the CMSForm to include validation for the Type field, ensuring proper input handling.
- Modified the ToResponse method to include the Type field in the CMSResponse, enhancing the API response structure.
- Adjusted the copyFormToEntity method in the CMS service to handle the new Type field, maintaining data integrity based on the selected type.
- Enhanced Swagger documentation to reflect the changes in the CMS API, providing clear examples for the new Type field.
2025-11-09 10:21:25 +03:30

122 lines
3.5 KiB
Go

package cms
import (
"tm/pkg/mongo"
"go.mongodb.org/mongo-driver/v2/bson"
)
// CMS represents the content management system for the landing page
type CMS struct {
mongo.Model `bson:",inline"`
Key string `bson:"key"`
Language string `bson:"language"`
CompanyName string `bson:"company_name"`
Country string `bson:"country"`
Type CMSType `bson:"type"`
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"`
}
type CMSType string
const (
CMSTypeCompany CMSType = "company"
CMSTypeOrganization CMSType = "organization"
)
// SetID sets the CMS ID (implements IDSetter interface)
func (c *CMS) SetID(id string) {
c.ID, _ = bson.ObjectIDFromHex(id)
}
// GetID returns the CMS ID (implements IDGetter interface)
func (c *CMS) GetID() string {
return c.ID.Hex()
}
// SetCreatedAt sets the created timestamp (implements Timestamp interface)
func (c *CMS) SetCreatedAt(timestamp int64) {
c.CreatedAt = timestamp
}
// SetUpdatedAt sets the updated timestamp (implements Timestamp interface)
func (c *CMS) SetUpdatedAt(timestamp int64) {
c.UpdatedAt = timestamp
}
// GetCreatedAt returns the created timestamp (implements Timestamp interface)
func (c *CMS) GetCreatedAt() int64 {
return c.CreatedAt
}
// GetUpdatedAt returns the updated timestamp (implements Timestamp interface)
func (c *CMS) GetUpdatedAt() int64 {
return c.UpdatedAt
}
// heroSection represents the hero section of the landing page
type heroSection struct {
Title string `bson:"title"`
Description string `bson:"description"`
ButtonText string `bson:"button_text"`
ButtonLink string `bson:"button_link"`
GifFile string `bson:"gif_file"`
}
// chartSection represents the chart section of the landing page
type chartSection struct {
Title string `bson:"title" json:"title"`
MissedAmount string `bson:"missed_amount" json:"missedAmount"`
Data []chartPoint `bson:"data" json:"data"`
}
type chartPoint struct {
Key string `bson:"key" json:"key"`
Value int `bson:"value" json:"value"`
}
// cardSection represents the card section of the landing page
type cardSection struct {
Title string `bson:"title"`
Description string `bson:"description"`
Cards []card `bson:"cards"`
}
// card represents a card in the card section
type card struct {
Icon string `bson:"icon"`
Title string `bson:"title"`
Description string `bson:"description"`
}
// contactSection represents the contact section of the landing page
type contactSection struct {
Title string `bson:"title"`
Description string `bson:"description"`
SubmitButtonText string `bson:"submit_button_text"`
Fields []formField `bson:"fields"`
}
// formField represents a form field in the contact section
type formField struct {
Name string `bson:"name"`
Label string `bson:"label"`
Placeholder string `bson:"placeholder"`
Required bool `bson:"required"`
}
// footerSection represents the footer section of the landing page
type footerSection struct {
Email string `bson:"email"`
Phone string `bson:"phone"`
Location string `bson:"location"`
Tagline string `bson:"tagline"`
Copyright string `bson:"copyright"`
}