feat: update admin
This commit is contained in:
@@ -257,3 +257,21 @@ func (m *mediasModel) GetRelations(ctx context.Context, hash string) ([]*model.M
|
||||
return &media
|
||||
}), nil
|
||||
}
|
||||
|
||||
// Count
|
||||
func (m *mediasModel) Count(ctx context.Context) (int64, error) {
|
||||
tbl := table.Medias
|
||||
stmt := tbl.SELECT(COUNT(tbl.ID).AS("count"))
|
||||
m.log.Infof("sql: %s", stmt.DebugSql())
|
||||
|
||||
var count struct {
|
||||
Count int64
|
||||
}
|
||||
|
||||
if err := stmt.QueryContext(ctx, db, &count); err != nil {
|
||||
m.log.Errorf("error counting media items: %v", err)
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return count.Count, nil
|
||||
}
|
||||
|
||||
@@ -203,3 +203,43 @@ func (m *ordersModel) SetStatus(ctx context.Context, orderNo string, status fiel
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Count
|
||||
func (m *ordersModel) Count(ctx context.Context, cond BoolExpression) (int64, error) {
|
||||
tbl := table.Orders
|
||||
stmt := SELECT(COUNT(tbl.ID).AS("cnt")).FROM(tbl).WHERE(cond)
|
||||
m.log.Infof("sql: %s", stmt.DebugSql())
|
||||
|
||||
var cnt struct {
|
||||
Cnt int64
|
||||
}
|
||||
|
||||
err := stmt.QueryContext(ctx, db, &cnt)
|
||||
if err != nil {
|
||||
m.log.Errorf("error counting orders: %v", err)
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return cnt.Cnt, nil
|
||||
}
|
||||
|
||||
// SumAmount
|
||||
func (m *ordersModel) SumAmount(ctx context.Context) (int64, error) {
|
||||
tbl := table.Orders
|
||||
stmt := SELECT(SUM(tbl.Price).AS("cnt")).FROM(tbl).WHERE(
|
||||
tbl.Status.EQ(Int(int64(fields.OrderStatusPaid))),
|
||||
)
|
||||
m.log.Infof("sql: %s", stmt.DebugSql())
|
||||
|
||||
var cnt struct {
|
||||
Cnt int64
|
||||
}
|
||||
|
||||
err := stmt.QueryContext(ctx, db, &cnt)
|
||||
if err != nil {
|
||||
m.log.Errorf("error summing order amount: %v", err)
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return cnt.Cnt, nil
|
||||
}
|
||||
|
||||
@@ -395,3 +395,21 @@ func (m *postsModel) GetMediaByIds(ctx context.Context, ids []int64) ([]model.Me
|
||||
|
||||
return medias, nil
|
||||
}
|
||||
|
||||
// Count
|
||||
func (m *postsModel) Count(ctx context.Context, cond BoolExpression) (int64, error) {
|
||||
tbl := table.Posts
|
||||
stmt := tbl.
|
||||
SELECT(COUNT(tbl.ID).AS("count")).
|
||||
WHERE(cond)
|
||||
|
||||
var count struct {
|
||||
Count int64
|
||||
}
|
||||
if err := stmt.QueryContext(ctx, db, &count); err != nil {
|
||||
m.log.Errorf("error counting posts: %v", err)
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return count.Count, nil
|
||||
}
|
||||
|
||||
@@ -310,3 +310,24 @@ func (m *usersModel) HasBought(ctx context.Context, userID, postID int64) (bool,
|
||||
|
||||
return userPost.ID > 0, nil
|
||||
}
|
||||
|
||||
// Count
|
||||
func (m *usersModel) Count(ctx context.Context, cond BoolExpression) (int64, error) {
|
||||
tbl := table.Users
|
||||
stmt := tbl.
|
||||
SELECT(COUNT(tbl.ID).AS("cnt")).
|
||||
WHERE(cond)
|
||||
|
||||
m.log.Infof("sql: %s", stmt.DebugSql())
|
||||
|
||||
var cnt struct {
|
||||
Cnt int64
|
||||
}
|
||||
|
||||
if err := stmt.QueryContext(ctx, db, &cnt); err != nil {
|
||||
m.log.Errorf("error counting users: %v", err)
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return cnt.Cnt, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user