Some checks failed
build quyun / Build (push) Failing after 2m1s
- Added definitions for admin authentication, media, posts, orders, and user management. - Implemented new API paths for admin functionalities including authentication, media management, order processing, and user statistics. - Updated existing endpoints to improve clarity and structure in the Swagger documentation. - Introduced new response schemas for various operations to standardize API responses.
73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
package admin
|
|
|
|
import (
|
|
"quyun/v2/app/services"
|
|
"quyun/v2/database/models"
|
|
"quyun/v2/pkg/fields"
|
|
|
|
"github.com/gofiber/fiber/v3"
|
|
)
|
|
|
|
// @provider
|
|
type statistics struct{}
|
|
|
|
type StatisticsResponse struct {
|
|
PostDraft int64 `json:"post_draft"`
|
|
PostPublished int64 `json:"post_published"`
|
|
Media int64 `json:"media"`
|
|
Order int64 `json:"order"`
|
|
User int64 `json:"user"`
|
|
Amount int64 `json:"amount"`
|
|
}
|
|
|
|
// dashboard statistics
|
|
//
|
|
// @Summary 仪表盘统计
|
|
// @Tags Admin Statistics
|
|
// @Produce json
|
|
// @Success 200 {object} StatisticsResponse "成功"
|
|
// @Router /admin/statistics [get]
|
|
func (s *statistics) statistics(ctx fiber.Ctx) (*StatisticsResponse, error) {
|
|
statistics := &StatisticsResponse{}
|
|
|
|
var err error
|
|
|
|
statistics.PostDraft, err = services.Posts.Count(
|
|
ctx,
|
|
models.PostQuery.Status.Eq(fields.PostStatusDraft),
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
statistics.PostPublished, err = services.Posts.Count(
|
|
ctx,
|
|
models.PostQuery.Status.Eq(fields.PostStatusPublished),
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
statistics.Media, err = services.Medias.Count(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// model.ExprCond(table.Orders.Status.EQ(Int(int64(fields.OrderStatusCompleted)))))
|
|
statistics.Order, err = services.Orders.Count(ctx, models.OrderQuery.Status.Eq(fields.OrderStatusCompleted))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
statistics.User, err = services.Users.Count(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
statistics.Amount, err = services.Orders.SumAmount(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return statistics, nil
|
|
}
|