From 071df9a2aa9534a52df32ba477826cf31961a56e Mon Sep 17 00:00:00 2001 From: areeqakbr Date: Mon, 30 Jun 2025 09:33:35 +0700 Subject: [PATCH] fixing bulk update by port --- model/dto/req/deviceDetails.go | 2 +- repository/device_details.go | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/model/dto/req/deviceDetails.go b/model/dto/req/deviceDetails.go index aa07df6..245d5c7 100644 --- a/model/dto/req/deviceDetails.go +++ b/model/dto/req/deviceDetails.go @@ -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 diff --git a/repository/device_details.go b/repository/device_details.go index aaad4c4..b0c4f6c 100644 --- a/repository/device_details.go +++ b/repository/device_details.go @@ -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