Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bxy4543 committed Sep 10, 2024
1 parent 5ad4301 commit 387d556
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions service/account/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,12 @@ func GetAllRegionConsumptionAmount(c *gin.Context) {
}
svc := region.AccountSvc
url := fmt.Sprintf("https://%s%s%s", svc, helper.GROUP, helper.GetConsumptionAmount)
body, err := json.Marshal(req)
body, err := json.Marshal(&helper.ConsumptionRecordReq{
TimeRange: req.TimeRange,
AppType: req.AppType,
Namespace: req.Namespace,
AppName: req.AppName,
})
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("failed to marshal request: %v", err)})
return
Expand Down Expand Up @@ -186,6 +191,10 @@ func GetAllRegionConsumptionAmount(c *gin.Context) {
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("failed to get response, status code: %d", resp.StatusCode)})
return
}
body, err = io.ReadAll(resp.Body)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("failed to read response body: %v", err)})
Expand All @@ -197,13 +206,13 @@ func GetAllRegionConsumptionAmount(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("failed to unmarshal response body: %v", err)})
return
}
amount, ok := respData["amount"].(int64)
amountResp, ok := respData["amount"].(float64)
if !ok {
c.JSON(http.StatusInternalServerError, gin.H{"error": "amount is not an integer"})
c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("amount is not an integer, is %T", respData["amount"])})
return
}
regionAmount[region.Domain] = amount
allAmount += amount
regionAmount[region.Domain] = int64(amountResp)
allAmount += int64(amountResp)
}
c.JSON(http.StatusOK, gin.H{
"regionAmount": regionAmount,
Expand Down

0 comments on commit 387d556

Please sign in to comment.