fixing bulk update by port

This commit is contained in:
areeqakbr 2025-06-30 09:33:35 +07:00
parent 7259cd1393
commit 071df9a2aa
2 changed files with 26 additions and 2 deletions

View File

@ -42,7 +42,7 @@ type AssignMultipleCustomersDTO struct {
}
type UpdateCustomerByPortDTO struct {
PortNumber int `json:"port_number" binding:"required,min=1"`
PortNumber int `json:"port_number,omitempty"`
NewCustomerName *string `json:"new_customer_name,omitempty"`
Status *entity.PortStatus `json:"status,omitempty"` // Add status field
Bandwidth *string `json:"bandwidth,omitempty"` // Add bandwidth field

View File

@ -232,6 +232,8 @@ func (r *deviceDetailsRepo) BulkUpdateCustomersByPort(deviceID uuid.UUID, update
devicePort.PortAssignments[i] = entity.PortAssignment{
PortNumber: i + 1,
CustomerName: nil,
Status: entity.PortStatusOff,
Bandwidth: nil,
}
}
}
@ -267,10 +269,32 @@ func (r *deviceDetailsRepo) BulkUpdateCustomersByPort(deviceID uuid.UUID, update
}
}
// Apply all updates
// Apply all updates - FIX: Include Status and Bandwidth updates
for _, update := range updates {
portIndex := update.PortNumber - 1
// Update customer name
devicePort.PortAssignments[portIndex].CustomerName = update.NewCustomerName
// Update status if provided
if update.Status != nil {
devicePort.PortAssignments[portIndex].Status = *update.Status
} else {
// Set default status based on customer assignment
if update.NewCustomerName != nil && *update.NewCustomerName != "" {
devicePort.PortAssignments[portIndex].Status = entity.PortStatusOn
} else {
devicePort.PortAssignments[portIndex].Status = entity.PortStatusOff
}
}
// Update bandwidth if provided
if update.Bandwidth != nil {
devicePort.PortAssignments[portIndex].Bandwidth = update.Bandwidth
} else if update.NewCustomerName == nil || *update.NewCustomerName == "" {
// Clear bandwidth when removing customer
devicePort.PortAssignments[portIndex].Bandwidth = nil
}
}
// Recalculate port_used based on actual assignments