diff --git a/api/v1/leaderboard/cron.job.operation.go b/api/v1/leaderboard/cron.job.operation.go index e159f96..7314a97 100644 --- a/api/v1/leaderboard/cron.job.operation.go +++ b/api/v1/leaderboard/cron.job.operation.go @@ -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) diff --git a/api/v1/leaderboard/leaderboard.go b/api/v1/leaderboard/leaderboard.go index c6ad0ff..8ffcb5d 100644 --- a/api/v1/leaderboard/leaderboard.go +++ b/api/v1/leaderboard/leaderboard.go @@ -27,6 +27,10 @@ func ApplyRoutes(r *gin.RouterGroup) { { h.GET("", getScoreBoard) } + u := r.Group("/updateOldUsersLeaderBoard") + { + u.GET("", UpdateLeaderBoardForAllUsers) + } } func getLeaderboard(c *gin.Context) { @@ -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) +}