forked from mtusi2026/mtusi2026lab2
Начало реализации сервиса.
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/netip"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/authidentity"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/authprovider"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/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 Login struct {
|
||||
Email string
|
||||
Password string
|
||||
}
|
||||
|
||||
type Register struct {
|
||||
Email string
|
||||
Password string
|
||||
RepeatPassword string
|
||||
}
|
||||
|
||||
// ---- Auth Identities ----
|
||||
|
||||
type AuthIdentity struct {
|
||||
ID uuid.UUID
|
||||
Role role.Role
|
||||
UserID uuid.UUID
|
||||
Provider authprovider.Type
|
||||
Identifier string
|
||||
PasswordHash *string
|
||||
Status authidentity.Status
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
type UpdateAuthIdentity struct {
|
||||
ID uuid.UUID
|
||||
Role *role.Role
|
||||
Provider *authprovider.Type
|
||||
Identifier *string
|
||||
PasswordHash *string
|
||||
Status *authidentity.Status
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type UpdateAuthIdentityPasswordHash struct {
|
||||
ID uuid.UUID
|
||||
PasswordHash string
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type UpdateAuthIdentityStatus struct {
|
||||
ID uuid.UUID
|
||||
Status authidentity.Status
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type GetAuthIdentityByRoleAndUserID struct {
|
||||
Role role.Role
|
||||
UserID uuid.UUID
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
ID uuid.UUID
|
||||
ChatID uuid.UUID
|
||||
SenderID uuid.UUID
|
||||
Text string
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
type CreateMessage struct {
|
||||
ChatID uuid.UUID
|
||||
SenderID uuid.UUID
|
||||
Text string
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package dto
|
||||
|
||||
import "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
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user