Реализация на 5

This commit is contained in:
Grbisba
2026-11-13 11:05:05 +03:00
parent ec540a1a72
commit d862103650
148 changed files with 11225 additions and 55 deletions
+1
View File
@@ -0,0 +1 @@
package dto
+126
View File
@@ -0,0 +1,126 @@
package dto
import (
"errors"
"net/netip"
"time"
"github.com/google/uuid"
"gitea.privcloud.tech/mtusi2026/internal/pkg/types/role"
)
// ---- Tokens ----
type UserDataInToken struct {
TokenID uuid.UUID
UserID uuid.UUID
Role role.Role
IsAccess bool
PhoneNumber *string
Email *string
ExpiresAt time.Time
IssuedAt time.Time
}
func (u UserDataInToken) Validate() error {
if u.TokenID == uuid.Nil {
return errors.New("invalid token id")
}
if u.UserID == uuid.Nil {
return errors.New("invalid user id")
}
if !u.Role.IsValid() {
return errors.New("invalid role")
}
if u.ExpiresAt.IsZero() {
return errors.New("invalid expiry")
}
if u.IssuedAt.IsZero() {
return errors.New("invalid issued")
}
return nil
}
type Token struct {
Payload string
}
type (
AccessToken Token
RefreshToken Token
)
type Tokens struct {
AccessToken AccessToken
RefreshToken RefreshToken
}
func (t AccessToken) Token() *Token {
return new(Token(t))
}
func (t RefreshToken) Token() *Token {
return new(Token(t))
}
type StoredRefreshToken struct {
ID uuid.UUID
UserID uuid.UUID
TokenHash string
UserAgent string
IPAddress netip.Addr
Role role.Role
ExpiresAt time.Time
RevokedAt *time.Time
CreatedAt time.Time
}
type RevokeRefreshToken struct {
ID uuid.UUID
RevokedAt time.Time
}
type RevokeRefreshTokensByUserID struct {
UserID uuid.UUID
RevokedAt time.Time
}
// ---- Auth ----
type Session struct {
ExpiresAt time.Time
Token string
TokenType string
User User
}
type Login struct {
Username string
Password string
}
type LoginResult struct {
ExpiresAt time.Time
TokenType string
User User
Tokens Tokens
}
// UserCredentials is internal authentication data, never a public user response.
type UserCredentials struct {
User User
PasswordHash string `json:"-"`
}
type Logout struct {
Token string
}
type Register struct {
Email string
Password string
RepeatPassword string
}
+31
View File
@@ -0,0 +1,31 @@
package dto
import (
"time"
"github.com/google/uuid"
)
type Chat struct {
ID uuid.UUID
Title string
MemberIDs []uuid.UUID
CreatedAt time.Time
}
type CreateChat struct {
CreatorID uuid.UUID
Title string
MemberIDs []uuid.UUID
}
type ChatMember struct {
UserID uuid.UUID
ChatID uuid.UUID
}
type ChatFilters struct {
UserID uuid.UUID
Limit *int
AfterID *uuid.UUID
}
+38
View File
@@ -0,0 +1,38 @@
package dto
import (
"time"
"github.com/google/uuid"
)
type Message struct {
AttachmentIDs []uuid.UUID
ID uuid.UUID
ChatID uuid.UUID
SenderID uuid.UUID
Text string
CreatedAt time.Time
}
type CreateMessage struct {
AttachmentIDs []uuid.UUID
IdempotencyKey string
ChatID uuid.UUID
SenderID uuid.UUID
Text string
}
type MessageFilters struct {
ChatID uuid.UUID
UserID uuid.UUID
Limit *int
AfterID *uuid.UUID
}
// MessageAttachment contains only the data needed to authorize linking an attachment.
type MessageAttachment struct {
ID uuid.UUID
ChatID uuid.UUID
Missing bool
}
+25
View File
@@ -0,0 +1,25 @@
package dto
import (
"time"
"github.com/google/uuid"
)
// Page is a page of records with the ID to use for the next page.
type Page[T any] struct {
Items []T
NextCursorID *uuid.UUID
}
// PagePosition is a resolved database cursor, ordered by creation time and ID.
type PagePosition struct {
CreatedAt time.Time
ID uuid.UUID
}
// PageQuery is prepared by a service; Limit includes the lookahead row.
type PageQuery struct {
Limit int
After *PagePosition
}
+30
View File
@@ -0,0 +1,30 @@
package dto
import (
"time"
"github.com/google/uuid"
)
type User struct {
ID uuid.UUID
Username string
DisplayName string
CreatedAt time.Time
}
type CreateUser struct {
Username string
DisplayName string
Password string
}
// CreateStoredUser contains the prepared database record, never a plaintext password.
type CreateStoredUser struct {
ID uuid.UUID
Username string
DisplayName string
PasswordHash string `json:"-"`
CreatedAt time.Time
UpdatedAt time.Time
}