feat: problem and submission framework
Co-authored-by: cxy004 <cxy004@qq.com> Co-authored-by: wzt <w.zhongtao@qq.com>
This commit is contained in:
parent
2ae99e2636
commit
2cec7d46bc
1
go.mod
1
go.mod
@ -9,6 +9,7 @@ require (
|
||||
github.com/gin-gonic/gin v1.8.1
|
||||
github.com/go-redis/redis/v8 v8.11.5
|
||||
github.com/golang-jwt/jwt/v4 v4.4.2
|
||||
github.com/lib/pq v1.10.2
|
||||
github.com/prometheus/client_golang v1.13.0
|
||||
github.com/swaggo/files v0.0.0-20220728132757-551d4a08d97a
|
||||
github.com/swaggo/gin-swagger v1.5.3
|
||||
|
3
go.sum
3
go.sum
@ -415,8 +415,9 @@ go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
||||
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
|
||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
|
||||
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
|
||||
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
|
||||
go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA=
|
||||
go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
|
||||
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
|
||||
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
|
||||
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
|
||||
|
@ -19,13 +19,13 @@ type loginRequest struct {
|
||||
// @Produce json
|
||||
// @Param username formData string true "username"
|
||||
// @Param password formData string true "password"
|
||||
// @Response 200 {object} e.Response "jwt token"
|
||||
// @Response 200 {object} e.Response "jwt token and user nickname"
|
||||
// @Router /v1/user/login [post]
|
||||
func (h *handler) Login(c *gin.Context) {
|
||||
req := new(loginRequest)
|
||||
|
||||
if err := c.ShouldBind(req); err != nil {
|
||||
e.Pong(c, e.InvalidParameter, err.Error())
|
||||
e.Pong(c, e.InvalidParameter, nil)
|
||||
return
|
||||
}
|
||||
|
||||
@ -52,5 +52,8 @@ func (h *handler) Login(c *gin.Context) {
|
||||
Version: version,
|
||||
}
|
||||
token, status := h.jwtService.SignClaim(claim)
|
||||
e.Pong(c, status, token)
|
||||
e.Pong(c, status, gin.H{
|
||||
"token": token,
|
||||
"nickname": user.NickName,
|
||||
})
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ func (h *handler) Profile(c *gin.Context) {
|
||||
req := new(profileRequest)
|
||||
if err := c.ShouldBind(req); err == nil {
|
||||
if req.UID != 0 && req.UID != uid {
|
||||
if role >= model.RoleAdmin {
|
||||
if role >= model.RoleGeneral {
|
||||
uid = req.UID
|
||||
} else {
|
||||
e.Pong(c, e.UserUnauthorized, nil)
|
||||
|
@ -1,14 +1,19 @@
|
||||
package model
|
||||
|
||||
import "gorm.io/gorm"
|
||||
import (
|
||||
"github.com/lib/pq"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Problem struct {
|
||||
gorm.Model `json:"meta"`
|
||||
Title string `json:"title" gorm:"not null"`
|
||||
Content string `json:"content" gorm:"not null"`
|
||||
TimeLimit uint `json:"time_limit" gorm:"not null"`
|
||||
MemoryLimit uint `json:"memory_limit" gorm:"not null"`
|
||||
ProviderID uint `json:"provider_id" gorm:"not null;index"`
|
||||
Provider User `json:"-" gorm:"foreignKey:ProviderID"`
|
||||
IsEnabled bool `json:"is_enabled" gorm:"not null;index"`
|
||||
Title string `json:"title" gorm:"not null"`
|
||||
Content string `json:"content" gorm:"not null"`
|
||||
TimeLimit uint `json:"time_limit" gorm:"not null"`
|
||||
MemoryLimit uint `json:"memory_limit" gorm:"not null"`
|
||||
ProviderID uint `json:"provider_id" gorm:"not null;index"`
|
||||
Provider User `json:"-" gorm:"foreignKey:ProviderID"`
|
||||
Languages pq.Int32Array `json:"languages" gorm:"type:int[]"`
|
||||
Points pq.Int32Array `json:"points" gorm:"type:int[]"`
|
||||
IsEnabled bool `json:"is_enabled" gorm:"not null;index"`
|
||||
}
|
||||
|
11
internal/repo/model/Status.go
Normal file
11
internal/repo/model/Status.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "gorm.io/gorm"
|
||||
|
||||
type Status struct {
|
||||
gorm.Model `json:"-"`
|
||||
SubmissionID uint `json:"submission_id" gorm:"not null;index"`
|
||||
Submission Submission `json:"-" gorm:"foreignKey:SubmissionID"`
|
||||
Verdict Verdict `json:"verdict" gorm:"not null"`
|
||||
Point int32 `json:"point" gorm:"not null"`
|
||||
}
|
13
internal/repo/model/Submission.go
Normal file
13
internal/repo/model/Submission.go
Normal file
@ -0,0 +1,13 @@
|
||||
package model
|
||||
|
||||
import "gorm.io/gorm"
|
||||
|
||||
type Submission struct {
|
||||
gorm.Model `json:"-"`
|
||||
ProblemID uint `json:"problem_id" gorm:"not null;index"`
|
||||
Problem Problem `json:"-" gorm:"foreignKey:ProblemID"`
|
||||
UserID uint `json:"user_id" gorm:"not null;index"`
|
||||
User User `json:"-" gorm:"foreignKey:UserID"`
|
||||
Language Lang `json:"language" gorm:"not null"`
|
||||
Code string `json:"code" gorm:"not null"`
|
||||
}
|
17
internal/repo/model/Verdict.go
Normal file
17
internal/repo/model/Verdict.go
Normal file
@ -0,0 +1,17 @@
|
||||
package model
|
||||
|
||||
type Verdict int
|
||||
|
||||
const (
|
||||
VerdictJudging Verdict = 1
|
||||
VerdictAccepted Verdict = 2
|
||||
VerdictWrongAnswer Verdict = 3
|
||||
VerdictTimeLimitExceeded Verdict = 4
|
||||
VerdictMemoryLimitExceeded Verdict = 5
|
||||
VerdictRuntimeError Verdict = 6
|
||||
VerdictCompileError Verdict = 7
|
||||
VerdictSystemError Verdict = 8
|
||||
VerdictJuryFailed Verdict = 9
|
||||
VerdictSkipped Verdict = 10
|
||||
VerdictPartiallyCorrect Verdict = 11
|
||||
)
|
@ -83,6 +83,7 @@ func (r *Repo) migrateDatabase() {
|
||||
|
||||
_ = r.db.AutoMigrate(&model.User{})
|
||||
_ = r.db.AutoMigrate(&model.Problem{})
|
||||
_ = r.db.AutoMigrate(&model.Submission{})
|
||||
}
|
||||
|
||||
// checkAlive deprecated
|
||||
|
24
internal/service/submission/service.go
Normal file
24
internal/service/submission/service.go
Normal file
@ -0,0 +1,24 @@
|
||||
package submission
|
||||
|
||||
import (
|
||||
"github.com/WHUPRJ/woj-server/internal/global"
|
||||
"github.com/WHUPRJ/woj-server/internal/repo/amqp"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var _ Service = (*service)(nil)
|
||||
|
||||
type Service interface {
|
||||
}
|
||||
|
||||
type service struct {
|
||||
log *zap.Logger
|
||||
mq *amqp.Repo
|
||||
}
|
||||
|
||||
func NewService(g *global.Global) Service {
|
||||
return &service{
|
||||
log: g.Log,
|
||||
mq: g.Mq.Get().(*amqp.Repo),
|
||||
}
|
||||
}
|
1
internal/service/submission/submit.go
Normal file
1
internal/service/submission/submit.go
Normal file
@ -0,0 +1 @@
|
||||
package submission
|
Loading…
Reference in New Issue
Block a user