Skip to content

Commit

Permalink
feat: Add Round winner check
Browse files Browse the repository at this point in the history
  • Loading branch information
sirateek committed Apr 7, 2024
1 parent b2a0f25 commit 06883b9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (

type Handler struct {
cfg config.Config

round map[string]bool
}

func ProvideHandler(cfg config.Config) Handler {
Expand All @@ -35,6 +37,9 @@ func (h *Handler) SubmitSuccessTask(c *gin.Context) {
result := c.GetHeader("X-NODE-ID")
logrus.Infof("%s found the correct answer! at %s", result, time.Now().String())

roundID := c.GetHeader("X-ROUND-ID")
h.round[roundID] = true

c.JSON(http.StatusOK, gin.H{
"message": "Correct!",
})
Expand All @@ -58,3 +63,15 @@ func (h *Handler) GetTheHashBase64(c *gin.Context) {
"message": h.generateBase64Hash(data),
})
}

func (h *Handler) CheckRoundWinner(c *gin.Context) {
roundID := c.GetHeader("X-ROUND-ID")

ok := h.round[roundID]
if ok {
c.JSON(http.StatusBadRequest, gin.H{"err": "Already got the winner"})
return
}

c.Status(http.StatusOK)
}
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func main() {

srv.Engine().GET("/submit-answer/:answer", han.SubmitSuccessTask)
srv.Engine().GET("/:data", han.GetTheHashBase64)
srv.Engine().GET("/round-has-winner", han.CheckRoundWinner)

srv.Serve()

Expand Down

0 comments on commit 06883b9

Please sign in to comment.