Added uuid middleware
This commit is contained in:
@@ -15,19 +15,27 @@ import (
|
||||
"gitlab.com/pactual1/backend/shared"
|
||||
)
|
||||
|
||||
func GetDevicesForContract(contractID uint64, companyID int) ([]models.Device, int, error) {
|
||||
// Fetch the contract from the database
|
||||
func GetDevicesForContract(contractID uint64, uuid string, companyID int) ([]models.Device, int, error) {
|
||||
// Fetch the contract from the database using both contractID and UUID
|
||||
var contract models.Contract
|
||||
if err := shared.GetDb().Where("id = ?", contractID).First(&contract).Error; err != nil {
|
||||
query := shared.GetDb().Where("id = ?", contractID)
|
||||
|
||||
// If UUID is provided, include it in the query
|
||||
if uuid != "" {
|
||||
query = query.Where("uuid = ?", uuid)
|
||||
}
|
||||
|
||||
if err := query.First(&contract).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
log.Printf("GetDevicesByContract Error: No contract found: %v", err)
|
||||
log.Printf("GetDevicesForContract Error: No contract found: %v", err)
|
||||
return nil, http.StatusNotFound, err
|
||||
} else {
|
||||
log.Printf("GetDevicesByContract Error: Database error: %v", err)
|
||||
log.Printf("GetDevicesForContract Error: Database error: %v", err)
|
||||
return nil, http.StatusInternalServerError, err
|
||||
}
|
||||
}
|
||||
log.Printf("This is the device IDS ID: %v", contract.DeviceIDs)
|
||||
|
||||
log.Printf("This is the device IDs: %v", contract.DeviceIDs)
|
||||
return GetDevicesByID(contract.DeviceIDs)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user