diff --git a/models/judge/judge.go b/models/judge/judge.go index 75b3148..b984bde 100644 --- a/models/judge/judge.go +++ b/models/judge/judge.go @@ -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 diff --git a/services/judge/judge.go b/services/judge/judge.go index 2ae149e..98162de 100644 --- a/services/judge/judge.go +++ b/services/judge/judge.go @@ -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 {