Skip to content

Commit

Permalink
Fix models, migration, resources and routes for cause
Browse files Browse the repository at this point in the history
  • Loading branch information
suntt2019 committed Aug 31, 2021
1 parent b6ecae5 commit d084bfd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
12 changes: 8 additions & 4 deletions app/response/resource/cause.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package resource

import "github.com/EduOJ/backend/database/models"
import (
"github.com/EduOJ/backend/database/models"
)

type CauseForAdmin struct {
ID uint `son:"id"`
Expand All @@ -9,11 +11,12 @@ type CauseForAdmin struct {

Hash string `json:"output_stripped_hash"`
Description string `json:"description"`
Marked bool `json:"marked"`

// Point: Points to be subtracted for this cause
Point uint `json:"point"`
Marked bool `json:"marked"`
Count uint `json:"count"`
Point uint `json:"point"`
Count uint `json:"count"`
OutputURL string `json:"output_url"`
}

type Cause struct {
Expand All @@ -37,6 +40,7 @@ func (c *CauseForAdmin) convert(cause *models.Cause) {
c.Point = cause.Point
c.Marked = cause.Marked
c.Count = cause.Count
c.OutputURL = cause.OutputURL
}

func (c *Cause) convert(cause *models.Cause) {
Expand Down
22 changes: 14 additions & 8 deletions app/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,24 @@ func Register(e *echo.Echo) {
updateProblem.PUT("/admin/problem/:id/test_case/:test_case_id", controller.UpdateTestCase).Name = "problem.updateTestCase"
updateProblem.DELETE("/admin/problem/:id/test_case/all", controller.DeleteTestCases).Name = "problem.deleteTestCases"
updateProblem.DELETE("/admin/problem/:id/test_case/:test_case_id", controller.DeleteTestCase).Name = "problem.deleteTestCase"

// cause APIs
api.GET("/problem/:id/test_case/:test_case_id/cause/:cause_id", controller.Todo,
cause := api.Group("",
middleware.ValidateParams(map[string]string{
"id": "NOT_FOUND",
"test_case_id": "TEST_CASE_NOT_FOUND",
"cause_id": "CAUSE_NOT_FOUND",
"problem_id": "NOT_FOUND",
"id": "NOT_FOUND",
}),
middleware.Logged,
).Name = "problem.getCause"
readProblemSecret.GET("/problem/:id/test_case/:test_case_id/causes", controller.Todo).Name = "problem.getCauses"
updateProblem.PUT("/problem/:id/test_case/:test_case_id/cause/:cause_id", controller.Todo).Name = "problem.updateCause"
updateProblem.DELETE("/problem/:id/test_case/:test_case_id/cause/:cause_id", controller.Todo).Name = "problem.deleteCause"
middleware.HasPermission(middleware.OrPermission{
A: middleware.UnscopedPermission{P: "mark_causes"},
B: middleware.ScopedPermission{P: "mark_causes", T: "problem", IdFieldName: "problem_id"},
}),
)
cause.GET("/problem/:problem_id/cause/:id", controller.Todo).Name = "problem.getCause"
cause.GET("/problem/:problem_id/causes", controller.Todo).Name = "problem.getCauses"
cause.GET("/causes", controller.Todo).Name = "problem.getAllCauses"
cause.PUT("/problem/:problem_id/cause/:id", controller.Todo).Name = "problem.updateCause"
cause.DELETE("/problem/:problem_id/cause/:id", controller.Todo).Name = "problem.deleteCause"

// submission APIs
submission := api.Group("",
Expand Down
9 changes: 5 additions & 4 deletions database/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -1206,13 +1206,14 @@ func GetMigration() *gormigrate.Gormigrate {
TestCaseID uint `sql:"index" json:"test_case_id"`
TestCase *TestCase `json:"test_case"`

Hash string `json:"hash" gorm:"index;not null;size:255;default:''"`
Hash string `json:"output_stripped_hash" gorm:"index;not null;size:255;default:''"`
Description string `json:"description"`
Marked bool `json:"marked" gorm:"default:false;not null"`

// Point: Points to be subtracted for this cause
Point uint `json:"point" gorm:"default:0;not null"`
Marked bool `json:"marked" gorm:"default:false;not null"`
Count uint `json:"count" gorm:"default:0;not null"`
Point uint `json:"point" gorm:"default:0;not null"`
Count uint `json:"count" gorm:"default:0;not null"`
OutputURL string `json:"output_url" gorm:"-"`

CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"-"`
Expand Down
7 changes: 4 additions & 3 deletions database/models/cause.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ type Cause struct {

Hash string `json:"output_stripped_hash" gorm:"index;not null;size:255;default:''"`
Description string `json:"description"`
Marked bool `json:"marked" gorm:"default:false;not null"`

// Point: Points to be subtracted for this cause
Point uint `json:"point" gorm:"default:0;not null"`
Marked bool `json:"marked" gorm:"default:false;not null"`
Count uint `json:"count" gorm:"default:0;not null"`
Point uint `json:"point" gorm:"default:0;not null"`
Count uint `json:"count" gorm:"default:0;not null"`
OutputURL string `json:"output_url" gorm:"-"`

CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"-"`
Expand Down

0 comments on commit d084bfd

Please sign in to comment.