部分表改用软删除

master
zcy 2021-03-22 12:10:37 +08:00
parent 7684079f0e
commit 2ed82019f6
3 changed files with 24 additions and 18 deletions

View File

@ -192,7 +192,7 @@ func (this *PlanController) GetUndo(c *gin.Context) {
}()
undos := []model.Undo{}
e := db.GetOrm().Model(&model.Undo{}).Find(&undos).Error
if nil != e{
if nil != e {
log.Print(e.Error())
return
}
@ -236,7 +236,7 @@ func (this *PlanController) DeleteUndo(c *gin.Context) {
sid := c.Param("id")
id := db.Atoi(sid)
e := db.GetOrm().Model(&model.Undo{}).Delete(&model.Undo{ID: int32(id)}).Error
if nil != e{
if nil != e {
log.Print(e.Error())
return
}

20
main.go
View File

@ -24,10 +24,10 @@ import (
// @BasePath /api/v1
var (
userController = controller.UserController{}
mailContoller = controller.MailController{}
fileController = controller.FileController{}
planController = controller.PlanController{}
userController = controller.UserController{}
mailContoller = controller.MailController{}
fileController = controller.FileController{}
planController = controller.PlanController{}
openapiController = controller.OpenApiController{}
)
@ -182,17 +182,17 @@ func main() {
api.POST("/plan_days", planController.PlanDay) // 获取本月有计划天数
api.GET("/plan_types", planController.Types)
api.PUT("/undo",planController.CreateUndo)
api.POST("/undo",planController.UpdateUndo)
api.GET("/undo",planController.GetUndo)
api.DELETE("/undo/:id",planController.DeleteUndo)
api.PUT("/undo", planController.CreateUndo)
api.POST("/undo", planController.UpdateUndo)
api.GET("/undo", planController.GetUndo)
api.DELETE("/undo/:id", planController.DeleteUndo)
}
openapi := r.Group("openapi")
{
openapi.POST("/diff")
openapi.POST("/ddl2orm",openapiController.DDL2ORM)
openapi.POST("/ddl2markdown",openapiController.DDL2Markdown)
openapi.POST("/ddl2orm", openapiController.DDL2ORM)
openapi.POST("/ddl2markdown", openapiController.DDL2Markdown)
}
e := r.Run(":" + strconv.Itoa(config.GetPort()))

View File

@ -7,6 +7,9 @@ import (
"crypto/md5"
"fmt"
"log"
"time"
"github.com/jinzhu/gorm"
)
type Plan struct {
@ -19,12 +22,15 @@ type Plan struct {
}
type Undo struct {
ID int32 `json:"id" gorm:"column:id" sql:"id"`
Content string `json:"content" gorm:"column:content" sql:"content"`
SpendTime int32 `json:"spend_time" gorm:"column:spend_time" sql:"spend_time"`
Parent int32 `json:"parent" gorm:"column:parent" sql:"parent"`
Level int32 `json:"level" gorm:"column:level" sql:"level"`
Type int32 `json:"type" gorm:"column:type" sql:"type"`
model gorm.Model
ID int32 `json:"id" gorm:"column:id" sql:"id"`
Content string `json:"content" gorm:"column:content" sql:"content"`
SpendTime int32 `json:"spend_time" gorm:"column:spend_time" sql:"spend_time"`
Parent int32 `json:"parent" gorm:"column:parent" sql:"parent"`
Level int32 `json:"level" gorm:"column:level" sql:"level"`
Type int32 `json:"type" gorm:"column:type" sql:"type"`
Done int `json:"done" gorm:"done" sql:"done"`
DeletedAt *time.Time `json:"deleted_at"`
}
type PlanType struct {