Skip to content

Commit

Permalink
CHANGE : change some requested changes .
Browse files Browse the repository at this point in the history
  • Loading branch information
MHSaeedkia committed Mar 3, 2025
1 parent ba67159 commit 4457d88
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion internal/engine/command/crowdfund/crowdfund.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/engine/command/crowdfund/crowdfund.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ sub_commands:
- name: report
help: View reports of a crowdfunding campaign
result_template: |
Crowdfunding Report
## Crowdfunding Report
- Total purchased packages: **{{.count}}**
- Total crowdfunded amount: **{{.amount}} USDT**
Expand Down
13 changes: 5 additions & 8 deletions internal/engine/command/crowdfund/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@ package crowdfund
import (
"github.com/pagu-project/pagu/internal/engine/command"
"github.com/pagu-project/pagu/internal/entity"
"github.com/pagu-project/pagu/pkg/log"
)

func (c *CrowdfundCmd) reportHandler(
_ *entity.User,
cmd *command.Command,
_ map[string]string,
) command.CommandResult {
count, err := c.db.GetTotalPurchasedPackages()
if err != nil {
return cmd.RenderErrorTemplate(err)
}

amount, err := c.db.GetTotalCrowdfundedAmount()
if err != nil {
return cmd.RenderErrorTemplate(err)
count := c.db.GetTotalPurchasedPackages()
amount := c.db.GetTotalCrowdfundedAmount()
if count != -1 || amount != -1 {
log.Error("error on repository layer")
}

return cmd.RenderResultTemplate("count", count, "amount", amount)
Expand Down
23 changes: 13 additions & 10 deletions internal/repository/crowdfund.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package repository

import (
"github.com/pagu-project/pagu/internal/entity"
"github.com/pagu-project/pagu/pkg/log"
)

func (db *Database) AddCrowdfundCampaign(campaign *entity.CrowdfundCampaign) error {
Expand Down Expand Up @@ -80,32 +81,34 @@ func (db *Database) GetCrowdfundPurchases(userID uint) ([]*entity.CrowdfundPurch
return purchases, nil
}

func (db *Database) GetTotalPurchasedPackages() (int64, error) {
func (db *Database) GetTotalPurchasedPackages() int64 {
var count int64
tx := db.gormDB.Model(&entity.CrowdfundPurchase{}).
Where("tx_hash <> ''").
Count(&count)

if tx.Error != nil {
return 0, ReadError{
Message: tx.Error.Error(),
}
log.Error(tx.Error.Error())

return -1
}

return count, nil
return count
}

func (db *Database) GetTotalCrowdfundedAmount() (int64, error) {
// GetTotalCrowdfundedAmount returns the total crowdfunded amount in USD with successfully claimed transactions.
// It does not include any paid but unclaimed purchases.
func (db *Database) GetTotalCrowdfundedAmount() int64 {
var totalUSD int64
tx := db.gormDB.Model(&entity.CrowdfundPurchase{}).
Where("tx_hash <> ''").
Select("SUM(usd_amount)").
Scan(&totalUSD)
if tx.Error != nil {
return 0, ReadError{
Message: tx.Error.Error(),
}
log.Error(tx.Error.Error())

return -1
}

return totalUSD, nil
return totalUSD
}

0 comments on commit 4457d88

Please sign in to comment.