feat: list shopee sync task history
This commit is contained in:
@@ -381,3 +381,23 @@ func (e ShopeeProduct) List(c *gin.Context) {
|
||||
}
|
||||
e.OK(rows, "查询成功")
|
||||
}
|
||||
|
||||
// ListSyncTasks returns recent synchronization history for the Admin console.
|
||||
func (e ShopeeProduct) ListSyncTasks(c *gin.Context) {
|
||||
e.MakeContext(c)
|
||||
rows := make([]models.ShopeeSyncTask, 0)
|
||||
db := primaryDB()
|
||||
if db == nil {
|
||||
e.Error(500, fmt.Errorf("database is not initialized"), "数据库未初始化")
|
||||
return
|
||||
}
|
||||
q := db.Order("id desc").Limit(100)
|
||||
if id := strings.TrimSpace(c.Query("shopeeId")); id != "" {
|
||||
q = q.Where("shopee_id = ?", id)
|
||||
}
|
||||
if err := q.Find(&rows).Error; err != nil {
|
||||
e.Error(500, err, "读取同步任务失败")
|
||||
return
|
||||
}
|
||||
e.OK(rows, "查询成功")
|
||||
}
|
||||
|
||||
@@ -21,5 +21,6 @@ func registerShopeeProductAdminRouter(v1 *gin.RouterGroup, auth *jwt.GinJWTMiddl
|
||||
a := apis.ShopeeProduct{}
|
||||
r := v1.Group("/shopee/products").Use(auth.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
r.GET("", a.List)
|
||||
r.GET("/sync-tasks", a.ListSyncTasks)
|
||||
r.GET("/sync/:shopeeId", a.GetByShopeeIDAdmin)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user