models

package
v0.0.0-...-392719a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidUserID            = errors.New("invalid user ID")
	ErrInvalidProvider          = errors.New("invalid provider")
	ErrInvalidProviderAccountID = errors.New("invalid provider account ID")
)
View Source
var (
	ErrInvalidToken     = errors.New("invalid token")
	ErrInvalidExpiresAt = errors.New("invalid expires at")
)
View Source
var (
	ErrInvalidUserName = errors.New("invalid user name")
	ErrInvalidRole     = errors.New("invalid role")
)

Functions

This section is empty.

Types

type APIAccount

type APIAccount struct {
	ID                int       `json:"id"`
	UserID            int       `json:"user_id"`
	Provider          string    `json:"provider"`
	ProviderAccountID string    `json:"provider_account_id"`
	AccessToken       string    `json:"access_token"`
	RefreshToken      string    `json:"refresh_token"`
	ExpiresAt         time.Time `json:"expires_at"`
	Scope             string    `json:"scope"`
	CreatedAt         time.Time `json:"created_at"`
	UpdatedAt         time.Time `json:"updated_at"`
}

func (*APIAccount) ToAccount

func (a *APIAccount) ToAccount() *Account

type APISession

type APISession struct {
	ID        int       `json:"id"`
	Token     string    `json:"token"`
	UserID    int       `json:"user_id"`
	IPAddress string    `json:"ip_address"`
	ExpiresAt time.Time `json:"expires_at"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

func (*APISession) ToSession

func (s *APISession) ToSession() *Session

type APIUser

type APIUser struct {
	ID          int       `json:"id"`
	Name        string    `json:"name"`
	DisplayName string    `json:"display_name"`
	Email       string    `json:"email"`
	Avatar      string    `json:"avatar"`
	Role        Role      `json:"role"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

func (*APIUser) ToUser

func (u *APIUser) ToUser() *User

type Account

type Account struct {
	ID                int            `json:"id"`
	UserID            int            `json:"user_id"`
	Provider          string         `json:"provider"`
	ProviderAccountID string         `json:"provider_account_id"`
	AccessToken       sql.NullString `json:"access_token"`
	RefreshToken      sql.NullString `json:"refresh_token"`
	ExpiresAt         sql.NullTime   `json:"expires_at"`
	Scope             sql.NullString `json:"scope"`
	CreatedAt         time.Time      `json:"created_at"`
	UpdatedAt         time.Time      `json:"updated_at"`
}

func NewAccount

func NewAccount(userID int, provider, providerAccountID, accessToken, refreshToken string, expiresAt time.Time, scope string) *Account

func (*Account) ToAPIAccount

func (a *Account) ToAPIAccount() *APIAccount

func (*Account) UpdateTokens

func (a *Account) UpdateTokens(accessToken, refreshToken string, expiresAt time.Time)

func (*Account) Validate

func (a *Account) Validate() error

type Role

type Role string
const (
	RoleUser  Role = "user"
	RoleAdmin Role = "admin"
)

type Session

type Session struct {
	ID        int            `json:"id"`
	Token     string         `json:"token"`
	UserID    int            `json:"user_id"`
	IPAddress sql.NullString `json:"ip_address"`
	ExpiresAt time.Time      `json:"expires_at"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
}

func NewSession

func NewSession(token string, userID int, ipAddress string, expiresAt time.Time) *Session

func (*Session) IsExpired

func (s *Session) IsExpired() bool

func (*Session) IsRefreshNeeded

func (s *Session) IsRefreshNeeded() bool

func (*Session) ToAPISession

func (s *Session) ToAPISession() *APISession

func (*Session) Validate

func (s *Session) Validate() error

type User

type User struct {
	ID          int            `json:"id"`
	Name        string         `json:"name"`
	DisplayName sql.NullString `json:"display_name"`
	Email       sql.NullString `json:"email"`
	Avatar      sql.NullString `json:"avatar"`
	Role        Role           `json:"role"`
	CreatedAt   time.Time      `json:"created_at"`
	UpdatedAt   time.Time      `json:"updated_at"`
}

func NewUser

func NewUser(name, displayName, email, avatar string, role Role) *User

func (*User) ToAPIUser

func (u *User) ToAPIUser() *APIUser

func (*User) Validate

func (u *User) Validate() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL