From 810cbf39e1630759cf0c224c2b81a6cdf1fe51c9 Mon Sep 17 00:00:00 2001 From: slhmy Date: Wed, 31 Jul 2024 09:26:34 +0800 Subject: [PATCH] Tidy code --- cmd/web_server/handler/problem.go | 9 ++------- models/judge/judge_db.go | 4 +--- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/cmd/web_server/handler/problem.go b/cmd/web_server/handler/problem.go index d4dfb2a..5e1e4c1 100644 --- a/cmd/web_server/handler/problem.go +++ b/cmd/web_server/handler/problem.go @@ -38,18 +38,13 @@ func SetupProblemRouter(baseRoute *gin.RouterGroup) { func getProblem(ginCtx *gin.Context) { slug := ginCtx.Param("slug") - problemInfo, err := problem_service.GetProblem(ginCtx, slug) + problem, err := problem_service.GetProblem(ginCtx, slug) if err != nil { _ = ginCtx.Error(err) return } - ginCtx.JSON(200, gin.H{ - "slug": problemInfo.Slug, - "title": problemInfo.Title, - "description": problemInfo.Description, - "tags": problem_model.GetTagsList(*problemInfo), - }) + ginCtx.JSON(200, problem) } // putProblem diff --git a/models/judge/judge_db.go b/models/judge/judge_db.go index a82c6f1..f0c2f27 100644 --- a/models/judge/judge_db.go +++ b/models/judge/judge_db.go @@ -52,9 +52,7 @@ func buildGetJudgeTXByOptions( tx *gorm.DB, options GetJudgeOptions, isCount bool, ) *gorm.DB { tx = tx.Model(&Judge{}). - Preload(clause.Associations) - // See more in: https://gorm.io/docs/preload.html - // Preload("User.Roles").Preload("Problem.Tags").Preload(clause.Associations) + Preload(clause.Associations) // See more in: https://gorm.io/docs/preload.html if len(options.Selection) > 0 { tx = tx.Select(options.Selection) }