created tasks endpoint for devices
This commit is contained in:
57
server/internal/dto/task.go
Normal file
57
server/internal/dto/task.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"smoop-api/internal/models"
|
||||
"time"
|
||||
)
|
||||
|
||||
type TaskDto struct {
|
||||
ID uint `json:"id"`
|
||||
DeviceGUID string `json:"deviceGuid"`
|
||||
Type models.DeviceTaskType `json:"type"`
|
||||
Payload string `json:"payload"` // raw JSON string
|
||||
Status models.TaskStatus `json:"status"`
|
||||
ErrorMsg string `json:"error,omitempty"`
|
||||
Result string `json:"result,omitempty"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
StartedAt *time.Time `json:"startedAt,omitempty"`
|
||||
FinishedAt *time.Time `json:"finishedAt,omitempty"`
|
||||
}
|
||||
|
||||
func MapTask(t models.DEviceTask) TaskDto {
|
||||
return TaskDto{
|
||||
ID: t.ID,
|
||||
DeviceGUID: t.DeviceGUID,
|
||||
Type: t.Type,
|
||||
Payload: t.Payload,
|
||||
Status: t.Status,
|
||||
ErrorMsg: t.ErrorMsg,
|
||||
Result: t.Result,
|
||||
CreatedAt: t.CreatedAt,
|
||||
StartedAt: t.StartedAt,
|
||||
FinishedAt: t.FinishedAt,
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new task (server/user -> device)
|
||||
type CreateTaskDto struct {
|
||||
Type models.DeviceTaskType `json:"type" binding:"required,oneof=start_stream stop_stream start_recording stop_recording update_config set_deep_sleep"`
|
||||
// Pass raw JSON string as payload (e.g. {"sleepTimeout":5,"jitterMs":50,"recordingDurationSec":60})
|
||||
// Keep it string to let device/server evolve freely.
|
||||
Payload string `json:"payload" binding:"required"`
|
||||
}
|
||||
|
||||
// Device polls: single next task
|
||||
type NextTaskResponseDto struct {
|
||||
HasTask bool `json:"hasTask"`
|
||||
Task *TaskDto `json:"task,omitempty"`
|
||||
}
|
||||
|
||||
// Device posts result
|
||||
type TaskResultDto struct {
|
||||
TaskID uint `json:"taskId" binding:"required"`
|
||||
// success=true => Finished, success=false => Error
|
||||
Success bool `json:"success"`
|
||||
Result string `json:"result"` // raw JSON result from device
|
||||
ErrorMsg string `json:"error"` // device-side reason if !Success
|
||||
}
|
||||
Reference in New Issue
Block a user