forked from rachmadiyanti.annisa.3004/service_antrean
Perbaikan Update
This commit is contained in:
@@ -39,7 +39,7 @@ var (
|
||||
|
||||
var (
|
||||
pageFieldToColumn = map[string]string{
|
||||
"Name": "name", "Icon": "icon", "Url": "url", "Level": "level", "Sort": "sort",
|
||||
"Name": "name", "Icon": "icon", "Url": "url", "Level": "level", "Sort": "sort", "Active": "active", "Parent": "parent",
|
||||
}
|
||||
componentFieldToColumn = map[string]string{
|
||||
"Name": "name", "Description": "description", "Directory": "directory", "Sort": "sort", "Active": "active",
|
||||
@@ -618,6 +618,13 @@ func (h *Rol_pagesHandler) UpdateRol_pagesBulk(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Normalize id fields: accept either "id" or "ids" in JSON, prefer ID
|
||||
for i := range reqs {
|
||||
if reqs[i].ID == nil && reqs[i].IDs != nil {
|
||||
reqs[i].ID = reqs[i].IDs
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure every object has numeric ID and validate
|
||||
for i := range reqs {
|
||||
if reqs[i].ID == nil {
|
||||
@@ -983,7 +990,7 @@ func (h *Rol_pagesHandler) executeUpdateTransaction(ctx context.Context, dbConn
|
||||
|
||||
// buildUpdateColumns builds update columns and values from the request
|
||||
func (h *Rol_pagesHandler) buildUpdateColumns(req pagesModels.PagesUpdateRequest) ([]string, []interface{}) {
|
||||
return buildUpdateColumnsFromStruct(req, pageFieldToColumn)
|
||||
return buildUpdateColumnsFromStruct(&req, pageFieldToColumn)
|
||||
}
|
||||
|
||||
// selectPageByID selects a page by ID
|
||||
@@ -1060,7 +1067,7 @@ func (h *Rol_pagesHandler) updateComponents(ctx context.Context, tx *sqlx.Tx, co
|
||||
|
||||
// buildComponentUpdateColumns builds update columns and values for a component
|
||||
func (h *Rol_pagesHandler) buildComponentUpdateColumns(compReq pagesModels.ComponentUpdateRequest) ([]string, []interface{}) {
|
||||
return buildUpdateColumnsFromStruct(compReq, componentFieldToColumn)
|
||||
return buildUpdateColumnsFromStruct(&compReq, componentFieldToColumn)
|
||||
}
|
||||
|
||||
// updatePermissions updates permissions for a page
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
// with proper null handling and optimized JSON marshaling
|
||||
type Rol_pages struct {
|
||||
ID int64 `json:"id" db:"id"`
|
||||
IDs int64 `json:"id" db:"id"`
|
||||
Name string `json:"name," db:"name"`
|
||||
Icon sql.NullString `json:"icon,omitempty" db:"icon"`
|
||||
Url sql.NullString `json:"url,omitempty" db:"url"`
|
||||
@@ -246,7 +247,8 @@ type PagesUpdateResponse struct {
|
||||
|
||||
// Update request
|
||||
type PagesUpdateRequest struct {
|
||||
ID *int `json:"id" validate:"required"`
|
||||
IDs *int `json:"id" validate:"omitempty"` // used when updating via JSON array (bulk)
|
||||
ID *int `json:"-" validate:"omitempty"` // required for single update via URL param
|
||||
// Status string `json:"status" validate:"required,oneof=draft active inactive"`
|
||||
Name *string `json:"name" validate:"omitempty,min=1,max=20"`
|
||||
Icon *string `json:"icon" validate:"omitempty,min=1,max=100"`
|
||||
|
||||
Reference in New Issue
Block a user