forked from mtusi2026/mtusi2026lab2
init(app) moved app code from Lab1
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package users
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gitflic.ru/project/bulla-max/mtusi2026lab1/internal/common"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
Username string `json:"username"`
|
||||
DisplayName string `json:"display_name"`
|
||||
CreatedAt common.RFCFormTime `json:"created_at"`
|
||||
}
|
||||
|
||||
type CreateUserRequest struct {
|
||||
Username string `json:"username" validate:"required"`
|
||||
DisplayName string `json:"display_name" validate:"required"`
|
||||
}
|
||||
|
||||
func NewUser(req CreateUserRequest) User {
|
||||
return User{
|
||||
ID: uuid.New(),
|
||||
Username: req.Username,
|
||||
DisplayName: req.DisplayName,
|
||||
CreatedAt: common.NowUTC(),
|
||||
}
|
||||
}
|
||||
|
||||
func (u User) GetID() uuid.UUID {
|
||||
return u.ID
|
||||
}
|
||||
|
||||
func (u User) GetCreatedAt() time.Time {
|
||||
return time.Time(u.CreatedAt)
|
||||
}
|
||||
|
||||
func (u User) GetUsername() string {
|
||||
return u.Username
|
||||
}
|
||||
Reference in New Issue
Block a user