models

package
v0.0.0-...-f47b430 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AdminRole = iota
	StaffRole
	UserRole
)

Variables

View Source
var SessionCache = cache.NewMemoryCache[Session]()

Functions

func CreateRecord

func CreateRecord[T ST](t T) error

func DeleteRecord

func DeleteRecord[T ST](t T) error

func DeleteRecordByID

func DeleteRecordByID[T ST](ID uint) (T, error)

func GetAllRecords

func GetAllRecords[T ST]() ([]T, error)

func GetRecordByExp

func GetRecordByExp[T ST](query any, args ...any) (T, error)

func GetRecordByID

func GetRecordByID[T ST](ID string) (T, error)

func GetRecordByModel

func GetRecordByModel[T ST](t T, preloads ...string) error

func GetUserByUsername

func GetUserByUsername(username string, u *User) error

func GetUserByUsernameOrEmail

func GetUserByUsernameOrEmail(username, email string, u *User) error

func GetVerifyEmailUsingIDToken

func GetVerifyEmailUsingIDToken(id, token string, ve *VerifyEmail) error

func UpdateRecord

func UpdateRecord[T ST](t T) error

Types

type CheckerType

type CheckerType string
const (
	Default CheckerType = "Default"
	String  CheckerType = "String"
	Float   CheckerType = "Float"
	Special CheckerType = "Special"
)

type Contest

type Contest struct {
	gorm.Model
}

type Dataset

type Dataset struct {
	gorm.Model
	Title    string
	Weight   int64 `gorm:"default:100;index:,sort:desc"`
	IsSample bool
	// todo: change to file store, because it's too expensive
	Input  []byte
	Output []byte

	UserID    uint
	AddedBy   *User `gorm:"foreignKey:UserID"`
	ProblemID uint
	Problem   *Problem
}

type Language

type Language struct {
	gorm.Model
	Name string `gorm:"unique;required"`
}

type PermitType

type PermitType string
const (
	Author PermitType = "Author"
	Editor PermitType = "Editor"
	Viewer PermitType = "Viewer"
	Tester PermitType = "Tester"
)

func (PermitType) IsPermitTypeValid

func (t PermitType) IsPermitTypeValid() bool

type Problem

type Problem struct {
	gorm.Model
	AuthorID  uint
	Author    *User    `gorm:"required;foreignKey:AuthorID" json:"-"`
	ContestID *uint    `json:"contestID"`
	Contest   *Contest `json:"contest"`
	Title     string   `gorm:"Index;not null;type:varchar(55)"`

	TimeLimit                         float64
	MemoryLimit                       float64
	Statement                         string
	InputStatement                    string
	OutputStatement                   string
	NoteStatement                     string
	StatementsVisibilityDuringContest bool

	Tags      []ProblemTag
	Datasets  []Dataset
	Solutions []ProblemSolution

	IsProblemPublishable bool        `gorm:"default:false"`
	IsProblemPublished   bool        `gorm:"default:false"`
	CheckerType          CheckerType `gorm:"default:Default"`
	SharedWith           []ProblemShare
	ChangeLogs           []ProblemChangeLog
	Discussions          []ProblemDiscussion
}

func (*Problem) FindSharedUser

func (p *Problem) FindSharedUser(userID uint) *ProblemShare

func (*Problem) GetSharedUserColumnName

func (p *Problem) GetSharedUserColumnName() string

func (*Problem) GetSharedWithColumnName

func (p *Problem) GetSharedWithColumnName() string

type ProblemChangeLog

type ProblemChangeLog struct {
	gorm.Model
	LogMessage string

	UserID    uint
	User      *User
	ProblemID uint
	Problem   *Problem

	OwnerShipType PermitType
	ChangedAt     time.Time
}

type ProblemDiscussion

type ProblemDiscussion struct {
	gorm.Model
	Message string

	UserID    uint
	User      *User
	ProblemID uint
	Problem   *Problem
	SentAt    time.Time
}

type ProblemShare

type ProblemShare struct {
	gorm.Model
	UserID         uint
	SharedWith     *User `gorm:"foreignKey:UserID"`
	ProblemID      uint
	Problem        *Problem
	PermissionType PermitType `gorm:"default:Viewer"`
}

func (*ProblemShare) CanAddDataset

func (ps *ProblemShare) CanAddDataset() bool

func (*ProblemShare) CanAddSolution

func (ps *ProblemShare) CanAddSolution() bool

type ProblemSolution

type ProblemSolution struct {
	gorm.Model
	Code         string
	LanguageID   uint
	Language     *Language
	LastExecuted *time.Time
	TimeTaken    *float64
	MemoryTaken  *float64

	UserID    uint
	User      *User
	ProblemId uint
	Problem   *Problem
}

type ProblemSpecialChecker

type ProblemSpecialChecker struct {
	gorm.Model
	Code       string
	LanguageID uint
	Language   *Language

	UserID        uint
	User          *User
	ProblemId     uint
	Problem       *Problem
	OwnerShipType PermitType
}

type ProblemTag

type ProblemTag struct {
	gorm.Model
	TagID     uint `json:"tagID"`
	Tag       *Tag
	ProblemID uint
	Problem   *Problem
}

type Session

type Session struct {
	ID        uuid.UUID `gorm:"primarykey"`
	UserID    uint
	User      *User
	UserAgent string
	IsBlocked bool `gorm:"default:0"`
	ClientIP  string
	ExpiresAt time.Time

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt time.Time `gorm:"index;default:null"`
}

type Tag

type Tag struct {
	gorm.Model
	TagName string `gorm:"unique;index"`
	UserID  uint
	AddedBy *User `gorm:"foreignKey:UserID"`
}

type User

type User struct {
	gorm.Model
	Username         string `gorm:"uniqueIndex;not null"`
	Email            string `gorm:"uniqueIndex,omitempty;default:null"`
	KeepEmailPrivate bool   `gorm:"default:1"`
	Password         string `gorm:"not null"`
	Role             uint   `gorm:"default:2"`
	Verified         bool   `gorm:"default:0"`

	DisplayName  string
	Organization string
	Country      string
	City         string
	Image        string
}

func (*User) CheckPassword

func (u *User) CheckPassword(plain string) error

func (*User) ExtractEmail

func (u *User) ExtractEmail() string

func (*User) HashPassword

func (u *User) HashPassword() error

type VerifyEmail

type VerifyEmail struct {
	gorm.Model
	Token          string `gorm:"uniqueIndex;not null"`
	Email          string `gorm:"not null"`
	ExpirationTime time.Time
	IsUsed         bool
	UserId         uint
	User           User
}

func (*VerifyEmail) ExtractEmail

func (ve *VerifyEmail) ExtractEmail() string

func (*VerifyEmail) FillEmailVerifierInfo

func (ve *VerifyEmail) FillEmailVerifierInfo(u *User) error
func (ve *VerifyEmail) GenerateLink() string

func (*VerifyEmail) GenerateToken

func (ve *VerifyEmail) GenerateToken() error

func (*VerifyEmail) IsLinkExpired

func (ve *VerifyEmail) IsLinkExpired() error

func (*VerifyEmail) IsLinkUsed

func (ve *VerifyEmail) IsLinkUsed() bool

func (*VerifyEmail) SetExpirationTime

func (ve *VerifyEmail) SetExpirationTime()

func (*VerifyEmail) VerifiedUser

func (ve *VerifyEmail) VerifiedUser() *User

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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