Complete API handlers refactoring to eliminate type switching and use repository pattern consistently
This commit is contained in:
@@ -1,35 +1,7 @@
|
||||
package api
|
||||
|
||||
import "time"
|
||||
|
||||
// API request/response models
|
||||
type ContentItem struct {
|
||||
ID string `json:"id"`
|
||||
SiteID string `json:"site_id"`
|
||||
HTMLContent string `json:"html_content"`
|
||||
OriginalTemplate string `json:"original_template"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
LastEditedBy string `json:"last_edited_by"`
|
||||
}
|
||||
|
||||
type ContentVersion struct {
|
||||
VersionID int64 `json:"version_id"`
|
||||
ContentID string `json:"content_id"`
|
||||
SiteID string `json:"site_id"`
|
||||
HTMLContent string `json:"html_content"`
|
||||
OriginalTemplate string `json:"original_template"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
CreatedBy string `json:"created_by"`
|
||||
}
|
||||
|
||||
type ContentResponse struct {
|
||||
Content []ContentItem `json:"content"`
|
||||
}
|
||||
|
||||
type ContentVersionsResponse struct {
|
||||
Versions []ContentVersion `json:"versions"`
|
||||
}
|
||||
// Use db package types directly for API responses - no duplication needed
|
||||
// Request models are kept below as they're different (input DTOs)
|
||||
|
||||
// Element context for backend ID generation
|
||||
type ElementContext struct {
|
||||
@@ -55,44 +27,7 @@ type RollbackContentRequest struct {
|
||||
RolledBackBy string `json:"rolled_back_by,omitempty"`
|
||||
}
|
||||
|
||||
// Collection API models
|
||||
type CollectionItem struct {
|
||||
ID string `json:"id"`
|
||||
SiteID string `json:"site_id"`
|
||||
ContainerHTML string `json:"container_html"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
LastEditedBy string `json:"last_edited_by"`
|
||||
Templates []CollectionTemplate `json:"templates,omitempty"`
|
||||
Items []CollectionItemData `json:"items,omitempty"`
|
||||
}
|
||||
|
||||
type CollectionTemplate struct {
|
||||
TemplateID int `json:"template_id"`
|
||||
CollectionID string `json:"collection_id"`
|
||||
SiteID string `json:"site_id"`
|
||||
Name string `json:"name"`
|
||||
HTMLTemplate string `json:"html_template"`
|
||||
IsDefault bool `json:"is_default"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
type CollectionItemData struct {
|
||||
ItemID string `json:"item_id"`
|
||||
CollectionID string `json:"collection_id"`
|
||||
SiteID string `json:"site_id"`
|
||||
TemplateID int `json:"template_id"`
|
||||
HTMLContent string `json:"html_content"`
|
||||
Position int `json:"position"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
LastEditedBy string `json:"last_edited_by"`
|
||||
TemplateName string `json:"template_name,omitempty"`
|
||||
}
|
||||
|
||||
type CollectionResponse struct {
|
||||
Collections []CollectionItem `json:"collections"`
|
||||
}
|
||||
// Collection response types also use db package directly
|
||||
|
||||
// Collection request models
|
||||
type CreateCollectionRequest struct {
|
||||
|
||||
Reference in New Issue
Block a user