Skip to content

Commit

Permalink
fix get payment with invoice arg
Browse files Browse the repository at this point in the history
  • Loading branch information
bxy4543 committed Sep 14, 2024
1 parent 7ef586d commit a512091
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
8 changes: 4 additions & 4 deletions controllers/pkg/database/cockroach/accountv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ func (c *Cockroach) GetPaymentWithID(paymentID string) (*types.Payment, error) {
return &payment, nil
}

func (c *Cockroach) GetPaymentWithLimit(ops *types.UserQueryOpts, req types.LimitReq, invoiced bool) ([]types.Payment, types.LimitResp, error) {
func (c *Cockroach) GetPaymentWithLimit(ops *types.UserQueryOpts, req types.LimitReq, invoiced *bool) ([]types.Payment, types.LimitResp, error) {
var payment []types.Payment
var total int64
var limitResp types.LimitResp
Expand All @@ -662,10 +662,10 @@ func (c *Cockroach) GetPaymentWithLimit(ops *types.UserQueryOpts, req types.Limi
}

queryPayment := types.Payment{PaymentRaw: types.PaymentRaw{UserUID: userUID}}
if invoiced {
queryPayment.InvoicedAt = true
}
query := c.DB.Model(&types.Payment{}).Where(queryPayment)
if invoiced != nil {
query = query.Where("invoiced_at = ?", *invoiced)
}
if !req.StartTime.IsZero() {
query = query.Where("created_at >= ?", req.StartTime)
}
Expand Down
14 changes: 12 additions & 2 deletions service/account/dao/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -1055,11 +1055,21 @@ func (m *MongoDB) getAppStoreList(req helper.GetCostAppListReq, skip, pageSize i
return
}

func (m *MongoDB) Disconnect(ctx context.Context) error {
func (m *Account) Disconnect(ctx context.Context) error {
if m == nil {
return nil
}
return m.Client.Disconnect(ctx)
if m.MongoDB != nil && m.MongoDB.Client != nil {
if err := m.MongoDB.Client.Disconnect(ctx); err != nil {
return fmt.Errorf("failed to close mongodb client: %v", err)
}
}
if m.Cockroach != nil && m.Cockroach.ck != nil {
if err := m.ck.Close(); err != nil {
return fmt.Errorf("failed to close cockroach client: %v", err)
}
}
return nil
}

func (m *MongoDB) GetConsumptionAmount(req helper.ConsumptionRecordReq) (int64, error) {
Expand Down
3 changes: 1 addition & 2 deletions service/account/helper/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ type GetPaymentReq struct {
// @Summary Invoiced
// @Description Invoiced
// @JSONSchema
Invoiced bool `json:"invoiced,omitempty" bson:"invoiced" example:"true"`
Invoiced *bool `json:"invoiced,omitempty" bson:"invoiced" example:"true"`

// @Summary Authentication information
// @Description Authentication information
Expand Down Expand Up @@ -388,7 +388,6 @@ func ParseAppCostsReq(c *gin.Context) (*AppCostsReq, error) {
return nil, fmt.Errorf("bind json error: %v", err)
}
setDefaultTimeRange(&userCosts.TimeRange)
userCosts.Owner = strings.TrimPrefix(userCosts.Owner, "ns-")
return userCosts, nil
}

Expand Down
6 changes: 6 additions & 0 deletions service/account/router/router.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package router

import (
"context"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -29,6 +30,11 @@ func RegisterPayRouter() {
if err := dao.InitDB(); err != nil {
log.Fatalf("Error initializing database: %v", err)
}
defer func() {
if err := dao.DBClient.Disconnect(context.Background()); err != nil {
log.Fatalf("Error disconnecting database: %v", err)
}
}()
// /account/v1alpha1/{/namespaces | /properties | {/costs | /costs/recharge | /costs/consumption | /costs/properties}}
router.Group(helper.GROUP).
POST(helper.GetHistoryNamespaces, api.GetBillingHistoryNamespaceList).
Expand Down

0 comments on commit a512091

Please sign in to comment.