Skip to content

Commit

Permalink
Limit invalid language
Browse files Browse the repository at this point in the history
  • Loading branch information
slhmy committed Oct 1, 2024
1 parent faf8128 commit d6d93e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions models/judge/judge.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ const (
ProgrammingLanguagePython ProgrammingLanguage = "Python"
)

func (sl ProgrammingLanguage) IsValid() bool {
switch sl {
case ProgrammingLanguageCpp, ProgrammingLanguageRust, ProgrammingLanguagePython:
return true
}
return false
}

// Using relationship according to https://gorm.io/docs/belongs_to.html
type Judge struct {
models.MetaFields
Expand Down
4 changes: 4 additions & 0 deletions services/judge/judge.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ func GetJudgeList(
func CreateJudge(
ctx context.Context, judge judge_model.Judge,
) (*judge_model.Judge, error) {
if !judge.Language.IsValid() {
return nil, fmt.Errorf("invalid language")
}

db := gorm_agent.GetDefaultDB()
newJudge, err := judge_model.CreateJudge(db, judge)
if err != nil {
Expand Down

0 comments on commit d6d93e6

Please sign in to comment.