Skip to content

Commit

Permalink
Merge branch 'main' into prod
Browse files Browse the repository at this point in the history
  • Loading branch information
p-shubh committed Oct 19, 2024
2 parents a4b2932 + 2b010d0 commit d8df4f4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
20 changes: 13 additions & 7 deletions api/v1/leaderboard/cron.job.operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,22 @@ func CronJobLeaderBoardUpdate(column_name string, leaderboard Leaderboard) {
return
}
}
func CronForReviewUpdate() {
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)

// fmt.Println("len voters : ", len(voters))
// fmt.Println("voters : ", voters)

if len(voters) > 0 {

for _, v := range voters {
Expand All @@ -96,15 +103,14 @@ func CronForReviewUpdate() {
} else {
if len(userIds) > 0 {
for _, id := range userIds {
go DynamicLeaderBoardUpdate(id, "reviews")
DynamicLeaderBoardUpdate(id, "reviews")
}
}
}
}

}

}

func AutoCalculateScoreBoard() {

// fmt.Println("STARTING AUTO CALCULATE SCOREBOARD AT ", time.Now())
Expand Down
20 changes: 18 additions & 2 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 @@ -84,7 +88,7 @@ func getScoreBoard(c *gin.Context) {
}

var user models.User
err := db.Model(&models.User{}).Select("user_id, name, profile_picture_url,country, wallet_address, discord, twitter, email_id").Where("user_id = ?", data.UserId).First(&user).Error
err := db.Model(&models.User{}).Select("user_id, name, profile_picture_url,country, wallet_address, discord, twitter, email_id, chain_name").Where("user_id = ?", data.UserId).First(&user).Error
if err != nil {
if err == gorm.ErrRecordNotFound {
response = append(response, UserScoreBoard)
Expand All @@ -97,7 +101,11 @@ func getScoreBoard(c *gin.Context) {

}

payload := models.User{UserId: user.UserId, Name: user.Name, WalletAddress: user.WalletAddress, ProfilePictureUrl: user.ProfilePictureUrl, Country: user.Country, Discord: user.Discord, Twitter: user.Twitter, EmailId: user.EmailId}
if user.ChainName == "" || user.ChainName == "null" {
user.ChainName = "-"
}

payload := models.User{UserId: user.UserId, Name: user.Name, WalletAddress: user.WalletAddress, ProfilePictureUrl: user.ProfilePictureUrl, Country: user.Country, Discord: user.Discord, Twitter: user.Twitter, EmailId: user.EmailId, ChainName: user.ChainName}

UserScoreBoard.UserDetails = payload

Expand Down Expand Up @@ -169,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 d8df4f4

Please sign in to comment.