Skip to content

Commit

Permalink
chore: route changed from scores to vp
Browse files Browse the repository at this point in the history
  • Loading branch information
This-Is-Prince committed Sep 17, 2023
1 parent 20aebd1 commit 3ab0366
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestScores(t *testing.T) {
}

// Create an HTTP POST request with the JSON payload
req, err := http.NewRequest("POST", ts.URL+"/scores", bytes.NewBuffer(inputJSON))
req, err := http.NewRequest("POST", ts.URL+"/vp", bytes.NewBuffer(inputJSON))
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions routes/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func SetupRoutes(clients *utils.Clients) *gin.Engine {
r.GET("/strategies/:strategy_id", func(c *gin.Context) {
GetStrategy(c)
})
r.POST("/scores", func(c *gin.Context) {
GetScores(c, clients)
r.POST("/vp", func(c *gin.Context) {
GetVotingPower(c, clients)
})
return r
}
12 changes: 6 additions & 6 deletions routes/scores.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ import (
"github.com/gin-gonic/gin"
)

type ScoresBody struct {
type VotingPowerBody struct {
Address string `json:"address"`
Strategies []strategies.Strategy `json:"strategies"`
}

func GetScores(c *gin.Context, clients *utils.Clients) {
func GetVotingPower(c *gin.Context, clients *utils.Clients) {
// Create a slice of strategies.Strategy to store the JSON data
var body ScoresBody
var body VotingPowerBody

// Bind the JSON data from the request body to the struct
if err := c.ShouldBindJSON(&body); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("Error invalid request body %s", err.Error())})
return
}

scores := []*big.Float{}
votingPower := []*big.Float{}
for _, strategy := range body.Strategies {
scores = append(scores, strategy.Score(clients, body.Address))
votingPower = append(votingPower, strategy.Score(clients, body.Address))
}

c.JSON(http.StatusOK, scores)
c.JSON(http.StatusOK, votingPower)
}

0 comments on commit 3ab0366

Please sign in to comment.