Files
NewSmoop/server/internal/dto/device.go

57 lines
1.3 KiB
Go

package dto
import "smoop-api/internal/models"
type DeviceDto struct {
GUID string `json:"guid"`
Name string `json:"name"`
Users []UserDto `json:"users,omitempty"`
}
type DeviceListDto struct {
Devices []DeviceDto `json:"devices"`
Offset int `json:"offset"`
Limit int `json:"limit"`
Total int64 `json:"total"`
}
type CreateDeviceDto struct {
GUID string `json:"guid" binding:"required"`
Name string `json:"name" binding:"required"`
UserIDs []uint `json:"userIds"`
}
type RenameDeviceDto struct {
Name string `json:"name" binding:"required"`
}
type EditDeviceToUserRelationDto struct {
UserID uint `json:"userId"`
UserIDs []uint `json:"userIds"`
}
// Remove users: accept one or many (kept separate for clarity of intent)
type RemoveDeviceUsersDto struct {
UserID uint `json:"userId"`
UserIDs []uint `json:"userIds"`
}
// Replace users: set entire list (may be empty to clear all)
type SetDeviceUsersDto struct {
UserIDs []uint `json:"userIds"`
}
func MapDevice(d models.Device) DeviceDto {
out := DeviceDto{
GUID: d.GUID,
Name: d.Name,
}
if len(d.Users) > 0 {
out.Users = make([]UserDto, 0, len(d.Users))
for _, u := range d.Users {
out.Users = append(out.Users, MapUser(u))
}
}
return out
}