first commit, i i have no idea what i have done
This commit is contained in:
20
server/internal/dto/auth.go
Normal file
20
server/internal/dto/auth.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package dto
|
||||
|
||||
type AuthDto struct {
|
||||
Username string `json:"username" binding:"required"`
|
||||
Password string `json:"password" binding:"required"`
|
||||
}
|
||||
|
||||
type AccessTokenDto struct {
|
||||
AccessToken string `json:"accessToken"`
|
||||
}
|
||||
|
||||
type ChangePasswordDto struct {
|
||||
UserID uint `json:"userId,omitempty"`
|
||||
OldPassword string `json:"oldPassword"`
|
||||
NewPassword string `json:"newPassword" binding:"required"`
|
||||
}
|
||||
|
||||
type CheckTokenResultDto struct {
|
||||
IsValid bool `json:"isValid"`
|
||||
}
|
||||
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
|
||||
}
|
||||
14
server/internal/dto/record.go
Normal file
14
server/internal/dto/record.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package dto
|
||||
|
||||
type RecordDto struct {
|
||||
ID uint `json:"id"`
|
||||
StartedAt int64 `json:"startedAt"`
|
||||
StoppedAt int64 `json:"stoppedAt"`
|
||||
}
|
||||
|
||||
type RecordListDto struct {
|
||||
Records []RecordDto `json:"records"`
|
||||
Offset int `json:"offset"`
|
||||
Limit int `json:"limit"`
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
29
server/internal/dto/user.go
Normal file
29
server/internal/dto/user.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package dto
|
||||
|
||||
import "smoop-api/internal/models"
|
||||
|
||||
type UserDto struct {
|
||||
ID uint `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Role models.Role `json:"role"`
|
||||
}
|
||||
|
||||
type UserRoleDto struct {
|
||||
Role models.Role `json:"role" binding:"required,oneof=admin user"`
|
||||
}
|
||||
|
||||
// CreateUserDto is used by POST /users/create to create a new user with a role.
|
||||
// Role must be one of: "admin" | "user".
|
||||
type CreateUserDto struct {
|
||||
Username string `json:"username" binding:"required"`
|
||||
Password string `json:"password" binding:"required"`
|
||||
Role string `json:"role" binding:"required,oneof=admin user"`
|
||||
}
|
||||
|
||||
func MapUser(u models.User) UserDto {
|
||||
return UserDto{
|
||||
ID: u.ID,
|
||||
Username: u.Username,
|
||||
Role: u.Role,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user