67 lines
2.8 KiB
Go
67 lines
2.8 KiB
Go
package controlapi
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"yovision/sense/internal/store"
|
||
|
|
)
|
||
|
|
|
||
|
|
func publicDevice(value store.ControlDevice) Device {
|
||
|
|
capabilities := make([]Capability, len(value.Capabilities))
|
||
|
|
for index := range value.Capabilities {
|
||
|
|
capabilities[index] = Capability(value.Capabilities[index])
|
||
|
|
}
|
||
|
|
tenantID := LogicalID(value.TenantID)
|
||
|
|
generation, observed := value.Generation, value.ObservedGeneration
|
||
|
|
converged, failureCount := value.Converged, value.FailureCount
|
||
|
|
endpointConfigured, credentialConfigured := value.EndpointConfigured, value.CredentialConfigured
|
||
|
|
createdAt, updatedAt := value.CreatedAt, value.UpdatedAt
|
||
|
|
result := Device{
|
||
|
|
Id: value.ID, TenantId: &tenantID, SiteId: value.SiteID,
|
||
|
|
SerialNumber: value.SerialNumber, Name: value.Name, Modality: Modality(value.Modality),
|
||
|
|
Capabilities: &capabilities, AreaId: value.AreaID,
|
||
|
|
DesiredState: DesiredState(value.DesiredState), ActualState: ActualState(value.ActualState),
|
||
|
|
AdapterStatus: AdapterStatus(value.AdapterStatus),
|
||
|
|
EndpointConfigured: &endpointConfigured, CredentialConfigured: &credentialConfigured,
|
||
|
|
Generation: &generation, ObservedGeneration: &observed, Converged: &converged,
|
||
|
|
FailureCount: &failureCount, NextAttemptAt: value.NextAttemptAt,
|
||
|
|
LastErrorCode: value.LastErrorCode, CreatedAt: &createdAt, UpdatedAt: &updatedAt,
|
||
|
|
}
|
||
|
|
if value.ProjectionVersions.QuotaSourceVersion != nil {
|
||
|
|
version := *value.ProjectionVersions.QuotaSourceVersion
|
||
|
|
result.ProjectionVersions.QuotaSourceVersion = &version
|
||
|
|
}
|
||
|
|
if value.ProjectionVersions.AreaPolicySourceVersion != nil {
|
||
|
|
version := *value.ProjectionVersions.AreaPolicySourceVersion
|
||
|
|
result.ProjectionVersions.AreaPolicySourceVersion = &version
|
||
|
|
}
|
||
|
|
result.ProjectionVersions.SyncedAt = value.ProjectionVersions.SyncedAt
|
||
|
|
return result
|
||
|
|
}
|
||
|
|
|
||
|
|
func publicQuota(value store.ControlSiteQuota) SiteQuotaStatus {
|
||
|
|
return SiteQuotaStatus{
|
||
|
|
Status: SiteQuotaStatusStatus(value.Status), UsedVideoChannels: value.UsedVideoChannels,
|
||
|
|
MaxVideoChannels: value.MaxVideoChannels,
|
||
|
|
AvailableVideoChannels: value.AvailableVideoChannels,
|
||
|
|
OverLimit: value.OverLimit, SourceVersion: value.SourceVersion, SyncedAt: value.SyncedAt,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func publicOperation(value store.ControlBatchOperation) BatchOperation {
|
||
|
|
results := make([]BatchItemResult, 0, len(value.Results))
|
||
|
|
for _, item := range value.Results {
|
||
|
|
var code *ErrorCode
|
||
|
|
if item.ErrorCode != nil {
|
||
|
|
converted := ErrorCode(*item.ErrorCode)
|
||
|
|
code = &converted
|
||
|
|
}
|
||
|
|
results = append(results, BatchItemResult{
|
||
|
|
DeviceId: item.DeviceID, Status: BatchItemResultStatus(item.Status),
|
||
|
|
ErrorCode: code, Message: item.Message, Generation: item.Generation,
|
||
|
|
})
|
||
|
|
}
|
||
|
|
return BatchOperation{
|
||
|
|
Id: value.ID, Status: BatchOperationStatus(value.Status), SubmittedAt: value.SubmittedAt,
|
||
|
|
CompletedAt: value.CompletedAt, Results: results, TraceId: value.TraceID,
|
||
|
|
}
|
||
|
|
}
|