fixing uppercase on devicewithoutconnections

This commit is contained in:
areeqakbr 2025-06-23 13:47:39 +07:00
parent d8e51e2ff4
commit 0c926d722b
1 changed files with 10 additions and 4 deletions

View File

@ -3,6 +3,7 @@ package usecase
import (
"errors"
"fmt"
"log"
"mime/multipart"
"strings"
"time"
@ -55,18 +56,23 @@ func NewDeviceDetailsUseCase(deviceDetailsRepo repository.DeviceDetailsRepo, geo
}
func (u *deviceDetailsUseCase) GetDevicesWithoutConnections(deviceTypes []string) ([]res.DeviceDetailsResponse, error) {
// Validate device types
// Validate device types and convert to uppercase
validTypes := map[string]bool{"CLOSURE": true, "OTB": true}
for _, deviceType := range deviceTypes {
if !validTypes[deviceType] {
return nil, fmt.Errorf("invalid device type: %s. Only closure and OTB are allowed", deviceType)
for i, deviceType := range deviceTypes {
upperDeviceType := strings.ToUpper(deviceType)
if !validTypes[upperDeviceType] {
return nil, fmt.Errorf("invalid device type: %s. Only CLOSURE and OTB are allowed", deviceType)
}
// Replace the original value in the slice with uppercase version for consistency
deviceTypes[i] = upperDeviceType
}
// If no device types provided, default to closure and OTB
if len(deviceTypes) == 0 {
deviceTypes = []string{"CLOSURE", "OTB"}
}
log.Printf("Fetching devices without connections for types: %v", deviceTypes)
devices, err := u.deviceDetailsRepo.GetDevicesWithoutConnections(deviceTypes)
if err != nil {