Skip to content

Commit

Permalink
"Added functionality to reset reviews to 0 for all leaderboard rows a…
Browse files Browse the repository at this point in the history
…nd created a new API endpoint to trigger this update"
  • Loading branch information
p-shubh committed Oct 19, 2024
1 parent c00614f commit 2b010d0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions api/v1/leaderboard/cron.job.operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ func CronJobLeaderBoardUpdate(column_name string, leaderboard Leaderboard) {
func ReviewUpdateforOldUsers() {
db := dbconfig.GetDb()

// Update Reviews to 0 for all rows
if err := db.Model(&Leaderboard{}).Where("1 = 1").Updates(map[string]interface{}{
"reviews": 0,
"updated_at": time.Now(),
}).Error; err != nil {
fmt.Println("Failed to update reviews:", err)
} else {
fmt.Println("Successfully updated reviews to 0 for all rows.")
}

var voters []string
db.Model(&models.Review{}).Select("voter").Find(&voters)

Expand Down
12 changes: 12 additions & 0 deletions api/v1/leaderboard/leaderboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func ApplyRoutes(r *gin.RouterGroup) {
{
h.GET("", getScoreBoard)
}
u := r.Group("/updateOldUsersLeaderBoard")
{
u.GET("", UpdateLeaderBoardForAllUsers)
}
}

func getLeaderboard(c *gin.Context) {
Expand Down Expand Up @@ -173,3 +177,11 @@ func getAllUsersScoreBoard(c *gin.Context) {

httpo.NewSuccessResponseP(200, "ScoreBoard fetched successfully", response).SendD(c)
}

func UpdateLeaderBoardForAllUsers(c *gin.Context) {
var response []interface{}

ReviewUpdateforOldUsers()

httpo.NewSuccessResponseP(200, "Leaderboard updated successfully", response).SendD(c)
}

0 comments on commit 2b010d0

Please sign in to comment.