991771ee19
- Introduced a new company category management feature, including CRUD operations for categories in both admin and public API endpoints. - Implemented category entity, service, repository, and handler layers following clean architecture principles. - Added new API routes for searching, retrieving, updating, deleting, and toggling publish status of categories, enhancing the overall functionality of the system. - Updated Swagger and YAML documentation to include detailed descriptions and examples for the new category endpoints, ensuring clarity for API consumers. - Enhanced error handling for duplicate categories and validation, improving the robustness of the category management process. - Updated existing routes to integrate category handling, ensuring a seamless user experience across the application.
53 lines
1.9 KiB
Go
53 lines
1.9 KiB
Go
package company_category
|
|
|
|
import "tm/pkg/response"
|
|
|
|
// CategoryForm represents the form for creating/updating a category
|
|
type CategoryForm struct {
|
|
Name string `json:"name" valid:"required,length(2|100)" example:"Technology"`
|
|
Description *string `json:"description,omitempty" valid:"optional,length(10|500)" example:"Technology related companies"`
|
|
Thumbnail *string `json:"thumbnail,omitempty" valid:"optional,url" example:"https://example.com/thumbnail.jpg"`
|
|
}
|
|
|
|
// SearchForm represents the form for searching categories with filters
|
|
type SearchForm struct {
|
|
Search *string `query:"q" valid:"optional"`
|
|
Published *bool `query:"published" valid:"optional"`
|
|
Limit *int `query:"limit" valid:"optional,range(1|100)"`
|
|
Offset *int `query:"offset" valid:"optional,min(0)"`
|
|
SortBy *string `query:"sort_by" valid:"optional,in(name|created_at|updated_at|published_at)"`
|
|
SortOrder *string `query:"sort_order" valid:"optional,in(asc|desc)"`
|
|
}
|
|
|
|
// CategoryListResponse represents the response for listing categories
|
|
type CategoryListResponse struct {
|
|
Categories []*CategoryResponse `json:"categories"`
|
|
Meta *response.Meta `json:"-"`
|
|
}
|
|
|
|
// CategoryResponse represents the category data sent in API responses
|
|
type CategoryResponse struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Description *string `json:"description,omitempty"`
|
|
Thumbnail *string `json:"thumbnail,omitempty"`
|
|
Published bool `json:"published"`
|
|
PublishedAt *int64 `json:"published_at,omitempty"`
|
|
CreatedAt int64 `json:"created_at"`
|
|
UpdatedAt int64 `json:"updated_at"`
|
|
}
|
|
|
|
// ToResponse converts Category to CategoryResponse
|
|
func (c *Category) ToResponse() *CategoryResponse {
|
|
return &CategoryResponse{
|
|
ID: c.ID.Hex(),
|
|
Name: c.Name,
|
|
Description: c.Description,
|
|
Thumbnail: c.Thumbnail,
|
|
Published: c.Published,
|
|
PublishedAt: c.PublishedAt,
|
|
CreatedAt: c.CreatedAt,
|
|
UpdatedAt: c.UpdatedAt,
|
|
}
|
|
}
|