domain

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DeckSecretCodeLength = 10

Variables

This section is empty.

Functions

This section is empty.

Types

type Card

type Card struct {
	gorm.Model `swaggerignore:"true"` // Model from gorm package
	Question   string                 `json:"question"`                    // The question on the card
	Answer     string                 `json:"answer"`                      // The answer to the question on the card
	Mcq        Mcq                    `json:"mcq" gorm:"foreignKey:McqID"` // The multiple choice question associated with the card
	DeckID     uint                   `json:"deck_id"`                     // The ID of the deck the card belongs to
	McqID      uint                   `json:"mcq_id"`                      // The ID of the multiple choice question associated with the card
	CardType   CardType               `json:"card_type"`                   // The type of the card
}

Card represents a card in the domain model. It includes fields for the question, answer, multiple choice question (mcq), deck ID, mcq ID, and card type.

func (*Card) HasMcqType

func (c *Card) HasMcqType() bool

HasMcqType checks if the card is of a type that includes a multiple choice question.

func (*Card) IsBlankType

func (c *Card) IsBlankType() bool

IsBlankType checks if the card is of a blank type.

func (*Card) IsLinked

func (c *Card) IsLinked() bool

IsLinked checks if the card is linked to a multiple choice question.

func (*Card) IsMcqType

func (c *Card) IsMcqType() bool

IsMcqType checks if the card is of a type that is only a multiple choice question.

func (*Card) IsProgressiveType

func (c *Card) IsProgressiveType() bool

IsProgressiveType checks if the card is of a progressive type.

func (*Card) IsQAOnlyType

func (c *Card) IsQAOnlyType() bool

IsQAOnlyType checks if the card is of a type that is only a question and answer.

func (*Card) String

func (c *Card) String() string

String returns a string representation of the card.

func (*Card) TableName

func (*Card) TableName() string

TableName returns the name of the table in the database.

type CardType

type CardType int32

CardType represents the type of card.

const (
	CardTypeQAOnly           CardType = 0
	CardTypeMCQOnly          CardType = 1
	CardTypeQAProgressive    CardType = 2
	CardTypeBlankOnly        CardType = 3
	CardTypeBlankProgressive CardType = 4
	CardTypeBlankMCQ         CardType = 5
)

Constants representing the different types of cards.

func (CardType) String

func (c CardType) String() string

String returns the string representation of a CardType.

type CreateDeck

type CreateDeck struct {
	Name        string `json:"name" validate:"required"`
	Description string `json:"description" validate:"required"`
	Lang        string `json:"lang" validate:"required,len=2,alpha"`
	Banner      string `json:"banner" validate:"required,uri"`
}

CreateDeck is a struct that contains the data needed to create a deck.

func (*CreateDeck) ToDeck

func (c *CreateDeck) ToDeck() Deck

ToDeck converts the CreateDeck struct to a Deck struct.

func (*CreateDeck) Validate

func (c *CreateDeck) Validate() error

Validate validates the CreateDeck struct.

type Deck

type Deck struct {
	gorm.Model  `swaggerignore:"true"`
	Name        string     `json:"name"`
	Description string     `json:"description"`
	Lang        string     `json:"lang"`
	Key         string     `json:"key"`
	Banner      string     `json:"banner"`
	Learners    []*User    `json:"-" gorm:"many2many:user_decks;"`
	Cards       []Card     `json:"cards" gorm:"foreignKey:DeckID"`
	OwnerID     uint       `json:"owner_id"`
	Status      DeckStatus `json:"status"`
}

Deck is the domain model for a deck.

func (*Deck) IsOwner

func (d *Deck) IsOwner(id uint) bool

IsOwner checks if the deck is owned by the user with the given id.

func (*Deck) TableName

func (*Deck) TableName() string

TableName returns the table name for the deck model.

func (*Deck) ToPublicDeck

func (d *Deck) ToPublicDeck() PublicDeck

ToPublicDeck converts the deck to a public deck.

type DeckIndex

type DeckIndex map[string]interface{}

DeckIndex is the index of the deck for MeiliSearch search engine.

type DeckStatus

type DeckStatus int64

DeckStatus is the status of the deck.

const (
	DeckStatusPrivate  DeckStatus = 0 // DeckStatusPrivate is the private status of the deck
	DeckStatusToReview DeckStatus = 1 // DeckStatusToReview is the to review status of the deck
	DeckStatusPublic   DeckStatus = 2 // DeckStatusPublic is the public status of the deck
)

type DiscordLogin

type DiscordLogin struct {
	ID       string `json:"id"`
	Username string `json:"username"`
	Avatar   string `json:"avatar"`
	Email    string `json:"email"`
}

DiscordLogin is a struct that represents the Discord login response.

func (*DiscordLogin) ToUser

func (d *DiscordLogin) ToUser() User

ToUser converts the DiscordLogin to a User.

type GithubLogin

type GithubLogin struct {
	Login      string `json:"login"`
	NodeID     string `json:"node_id"`
	AvatarURL  string `json:"avatar_url"`
	GravatarID string `json:"gravatar_id"`
	URL        string `json:"url"`
	Bio        string `json:"bio"`
	Email      string `json:"email"`
	ID         int    `json:"id"`
}

GithubLogin is a struct that represents the Github login response.

func (*GithubLogin) ToUser

func (g *GithubLogin) ToUser() User

ToUser converts the GithubLogin to a User.

type Login

type Login struct {
	Email    string `json:"email" validate:"email"` // Email of the user
	Password string `json:"password"`               // Password of the user
}

Login is the login model.

type Mcq

type Mcq struct {
	gorm.Model `swaggerignore:"true"`
	Answers    string `json:"answers"`
	Linked     bool   `json:"linked"`
}

Mcq is the domain model for a mcq.

func (*Mcq) ExtractAnswers

func (m *Mcq) ExtractAnswers() []string

func (*Mcq) IsLinked

func (m *Mcq) IsLinked() bool

IsLinked returns true if the mcq is linked.

func (*Mcq) TableName

func (*Mcq) TableName() string

TableName returns the table name for the mcq model.

type Model

type Model interface {
	TableName() string
}

type Permission

type Permission int64

Permission is the permission level of a user.

const (
	PermissionNone  Permission = iota // PermissionNone is the default permission level.
	PermissionUser                    // PermissionUser is the permission level of a user.
	PermissionVip                     // PermissionVip is the permission level of a vip.
	PermissionAdmin                   // PermissionAdmin is the permission level of an admin.
)

func (Permission) IsValid

func (p Permission) IsValid() bool

func (Permission) String

func (p Permission) String() string

type PublicDeck

type PublicDeck struct {
	Name        string `json:"name"`        // Name of the deck
	Description string `json:"description"` // Description of the deck
	Lang        string `json:"lang"`        // Lang of the deck
	Banner      string `json:"banner"`      // Banner of the deck
	ID          uint   `json:"id"`          // ID of the deck
}

PublicDeck is the public deck model.

type PublicUser

type PublicUser struct {
	Username   string     `json:"username"`   // Username of the user
	Email      string     `json:"email"`      // Email of the user
	Avatar     string     `json:"avatar"`     // Avatar of the user
	ID         uint       `json:"id"`         // ID of the user
	Permission Permission `json:"permission"` // Permission of the user
}

PublicUser is the public user model.

type Register

type Register struct {
	Username string `json:"username" validate:"required"` // Username of the user
	Email    string `json:"email" validate:"email"`       // Email of the user
	Password string `json:"password" validate:"required"` // Password of the user
}

Register is the register model.

func (*Register) ToUser

func (r *Register) ToUser() User

ToUser converts the register model to a user.

func (*Register) Validate

func (r *Register) Validate() error

Validate validates the register model.

type Route

type Route struct {
	Handler    func(c *fiber.Ctx) error // Handler is the handler function for the route.
	Method     string                   // Method is the method of the route.
	Permission Permission               // Permission is the permission level of the route.
}

Route is a route for the API It contains the handler, method and permission level.

type User

type User struct {
	gorm.Model    `swaggerignore:"true"`
	Username      string     `json:"username"`
	Email         string     `json:"email" validate:"email" gorm:"unique"`
	Password      string     `json:"-"`
	Avatar        string     `json:"avatar"`
	OauthProvider string     `json:"oauth_provider" `
	OauthID       string     `json:"oauth_id" gorm:"unique"`
	Learning      []*Deck    `json:"learning" gorm:"many2many:user_decks;"`
	OwnDecks      []Deck     `json:"own_decks" gorm:"foreignKey:OwnerID"`
	Permission    Permission `json:"permission"`
	Oauth         bool       `json:"oauth" gorm:"default:false"`
}

User is the domain model for a user.

func (*User) HasPermission

func (u *User) HasPermission(permission Permission) bool

HasPermission checks if the user has the given permission.

func (*User) TableName

func (*User) TableName() string

TableName returns the table name for the user model.

func (*User) ToPublicUser

func (u *User) ToPublicUser() PublicUser

ToPublicUser converts the user to a public user.

func (*User) Validate

func (u *User) Validate() error

Validate validates the user.

type Validator added in v1.2.2

type Validator struct {
	// contains filtered or unexported fields
}

func GetValidatorInstance added in v1.2.2

func GetValidatorInstance() *Validator

func (*Validator) Validate added in v1.2.2

func (v *Validator) Validate() *validator.Validate

Jump to

Keyboard shortcuts

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