Intial commit
This commit is contained in:
No files matched your search
@@ -0,0 +1,107 @@
|
||||
package component
|
||||
|
||||
import (
|
||||
"api-service/internal/models"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Rol_component represents the data structure for the role_access.rol_component table
|
||||
// with proper null handling and optimized JSON marshaling.
|
||||
type Rol_component struct {
|
||||
ID int64 `json:"id" db:"id"`
|
||||
Name string `json:"name" db:"name"`
|
||||
Description sql.NullString `json:"description,omitempty" db:"description"`
|
||||
Directory string `json:"directory" db:"directory"`
|
||||
Active bool `json:"active" db:"active"`
|
||||
FkRolPagesID int64 `json:"fk_rol_pages_id" db:"fk_rol_pages_id"`
|
||||
Sort int64 `json:"sort" db:"sort"`
|
||||
}
|
||||
|
||||
// MarshalJSON for Rol_component handles the sql.NullString field 'Description'
|
||||
// to ensure it appears as null, an empty string, or the string value in JSON.
|
||||
func (r Rol_component) MarshalJSON() ([]byte, error) {
|
||||
type Alias Rol_component
|
||||
aux := &struct {
|
||||
*Alias
|
||||
Description *string `json:"description,omitempty"`
|
||||
}{
|
||||
Alias: (*Alias)(&r),
|
||||
}
|
||||
|
||||
if r.Description.Valid {
|
||||
aux.Description = &r.Description.String
|
||||
}
|
||||
return json.Marshal(aux)
|
||||
}
|
||||
|
||||
// Helper method to safely get Description
|
||||
func (r *Rol_component) GetDescription() string {
|
||||
if r.Description.Valid {
|
||||
return r.Description.String
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// REQUEST & RESPONSE STRUCTS FOR ROL_COMPONENT
|
||||
// =============================================================================
|
||||
|
||||
// ComponentCreateRequest defines the structure for creating a new component.
|
||||
type ComponentCreateRequest struct {
|
||||
Name string `json:"name" validate:"required,min=1,max=100"`
|
||||
Description *string `json:"description" validate:"omitempty,max=255"`
|
||||
Directory string `json:"directory" validate:"required,min=1,max=255"`
|
||||
Active bool `json:"active"`
|
||||
Sort int64 `json:"sort"`
|
||||
FkRolPagesID int64 `json:"fk_rol_pages_id" validate:"required,min=1"`
|
||||
}
|
||||
|
||||
// ComponentUpdateRequest defines the structure for updating an existing component.
|
||||
// ID is handled via URL parameter, so it's omitted from JSON with `json:"-"`.
|
||||
type ComponentUpdateRequest struct {
|
||||
ID *int `json:"-" validate:"required"` // ID is from URL param
|
||||
Name *string `json:"name" validate:"omitempty,min=1,max=100"`
|
||||
Description *string `json:"description" validate:"omitempty,max=255"`
|
||||
Directory *string `json:"directory" validate:"omitempty,min=1,max=255"`
|
||||
Active *bool `json:"active" validate:"omitempty"`
|
||||
Sort *int `json:"sort" validate:"omitempty,min=1"`
|
||||
FkRolPagesID *int `json:"fk_rol_pages_id" validate:"omitempty,min=1"`
|
||||
}
|
||||
|
||||
// ComponentsGetResponse defines the response structure for getting a list of components.
|
||||
type ComponentsGetResponse struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data []Rol_component `json:"data"`
|
||||
Meta models.MetaResponse `json:"meta"`
|
||||
}
|
||||
|
||||
// ComponentCreateResponse defines the response structure for creating a component.
|
||||
type ComponentCreateResponse struct {
|
||||
Message string `json:"message"`
|
||||
Data *Rol_component `json:"data"`
|
||||
}
|
||||
|
||||
// ComponentUpdateResponse defines the response structure for updating a component.
|
||||
type ComponentUpdateResponse struct {
|
||||
Message string `json:"message"`
|
||||
Data *Rol_component `json:"data"`
|
||||
}
|
||||
|
||||
// ComponentDeleteResponse defines the response structure for deleting a component.
|
||||
type ComponentDeleteResponse struct {
|
||||
Message string `json:"message"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
// Rol_componentFilter defines the structure for query parameters when filtering components.
|
||||
type Rol_componentFilter struct {
|
||||
PageID *int64 `json:"page_id,omitempty" form:"page_id"`
|
||||
Active *bool `json:"active,omitempty" form:"active"`
|
||||
Search *string `json:"search,omitempty" form:"search"`
|
||||
DateFrom *time.Time `json:"date_from,omitempty" form:"date_from"`
|
||||
DateTo *time.Time `json:"date_to,omitempty" form:"date_to"`
|
||||
Status *string `json:"status,omitempty" form:"status"`
|
||||
}
|
||||
Reference in New Issue
Block a user