first commit, i i have no idea what i have done

This commit is contained in:
tdv
2025-08-31 22:42:08 +03:00
commit c5632f6a37
177 changed files with 9173 additions and 0 deletions

View 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"`
}

View 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
}

View 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"`
}

View 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,
}
}