fix: some load bug
This commit is contained in:
parent
36ee60b9fa
commit
489134fcb9
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @Date: 2021-03-21 19:54:57
|
||||
* @LastEditors: viletyy
|
||||
* @LastEditTime: 2021-06-11 15:22:16
|
||||
* @LastEditTime: 2021-06-14 23:19:52
|
||||
* @FilePath: /potato/internal/controller/api/v1/basic/vendor.go
|
||||
*/
|
||||
package basic
|
||||
|
@ -192,7 +192,7 @@ func (vendor Vendor) Delete(c *gin.Context) {
|
|||
}
|
||||
param := service.DeleteVendorRequest{ID: vendorId}
|
||||
svc := service.New(c.Request.Context())
|
||||
err = svc.DeleteVendor(¶m)
|
||||
dbvendor, err := svc.DeleteVendor(¶m)
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
global.GO_LOG.Sugar().Errorf("svc.DeleteVendor err: %v", err)
|
||||
|
@ -205,5 +205,6 @@ func (vendor Vendor) Delete(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
errcode.Success.Data = dbvendor
|
||||
response.ToErrorResponse(errcode.Success)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @Date: 2021-06-10 22:53:09
|
||||
* @LastEditors: viletyy
|
||||
* @LastEditTime: 2021-06-11 10:54:38
|
||||
* @LastEditTime: 2021-06-14 23:19:25
|
||||
* @FilePath: /potato/internal/dao/vendor.go
|
||||
*/
|
||||
package dao
|
||||
|
@ -56,7 +56,7 @@ func (d *Dao) UpdateVendor(id int64, name string, uuid int) (basic.Vendor, error
|
|||
return dbVendor, dbVendor.Update(d.Engine)
|
||||
}
|
||||
|
||||
func (d *Dao) DeleteVendor(id int64) error {
|
||||
func (d *Dao) DeleteVendor(id int64) (basic.Vendor, error) {
|
||||
vendor := basic.Vendor{
|
||||
Model: &model.Model{ID: id},
|
||||
}
|
||||
|
@ -64,8 +64,8 @@ func (d *Dao) DeleteVendor(id int64) error {
|
|||
dbVendor, err := vendor.Get(d.Engine)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
return vendor, err
|
||||
}
|
||||
|
||||
return dbVendor.Delete(d.Engine)
|
||||
return dbVendor, dbVendor.Delete(d.Engine)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @Date: 2021-03-22 17:50:15
|
||||
* @LastEditors: viletyy
|
||||
* @LastEditTime: 2021-06-11 10:46:51
|
||||
* @LastEditTime: 2021-06-14 22:51:58
|
||||
* @FilePath: /potato/internal/model/model.go
|
||||
*/
|
||||
package model
|
||||
|
@ -9,8 +9,8 @@ package model
|
|||
import "time"
|
||||
|
||||
type Model struct {
|
||||
ID int64 `gorm:"primary_key" json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt time.Time `gorm:"index" json:"-"`
|
||||
ID int64 `gorm:"primary_key" json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt *time.Time `gorm:"index" json:"-"`
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @Date: 2021-03-21 19:54:57
|
||||
* @LastEditors: viletyy
|
||||
* @LastEditTime: 2021-06-11 00:22:23
|
||||
* @LastEditTime: 2021-06-14 23:32:56
|
||||
* @FilePath: /potato/internal/routers/basic.go
|
||||
*/
|
||||
package routers
|
||||
|
@ -9,8 +9,9 @@ package routers
|
|||
import "github.com/viletyy/potato/internal/controller/api/v1/basic"
|
||||
|
||||
func V1InitBasicRouter() {
|
||||
v1RouterGroup := Engine.Group("../api/v1")
|
||||
|
||||
vendors := V1RouterGroup.Group("/vendors")
|
||||
vendors := v1RouterGroup.Group("/vendors")
|
||||
vendor := basic.NewVendor()
|
||||
{
|
||||
vendors.GET("", vendor.List)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @Date: 2021-03-21 19:54:57
|
||||
* @LastEditors: viletyy
|
||||
* @LastEditTime: 2021-06-13 23:39:38
|
||||
* @LastEditTime: 2021-06-14 23:32:23
|
||||
* @FilePath: /potato/internal/routers/router.go
|
||||
*/
|
||||
package routers
|
||||
|
@ -25,7 +25,6 @@ import (
|
|||
|
||||
var (
|
||||
Engine = gin.Default()
|
||||
V1RouterGroup = Engine.Group("../api/v1")
|
||||
methodLimiters = limiter.NewMethodLimiter().AddBuckets(limiter.LimiterBucketRule{
|
||||
Key: "/auth",
|
||||
FillInterval: time.Second,
|
||||
|
@ -35,8 +34,13 @@ var (
|
|||
)
|
||||
|
||||
func InitRouter() *gin.Engine {
|
||||
gin.SetMode(global.GO_CONFIG.App.RunMode) // 设置运行模式
|
||||
|
||||
gin.SetMode(global.GO_CONFIG.App.RunMode) // 设置运行模式
|
||||
Engine.Use(middleware.AppInfo()) // 设置app信息
|
||||
Engine.Use(middleware.RateLimiter(methodLimiters)) // 设置限流控制
|
||||
Engine.Use(middleware.ContextTimeout(time.Duration(global.GO_CONFIG.App.DefaultContextTimeout))) // 设置统一超时控制
|
||||
Engine.Use(middleware.Translations()) // 设置自定义验证
|
||||
Engine.Use(middleware.CORS()) // 设置跨域
|
||||
Engine.Use(middleware.Tracing())
|
||||
if global.GO_CONFIG.App.RunMode == "debug" {
|
||||
Engine.Use(gin.Logger()) // 设置log
|
||||
Engine.Use(gin.Recovery()) // 设置recovery
|
||||
|
@ -44,26 +48,18 @@ func InitRouter() *gin.Engine {
|
|||
Engine.Use(middleware.AccessLog())
|
||||
Engine.Use(middleware.Recovery())
|
||||
}
|
||||
Engine.Use(middleware.AppInfo()) // 设置app信息
|
||||
Engine.Use(middleware.RateLimiter(methodLimiters)) // 设置限流控制
|
||||
Engine.Use(middleware.ContextTimeout(time.Duration(global.GO_CONFIG.App.DefaultContextTimeout))) // 设置统一超时控制
|
||||
Engine.Use(middleware.Translations()) // 设置自定义验证
|
||||
Engine.Use(middleware.CORS()) // 设置跨域
|
||||
Engine.Use(middleware.Tracing())
|
||||
|
||||
Engine.StaticFS("/static", http.Dir(global.GO_CONFIG.App.UploadSavePath))
|
||||
|
||||
Engine.POST("/api/auth", api.GetAuth)
|
||||
Engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||
|
||||
V1InitModule()
|
||||
v1RouterGroup := Engine.Group("../api/v1")
|
||||
v1RouterGroup.Use(middleware.JWT())
|
||||
|
||||
upload := v1.NewUpload()
|
||||
v1RouterGroup.POST("/upload", upload.Create)
|
||||
V1InitBasicRouter()
|
||||
|
||||
return Engine
|
||||
}
|
||||
|
||||
func V1InitModule() {
|
||||
V1RouterGroup.Use(middleware.JWT())
|
||||
upload := v1.NewUpload()
|
||||
V1RouterGroup.POST("/upload", upload.Create)
|
||||
V1InitBasicRouter()
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @Date: 2021-06-10 17:57:48
|
||||
* @LastEditors: viletyy
|
||||
* @LastEditTime: 2021-06-11 01:17:09
|
||||
* @LastEditTime: 2021-06-14 23:19:35
|
||||
* @FilePath: /potato/internal/service/vendor.go
|
||||
*/
|
||||
package service
|
||||
|
@ -60,6 +60,6 @@ func (svc *Service) UpdateVendor(param *UpdateVendorRequest) (basic.Vendor, erro
|
|||
return svc.dao.UpdateVendor(param.ID, param.Name, param.Uuid)
|
||||
}
|
||||
|
||||
func (svc *Service) DeleteVendor(param *DeleteVendorRequest) error {
|
||||
func (svc *Service) DeleteVendor(param *DeleteVendorRequest) (basic.Vendor, error) {
|
||||
return svc.dao.DeleteVendor(param.ID)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue