dto

package
v0.0.0-...-6a26343 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Deserialize

func Deserialize[T Deserializable](body []byte) (*T, error)

Types

type ApiPayload

type ApiPayload[T ApiResponseBody] struct {
	Body  T      `json:"body"`
	Error string `json:"error"`
}

func NewApiPayload

func NewApiPayload[T ApiResponseBody](payload T, error string) ApiPayload[T]

type ApiResponseBody

type ApiResponseBody interface {
	Comment | Country | *User | Vote | *NewUser | []*NewUser | SessionAuth |
		[]Comment | []Country | []User | []Vote | map[uuid.UUID]User | []Result
}

type Auth

type Auth struct {
	Token      string //session token
	Expiration time.Time
	UserId     uuid.UUID
	AuthLvl    enum.AuthLvl
}

Auth is used internally to verify a user, auth level, and expiration of session. The token refers to a session token, not auth token. It should never be returned to a user

func (Auth) ToSession

func (a Auth) ToSession(user User, cookie http.Cookie) SessionAuth

type ChatResponseBody

type ChatResponseBody interface {
	*Comment | []Comment | SocketError | UpdateMessage | *NewUser
}

type Comment

type Comment struct {
	UUID      uuid.UUID `json:"id"`
	UserId    uuid.UUID `json:"userId"`
	Text      string    `json:"text"`
	FileName  string    `json:"fileName"`
	CreatedAt time.Time `json:"createdAt"`
	ReplyTo   *Comment  `json:"replyToComment,omitempty"`
}

func (Comment) Validate

func (c Comment) Validate() *errs.AppError

type CookieOpts

type CookieOpts struct {
	Path     string `json:"path"`
	MaxAge   int    `json:"maxAge"`
	Secure   bool   `json:"secure"`
	HttpOnly bool
	SameSite string
	Domain   string
}

type Country

type Country struct {
	Name          string `json:"name"`
	Slug          string `json:"slug"`
	BandName      string `json:"bandName"`
	SongName      string `json:"songName"`
	Flag          string `json:"flag"`
	Participating bool   `json:"participating"`
}

type Deserializable

type Deserializable interface {
	Country | User | Vote | VoteSingle
}

type NewUser

type NewUser struct {
	Name    string       `json:"name"`
	Slug    string       `json:"slug"`
	UUID    uuid.UUID    `json:"id"`
	AuthLvl enum.AuthLvl `json:"authLvl"`
	Token   string       `json:"token"`
}

func (*NewUser) Slugify

func (nu *NewUser) Slugify()

type Result

type Result struct {
	CountrySlug string `json:"countrySlug"`
	Costume     int    `json:"costume"`
	Song        int    `json:"song"`
	Performance int    `json:"performance"`
	Props       int    `json:"props"`
	Total       int    `json:"total"`
}

type SessionAuth

type SessionAuth struct {
	Name         string
	SessionToken string     `json:"token"`
	CookieOpts   CookieOpts `json:"opts"`
	User         User       `json:"user"`
	Bot          uuid.UUID  `json:"botId"`
}

SessionAuth gets returned to users when they log in

type SocketError

type SocketError string

type SocketMessage

type SocketMessage struct {
	Category enum.ChatMsgType `json:"category"`
	Body     json.RawMessage  `json:"body"`
}

func NewSocketErrorMessage

func NewSocketErrorMessage(message string) SocketMessage

NewSocketErrorMessage can be passed an empty string to get the default message

func NewSocketMessage

func NewSocketMessage[T ChatResponseBody](category enum.ChatMsgType, payload T) SocketMessage

type UpdateMessage

type UpdateMessage struct {
	UpdatedUser User    `json:"updatedUser"`
	Comment     Comment `json:"comment"`
}

type User

type User struct {
	UUID    uuid.UUID    `json:"id"`
	Name    string       `json:"name"`
	Slug    string       `json:"slug"`
	Icon    string       `json:"icon"`
	AuthLvl enum.AuthLvl `json:"authLvl"`
}

func (User) Validate

func (u User) Validate() *errs.AppError

type UserAvatar

type UserAvatar struct {
	UUID    uuid.UUID
	File    multipart.File
	Header  *multipart.FileHeader
	CropBox image.Rectangle
}

type Vote

type Vote struct {
	UserId      uuid.UUID `json:"userId"`
	CountrySlug string    `json:"countrySlug"`
	Costume     uint8     `json:"costume"`
	Song        uint8     `json:"song"`
	Performance uint8     `json:"performance"`
	Props       uint8     `json:"props"`
}

type VoteSingle

type VoteSingle struct {
	UserId      uuid.UUID       `json:"userId"`
	CountrySlug string          `json:"countrySlug"`
	Cat         enum.Categories `json:"cat"`
	Score       uint8           `json:"score"`
}

func (VoteSingle) Validate

func (v VoteSingle) Validate() *errs.AppError

Jump to

Keyboard shortcuts

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