package code import ( "github.com/gin-gonic/gin" "product/backend/module/base" "product/backend/module/directive" "product/backend/moo/db" "product/backend/moo/log" ) const tableName = moduleName type Body struct { WorkID uint `gorm:"" json:"workId"` Lang string `gorm:"type:enum('scratch', 'python', 'cpp', 'go')" json:"lang" binding:"oneof=scratch python cpp go"` InitCode string `gorm:"type:varchar(4096)" json:"initCode"` FinalCode string `gorm:"type:varchar(9192)" json:"finalCode"` Order int `gorm:"" json:"order"` State bool `gorm:"" json:"state"` } type Model struct { Body base.Model Directives []directive.Model `gorm:"many2many:code_directive;joinForeignKey:code_id;joinReferences:directive_id" json:"directives"` } type PostModel struct { Model DirectiveID []uint `gorm:"-" json:"directiveId"` } type PutModel struct { Model ID uint `gorm:"primarykey" json:"id" binding:"required"` DirectiveID []uint `gorm:"-" json:"directiveId"` } func (Model) TableName() string { return tableName } type GetReq struct { base.GetReq } func init() { // Migrate if gin.Mode() == gin.DebugMode { if err := db.DB.AutoMigrate(&Model{}); err != nil { log.Warn(err) } } }