68 lines
2.1 KiB
Go
68 lines
2.1 KiB
Go
package income
|
|
|
|
import (
|
|
"context"
|
|
|
|
db "management/internal/db/sqlc"
|
|
"management/internal/pkg/redis"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
type IncomeBiz interface {
|
|
Create(ctx context.Context, arg *db.CreateIncomeParams) (*db.Income, error)
|
|
Update(ctx context.Context, arg *db.UpdateIncomeParams) (*db.Income, error)
|
|
List(ctx context.Context, arg *db.ListIncomeConditionParam) ([]*db.IncomeView, int64, error)
|
|
Get(ctx context.Context, id int64) (*db.Income, error)
|
|
Sum(ctx context.Context) (pgtype.Numeric, error)
|
|
SumByProjectID(ctx context.Context, id int64) (pgtype.Numeric, error)
|
|
Statistics(ctx context.Context) ([]*db.StatisticsIncomeRow, error)
|
|
StatisticsByProjectID(ctx context.Context, projectID int64) ([]*db.StatisticsIncomeByProjectIDRow, error)
|
|
}
|
|
|
|
type incomeBiz struct {
|
|
store db.Store
|
|
redis redis.IRedis
|
|
}
|
|
|
|
var _ IncomeBiz = (*incomeBiz)(nil)
|
|
|
|
func New(store db.Store, redis redis.IRedis) *incomeBiz {
|
|
return &incomeBiz{
|
|
store: store,
|
|
redis: redis,
|
|
}
|
|
}
|
|
|
|
func (b *incomeBiz) Create(ctx context.Context, arg *db.CreateIncomeParams) (*db.Income, error) {
|
|
return b.store.CreateIncome(ctx, arg)
|
|
}
|
|
|
|
func (b *incomeBiz) Update(ctx context.Context, arg *db.UpdateIncomeParams) (*db.Income, error) {
|
|
return b.store.UpdateIncome(ctx, arg)
|
|
}
|
|
|
|
func (b *incomeBiz) List(ctx context.Context, arg *db.ListIncomeConditionParam) ([]*db.IncomeView, int64, error) {
|
|
return b.store.ListIncomeCondition(ctx, arg)
|
|
}
|
|
|
|
func (b *incomeBiz) Get(ctx context.Context, id int64) (*db.Income, error) {
|
|
return b.store.GetIncome(ctx, id)
|
|
}
|
|
|
|
func (b *incomeBiz) Sum(ctx context.Context) (pgtype.Numeric, error) {
|
|
return b.store.SumIncome(ctx)
|
|
}
|
|
|
|
func (b *incomeBiz) SumByProjectID(ctx context.Context, id int64) (pgtype.Numeric, error) {
|
|
return b.store.SumIncomeByProjectID(ctx, id)
|
|
}
|
|
|
|
func (b *incomeBiz) Statistics(ctx context.Context) ([]*db.StatisticsIncomeRow, error) {
|
|
return b.store.StatisticsIncome(ctx)
|
|
}
|
|
|
|
func (b *incomeBiz) StatisticsByProjectID(ctx context.Context, projectID int64) ([]*db.StatisticsIncomeByProjectIDRow, error) {
|
|
return b.store.StatisticsIncomeByProjectID(ctx, projectID)
|
|
}
|