完成基础model部分

This commit is contained in:
2022-05-25 17:30:46 +08:00
parent ddec628641
commit 9bb43f4484
18 changed files with 498 additions and 0 deletions

15
models/entity/category.go Normal file
View File

@@ -0,0 +1,15 @@
package entity
import "online_code/common/types"
// Category 分类表
type Category struct {
types.BaseDbModel
Identity string `json:"identity" gorm:"column:identity;type:varchar(36);comment:'分类的唯一标识'"`
Name string `json:"name" gorm:"column:name;type:varchar(100);comment:'分类名称'" `
ParentId int `json:"parent_id" gorm:"column:parent_id;type:int(11);comment:'父级ID'" `
}
func (table *Category) TableName() string {
return "category"
}

21
models/entity/problem.go Normal file
View File

@@ -0,0 +1,21 @@
package entity
import "online_code/common/types"
// Problem 问题表
type Problem struct {
types.BaseDbModel
Identity string `json:"identity" gorm:"column:identity;type:varchar(36);comment:'问题表的唯一标识'" ` // 问题表的唯一标识
ProblemCategories []*ProblemCategory `json:"problem_categories" gorm:"foreignKey:problem_id;references:id;comment:'关联问题分类表'" ` // 关联问题分类表
Title string `json:"title" gorm:"column:title;type:varchar(255);comment:'文章标题'" ` // 文章标题
Content string `json:"content" gorm:"column:content;type:text;comment:'文章正文'" ` // 文章正文
MaxRuntime int `json:"max_runtime" gorm:"column:max_runtime;type:int(11);comment:'最大运行时长'" ` // 最大运行时长
MaxMem int `json:"max_mem" gorm:"column:max_mem;type:int(11);comment:'最大运行内存'" ` // 最大运行内存
TestCases []*TestCase `json:"test_cases" gorm:"foreignKey:problem_identity;references:identity;comment:'关联测试用例表'" ` // 关联测试用例表
PassNum int64 `json:"pass_num" gorm:"column:pass_num;type:int(11);comment:'通过次数'" ` // 通过次数
SubmitNum int64 `json:"submit_num" gorm:"column:submit_num;type:int(11);comment:'提交次数'" ` // 提交次数
}
func (table *Problem) TableName() string {
return "problem_basic"
}

View File

@@ -0,0 +1,17 @@
package entity
import (
"online_code/common/types"
)
// ProblemCategory 问题分类表
type ProblemCategory struct {
types.BaseDbModel
ProblemId uint `json:"problem_id" gorm:"column:problem_id;type:int(11);comment:'问题的ID'" ` // 问题的ID
CategoryId uint `json:"category_id" gorm:"column:category_id;type:int(11);comment:'分类的ID'" ` // 分类的ID
CategoryBasic *Category `json:"category_basic" gorm:"foreignKey:id;references:category_id;comment:'关联分类的基础信息表'" ` // 关联分类的基础信息表
}
func (table *ProblemCategory) TableName() string {
return "problem_category"
}

16
models/entity/submit.go Normal file
View File

@@ -0,0 +1,16 @@
package entity
// Submit 提交表
type Submit struct {
Identity string `json:"identity" gorm:"column:identity;type:varchar(36);comment:'用户唯一标识'" ` // 唯一标识
ProblemIdentity string `json:"problem_identity" gorm:"column:problem_identity;type:varchar(36);comment:'问题表的唯一标识'" ` // 问题表的唯一标识
ProblemBasic *Problem `json:"problem_basic" gorm:"foreignKey:identity;references:problem_identity;comment:'关联问题基础表'" ` // 关联问题基础表
UserIdentity string `json:"user_identity" gorm:"column:user_identity;type:varchar(36);comment:'用户表的唯一标识'" ` // 用户表的唯一标识
UserBasic *User `json:"user_basic" gorm:"foreignKey:identity;references:user_identity;comment:'联用户基础表'" ` // 关联用户基础表
Path string `json:"path" gorm:"column:path;type:varchar(255);comment:'代码存放路径'" ` // 代码存放路径
Status int `json:"status" gorm:"column:status;type:tinyint(1);comment:'状态'" ` // 【-1-待判断1-答案正确2-答案错误3-运行超时4-运行超内存, 5-编译错误】
}
func (table *Submit) TableName() string {
return "submit"
}

View File

@@ -0,0 +1,16 @@
package entity
import "online_code/common/types"
// TestCase 测试用例
type TestCase struct {
types.BaseDbModel
Identity string `json:"identity" gorm:"column:identity;type:varchar(255);comment:'用户唯一标识''" `
ProblemIdentity string `json:"problem_identity" gorm:"column:problem_identity;type:varchar(255);comment:'问题'" `
Input string `json:"input" gorm:"column:input;type:text;" `
Output string `json:"output" gorm:"column:output;type:text;" `
}
func (table *TestCase) TableName() string {
return "test_case"
}

19
models/entity/user.go Normal file
View File

@@ -0,0 +1,19 @@
package entity
import "online_code/common/types"
type User struct {
types.BaseDbModel
Identity string `json:"identity" gorm:"column:identity;type:varchar(36);comment:'用户唯一标识'"`
Name string `json:"name" gorm:"column:name;type:varchar(100);not null;comment:'用户名'"`
Password string `json:"password" gorm:"column:password;type:varchar(32);not null;comment:'用户密码'"`
Phone string `json:"phone" gorm:"column:phone;type:varchar(20);not null;comment:'用户手机号'"`
Mail string `json:"mail" gorm:"column:mail;type:varchar(100);not null;comment:'用户邮箱'"`
PassNum int64 `json:"pass_num" gorm:"column:pass_num;type:int(11);comment:'通过的次数'"`
SubmitNum int64 `json:"submit_num" gorm:"column:submit_num;type:int(11);comment:'提交次数'"`
IsAdmin int `json:"is_admin" gorm:"column:is_admin;type:tinyint(1);comment:'是否是管理员【0-否1-是】'"`
}
func (table *User) TableName() string {
return "user"
}