refactor🎨:修改Syspost模块功能

This commit is contained in:
wenjianzhang
2021-06-24 20:17:58 +08:00
parent 6994857f4b
commit 2025809d91
3 changed files with 24 additions and 26 deletions
+7 -9
View File
@@ -1,10 +1,8 @@
package apis
import (
"github.com/gin-gonic/gin/binding"
"net/http"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"github.com/go-admin-team/go-admin-core/sdk/api"
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
@@ -46,9 +44,9 @@ func (e SysPost) GetPage(c *gin.Context) {
list := make([]models.SysPost, 0)
var count int64
err = s.GetSysPostPage(&req, &list, &count)
err = s.GetPage(&req, &list, &count)
if err != nil {
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
e.Error(500, err, "查询失败")
return
}
@@ -78,7 +76,7 @@ func (e SysPost) Get(c *gin.Context) {
}
var object models.SysPost
err = s.GetSysPost(&req, &object)
err = s.Get(&req, &object)
if err != nil {
e.Error(500, err, "查询失败")
return
@@ -112,7 +110,7 @@ func (e SysPost) Insert(c *gin.Context) {
return
}
req.SetCreateBy(user.GetUserId(c))
err = s.InsertSysPost(&req)
err = s.Insert(&req)
if err != nil {
e.Error(500, err, "创建失败")
return
@@ -147,7 +145,7 @@ func (e SysPost) Update(c *gin.Context) {
req.SetUpdateBy(user.GetUserId(c))
err = s.UpdateSysPost(&req)
err = s.Update(&req)
if err != nil {
e.Logger.Error(err)
return
@@ -177,7 +175,7 @@ func (e SysPost) Delete(c *gin.Context) {
return
}
req.SetUpdateBy(user.GetUserId(c))
err = s.RemoveSysPost(&req)
err = s.Remove(&req)
if err != nil {
e.Logger.Error(err)
return
+5 -5
View File
@@ -43,13 +43,13 @@ func registerSysTableRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddl
tables := v1.Group("/sys/tables")
{
sysTable := tools.SysTable{}
tables.Group("").Use(authMiddleware.MiddlewareFunc()).GET("/page", sysTable.GetSysTableList)
tables.Group("").Use(authMiddleware.MiddlewareFunc()).GET("/page", sysTable.GetPage)
tablesInfo := tables.Group("/info").Use(authMiddleware.MiddlewareFunc())
{
tablesInfo.POST("", sysTable.InsertSysTable)
tablesInfo.PUT("", sysTable.UpdateSysTable)
tablesInfo.DELETE("/:tableId", sysTable.DeleteSysTables)
tablesInfo.GET("/:tableId", sysTable.GetSysTables)
tablesInfo.POST("", sysTable.Insert)
tablesInfo.PUT("", sysTable.Update)
tablesInfo.DELETE("/:tableId", sysTable.Delete)
tablesInfo.GET("/:tableId", sysTable.Get)
tablesInfo.GET("", sysTable.GetSysTablesInfo)
}
}
+12 -12
View File
@@ -15,8 +15,8 @@ type SysPost struct {
service.Service
}
// GetSysPostPage 获取SysPost列表
func (e *SysPost) GetSysPostPage(c *dto.SysPostSearch, list *[]models.SysPost, count *int64) error {
// GetPage 获取SysPost列表
func (e *SysPost) GetPage(c *dto.SysPostSearch, list *[]models.SysPost, count *int64) error {
var err error
var data models.SysPost
@@ -28,14 +28,14 @@ func (e *SysPost) GetSysPostPage(c *dto.SysPostSearch, list *[]models.SysPost, c
Find(list).Limit(-1).Offset(-1).
Count(count).Error
if err != nil {
e.Log.Errorf("db error:%s", err)
e.Log.Errorf("db error:%s \r", err)
return err
}
return nil
}
// GetSysPost 获取SysPost对象
func (e *SysPost) GetSysPost(d *dto.SysPostById, model *models.SysPost) error {
// Get 获取SysPost对象
func (e *SysPost) Get(d *dto.SysPostById, model *models.SysPost) error {
var err error
var data models.SysPost
@@ -54,8 +54,8 @@ func (e *SysPost) GetSysPost(d *dto.SysPostById, model *models.SysPost) error {
return nil
}
// InsertSysPost 创建SysPost对象
func (e *SysPost) InsertSysPost(c *dto.SysPostControl) error {
// Insert 创建SysPost对象
func (e *SysPost) Insert(c *dto.SysPostControl) error {
var err error
var data models.SysPost
c.Generate(&data)
@@ -67,8 +67,8 @@ func (e *SysPost) InsertSysPost(c *dto.SysPostControl) error {
return nil
}
// UpdateSysPost 修改SysPost对象
func (e *SysPost) UpdateSysPost(c *dto.SysPostControl) error {
// Update 修改SysPost对象
func (e *SysPost) Update(c *dto.SysPostControl) error {
var err error
var model = models.SysPost{}
e.Orm.First(&model, c.GetId())
@@ -86,8 +86,8 @@ func (e *SysPost) UpdateSysPost(c *dto.SysPostControl) error {
return nil
}
// RemoveSysPost 删除SysPost
func (e *SysPost) RemoveSysPost(d *dto.SysPostById) error {
// Remove 删除SysPost
func (e *SysPost) Remove(d *dto.SysPostById) error {
var err error
var data models.SysPost
@@ -102,4 +102,4 @@ func (e *SysPost) RemoveSysPost(d *dto.SysPostById) error {
return err
}
return nil
}
}