Initial commit: Эфир мессенджер

This commit is contained in:
2026-04-06 14:57:36 +03:00
commit ff93679b6d
50 changed files with 5642 additions and 0 deletions

45
internal/models/user.go Normal file
View File

@@ -0,0 +1,45 @@
package models
import (
"time"
)
type UserRole string
const (
RoleUser UserRole = "user"
RoleGlobalAdmin UserRole = "global_admin"
)
type User struct {
ID int64 `json:"id"`
Login string `json:"login"`
PasswordHash string `json:"-"` // never send to client
Role UserRole `json:"role"`
LastSeen *time.Time `json:"last_seen,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
// SafeUser возвращает пользователя без чувствительных данных
type SafeUser struct {
ID int64 `json:"id"`
Login string `json:"login"`
Role UserRole `json:"role"`
LastSeen *time.Time `json:"last_seen,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
func (u *User) ToSafe() *SafeUser {
return &SafeUser{
ID: u.ID,
Login: u.Login,
Role: u.Role,
LastSeen: u.LastSeen,
CreatedAt: u.CreatedAt,
}
}
// IsGlobalAdmin проверяет, является ли пользователь глобальным админом
func (u *User) IsGlobalAdmin() bool {
return u.Role == RoleGlobalAdmin
}