Files
simrsx-be/internal/domain/main-entities/user/dto.go

84 lines
1.9 KiB
Go

package user
import (
ecore "simrs-vx/internal/domain/base-entities/core"
erc "simrs-vx/internal/domain/references/common"
"time"
)
type CreateDto struct {
Name string `json:"name"`
Password string `json:"password"`
Status_Code erc.StatusCode `json:"status_code"`
}
type ReadListDto struct {
Name string `json:"name"`
Status_Code erc.StatusCode `json:"status_code"`
Page int `json:"page"`
PageSize int `json:"page_size"`
NoPagination int `json:"no_pagination"`
}
type ReadDetailDto struct {
Id uint `json:"id"`
Name string `json:"name"`
}
type UpdateDto struct {
Id uint `json:"id"`
CreateDto
}
type DeleteDto struct {
Id uint `json:"id"`
}
type MetaDto struct {
PageNumber int `json:"page_number"`
PageSize int `json:"page_size"`
Count int `json:"count"`
}
type LoginDto struct {
Name string `json:"name" validate:"required"`
Password string `json:"password" validate:"required"`
Duration uint32 `json:"duration"` // in minutes
}
type ResponseDto struct {
ecore.Main
Name string `json:"name"`
Status_Code erc.StatusCode `json:"status_code"`
FailedLoginCount uint8 `json:"failedLoginCount"`
LastSuccessLogin *time.Time `json:"lastSuccessLogin,omitempty"`
LastAllowdLogin *time.Time `json:"lastAllowdLogin,omitempty"`
}
func (d *User) ToResponse() ResponseDto {
resp := ResponseDto{
Name: d.Name,
Status_Code: d.Status_Code,
FailedLoginCount: d.FailedLoginCount,
LastSuccessLogin: d.LastSuccessLogin,
LastAllowdLogin: d.LastAllowdLogin,
}
resp.Main = d.Main
return resp
}
func ToResponseList(data []User) []ResponseDto {
resp := make([]ResponseDto, len(data))
for i, u := range data {
resp[i] = u.ToResponse()
}
return resp
}
func (c CreateDto) Sanitize() CreateDto {
sanitized := c
sanitized.Password = "[REDACTED]"
return sanitized
}