first commit, i i have no idea what i have done
This commit is contained in:
56
server/internal/dto/device.go
Normal file
56
server/internal/dto/device.go
Normal file
@@ -0,0 +1,56 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user