problem_model

package
v0.0.0-...-9bad8b2 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2025 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultProblemDifficulty = ProblemDifficultyEasy

Variables

View Source
var ProblemInfoSelection = append([]string{"slug", "title", "difficulty", "accept_count", "submit_count"}, models.MetaFieldsSelection...)

Functions

func CountProblemByOptions

func CountProblemByOptions(tx *gorm.DB, options GetProblemOptions) (int64, error)

func CreateProblem

func CreateProblem(tx *gorm.DB, problem Problem) error

func DeleteProblem

func DeleteProblem(tx *gorm.DB, slug string) error

func GetTagsList

func GetTagsList(problem Problem) []string

func UpdateProblem

func UpdateProblem(tx *gorm.DB, problem Problem) error

Types

type GetProblemOptions

type GetProblemOptions struct {
	Selection  []string
	Slug       string
	TitleQuery string
	Difficulty ProblemDifficulty
	Tags       []*ProblemTag
	Offset     *int
	Limit      *int
}

type Problem

type Problem struct {
	models.MetaFields
	Slug        string            `json:"slug" gorm:"primaryKey"`
	Title       string            `json:"title" gorm:"not null"`
	Description *string           `json:"description,omitempty"`
	Difficulty  ProblemDifficulty `json:"difficulty,omitempty"`
	Tags        []*ProblemTag     `json:"tags" gorm:"many2many:problem_problem_tags;"`
	Solved      *bool             `json:"solved,omitempty" gorm:"-"`
	AcceptCount int               `json:"acceptCount"`
	SubmitCount int               `json:"submitCount"`
}

func GetProblem

func GetProblem(tx *gorm.DB, slug string) (*Problem, error)

func GetProblemListByOptions

func GetProblemListByOptions(tx *gorm.DB, options GetProblemOptions) ([]Problem, error)

func (Problem) ToProblemInfo

func (p Problem) ToProblemInfo() ProblemInfoView

type ProblemDifficulty

type ProblemDifficulty string
const (
	ProblemDifficultyEasy   ProblemDifficulty = "easy"
	ProblemDifficultyMedium ProblemDifficulty = "medium"
	ProblemDifficultyHard   ProblemDifficulty = "hard"
)

func (ProblemDifficulty) IsValid

func (d ProblemDifficulty) IsValid() bool

type ProblemInfoView

type ProblemInfoView struct {
	Slug       string            `json:"slug"`
	Title      string            `json:"title"`
	Difficulty ProblemDifficulty `json:"difficulty"`
	Tags       []ProblemTagView  `json:"tags"`
	Solved     *bool             `json:"solved,omitempty"`
	PassRate   float32           `json:"passRate"`
}

func GetProblemInfoViewList

func GetProblemInfoViewList(problems []Problem) []ProblemInfoView

type ProblemTag

type ProblemTag struct {
	models.MetaFields
	Name     string     `json:"name" gorm:"primaryKey"`
	Problems []*Problem `json:"problems,omitempty" gorm:"many2many:problem_problem_tags;"`
}

func (ProblemTag) ToProblemTagView

func (pt ProblemTag) ToProblemTagView() ProblemTagView

type ProblemTagView

type ProblemTagView struct {
	models.MetaFields
	Name string `json:"name"`
}

func GetProblemTagViewList

func GetProblemTagViewList(tags []*ProblemTag) []ProblemTagView

Jump to

Keyboard shortcuts

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