diff --git a/cmd/clean/main.go b/cmd/clean/main.go index ef362ad..49a906c 100644 --- a/cmd/clean/main.go +++ b/cmd/clean/main.go @@ -50,10 +50,10 @@ func clearDB() { err := db.Migrator().DropTable( &user_model.User{}, &problem_model.Problem{}, - &problem_model.AlgorithmTag{}, + &problem_model.ProblemTag{}, &judge_model.Judge{}, &judge_model.JudgeResult{}, - "problem_algorithm_tags", + "problem_problem_tags", "casbin_rule", ) diff --git a/cmd/init/problem_package.go b/cmd/init/problem_package.go index 8db48ba..f59a1c1 100644 --- a/cmd/init/problem_package.go +++ b/cmd/init/problem_package.go @@ -78,7 +78,7 @@ func loadProblemPackages(ctx context.Context) { Slug: slug, Title: title, Description: &description, - Tags: []*problem_model.AlgorithmTag{ + Tags: []*problem_model.ProblemTag{ {Name: "to-be-add"}, }, }) diff --git a/go.mod b/go.mod index 45c9b00..383e202 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,10 @@ require ( gorm.io/gorm v1.25.10 ) -require github.com/stretchr/testify v1.9.0 +require ( + github.com/stretchr/testify v1.9.0 + github.com/swaggo/swag v1.16.3 +) require ( github.com/ClickHouse/ch-go v0.61.5 // indirect @@ -41,7 +44,6 @@ require ( github.com/segmentio/asm v1.2.0 // indirect github.com/shopspring/decimal v1.4.0 // indirect github.com/sourcegraph/conc v0.3.0 // indirect - github.com/swaggo/swag v1.16.3 // indirect go.opentelemetry.io/otel v1.26.0 // indirect go.opentelemetry.io/otel/trace v1.26.0 // indirect go.uber.org/multierr v1.11.0 // indirect diff --git a/models/problem/problem.go b/models/problem/problem.go index 6b67dea..42564dc 100644 --- a/models/problem/problem.go +++ b/models/problem/problem.go @@ -4,16 +4,17 @@ import "github.com/oj-lab/oj-lab-platform/models" type Problem struct { models.MetaFields - Slug string `json:"slug" gorm:"primaryKey"` - Title string `json:"title" gorm:"not null"` - Description *string `json:"description,omitempty"` - Tags []*AlgorithmTag `json:"tags" gorm:"many2many:problem_algorithm_tags;"` + Slug string `json:"slug" gorm:"primaryKey"` + Title string `json:"title" gorm:"not null"` + Description *string `json:"description,omitempty"` + Tags []*ProblemTag `json:"tags" gorm:"many2many:problem_problem_tags;"` + Solved bool `json:"solved,omitempty" gorm:"-"` } -type AlgorithmTag struct { +type ProblemTag struct { models.MetaFields Name string `json:"name" gorm:"primaryKey"` - Problems []*Problem `json:"problems,omitempty" gorm:"many2many:problem_algorithm_tags;"` + Problems []*Problem `json:"problems,omitempty" gorm:"many2many:problem_problem_tags;"` } var ProblemInfoSelection = append([]string{"slug", "title"}, models.MetaFieldsSelection...) diff --git a/models/problem/problem_db.go b/models/problem/problem_db.go index 1161557..d74f229 100644 --- a/models/problem/problem_db.go +++ b/models/problem/problem_db.go @@ -35,7 +35,7 @@ type GetProblemOptions struct { Selection []string Slug *string Title *string - Tags []*AlgorithmTag + Tags []*ProblemTag Offset *int Limit *int } @@ -51,8 +51,8 @@ func buildGetProblemTXByOptions(tx *gorm.DB, options GetProblemOptions, isCount } if len(tagsList) > 0 { tx = tx. - Joins("JOIN problem_algorithm_tags ON problem_algorithm_tags.problem_slug = problems.slug"). - Where("problem_algorithm_tags.algorithm_tag_name in ?", tagsList) + Joins("JOIN problem_problem_tags ON problem_problem_tags.problem_slug = problems.slug"). + Where("problem_problem_tags.problem_tag_name in ?", tagsList) } if options.Slug != nil { tx = tx.Where("slug = ?", *options.Slug) diff --git a/models/problem/problem_test.go b/models/problem/problem_test.go index c2ee8e7..fa4d3f1 100644 --- a/models/problem/problem_test.go +++ b/models/problem/problem_test.go @@ -15,7 +15,7 @@ func TestProblemDB(t *testing.T) { Slug: "a-plus-b-problem", Title: "A+B Problem", Description: &description, - Tags: []*AlgorithmTag{{Name: "tag1"}, {Name: "tag2"}}, + Tags: []*ProblemTag{{Name: "tag1"}, {Name: "tag2"}}, } err := CreateProblem(db, problem) @@ -36,7 +36,7 @@ func TestProblemDB(t *testing.T) { problemOption := GetProblemOptions{ Selection: ProblemInfoSelection, - Tags: []*AlgorithmTag{{Name: "tag1"}}, + Tags: []*ProblemTag{{Name: "tag1"}}, Slug: &problem.Slug, }