Skip to content

Commit

Permalink
add overview
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouop0 committed Jul 3, 2024
1 parent 22b6274 commit d20d8fb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/sql/postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ CREATE TABLE IF NOT EXISTS game_credit
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
game_contract varchar(42) NOT NULL,
address varchar(64) NOT NULL,
credit numeric NOT NULL
credit bigint NOT NULL
);

12 changes: 12 additions & 0 deletions internal/api/dispute_game_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,15 @@ func (h DisputeGameHandler) GetCreditDetails(c *gin.Context) {
"records": games,
})
}

func (h DisputeGameHandler) GetOverview(c *gin.Context) {
var gameCount int64
var totalCredit int64
h.DB.Model(&schema.DisputeGame{}).Count(&gameCount)
h.DB.Model(&schema.GameCredit{}).Select("IFNULL(sum(credit), 0) as totalCredit").Find(&totalCredit)
c.JSON(http.StatusOK, gin.H{
"disputeGameProxy": "0x05F9613aDB30026FFd634f38e5C4dFd30a197Fa1",
"totalGames": gameCount,
"totalCredit": totalCredit,
})
}
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func main() {
router.GET("/disputegames/:address/claimdatas", disputeGameHandler.GetClaimData)
router.GET("/disputegames/credit/rank", disputeGameHandler.GetCreditRank)
router.GET("/disputegames/:address/credit", disputeGameHandler.GetCreditDetails)
router.GET("/disputegames/overview", disputeGameHandler.GetOverview)

err := router.Run()
if err != nil {
Expand Down

0 comments on commit d20d8fb

Please sign in to comment.