-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new fields to Leaderboard, ScoreBoard, and UserScoreBoard struc…
…ts; updated corresponding models and database migrations; added new API handlers for BetaGraphqlQueryForLeaderboard and ErebrusQueryForLeaderboard; updated existing API handlers to include
- Loading branch information
Showing
11 changed files
with
499 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package leaderboard | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/NetSepio/gateway/config/dbconfig" | ||
"github.com/NetSepio/gateway/config/models" | ||
"github.com/NetSepio/gateway/graphql" | ||
"github.com/google/uuid" | ||
"gorm.io/gorm" | ||
) | ||
|
||
func BetaGraphqlQueryForLeaderboard() ([]string, error) { | ||
// Database connection setup (replace with your actual connection details) | ||
db := dbconfig.GetDb() | ||
|
||
var userIds []string | ||
|
||
// Call Beta Test Query | ||
betaTestResponse, err := graphql.BetaTestQuery() | ||
if err != nil { | ||
log.Printf("Error performing Beta Test query: %v", err) | ||
return nil, err // Return the error if the query fails | ||
} | ||
|
||
fmt.Println("Beta Test Query Results:") | ||
for _, token := range betaTestResponse.Data.CurrentTokenDatasV2 { | ||
fmt.Printf("Token Name: %s, Description: %s\n", token.TokenName, token.Description) | ||
for _, ownership := range token.CurrentTokenOwnerships { | ||
fmt.Printf("Owner Address: %s, Last Transaction: %s\n", ownership.OwnerAddress, ownership.LastTransactionTimestamp) | ||
|
||
// Check if the user exists or create a new one if not | ||
var user models.User | ||
result := db.Where("wallet_address = ?", ownership.OwnerAddress).First(&user) | ||
if result.Error != nil { | ||
// If the user does not exist, create a new one | ||
if result.Error == gorm.ErrRecordNotFound { | ||
// Generate a new UUID for the user | ||
user = models.User{ | ||
UserId: uuid.New().String(), // UUID generation | ||
WalletAddress: &ownership.OwnerAddress, | ||
} | ||
if err := db.Create(&user).Error; err != nil { | ||
log.Printf("Error creating new user: %v", err) | ||
return userIds, err // Return if error occurs while creating user | ||
} else { | ||
userIds = append(userIds, user.UserId) | ||
// leaderboard.DynamicLeaderBoardUpdate(user.UserId, "reviews") | ||
|
||
} | ||
fmt.Printf("Created new user with UserID: %s\n", user.UserId) | ||
} else { | ||
// If another error occurred, log and return it | ||
log.Printf("Error querying user: %v", result.Error) | ||
return nil, result.Error | ||
} | ||
} else { | ||
// leaderboard.DynamicLeaderBoardUpdate(user.UserId, "reviews") | ||
userIds = append(userIds, user.UserId) | ||
} | ||
} | ||
} | ||
return userIds, nil | ||
} | ||
func ErebrusQueryForLeaderboard() ([]string, error) { | ||
// Database connection setup (replace with your actual connection details) | ||
db := dbconfig.GetDb() | ||
|
||
var userIds []string | ||
|
||
// Call Beta Test Query | ||
betaTestResponse, err := graphql.ErebrusQuery() | ||
if err != nil { | ||
log.Printf("Error performing Beta Test query: %v", err) | ||
return nil, err // Return the error if the query fails | ||
} | ||
|
||
fmt.Println("Beta Test Query Results:") | ||
for _, token := range betaTestResponse.Data.CurrentTokenDatasV2 { | ||
fmt.Printf("Token Name: %s, Description: %s\n", token.TokenName, token.Description) | ||
for _, ownership := range token.CurrentTokenOwnerships { | ||
fmt.Printf("Owner Address: %s, Last Transaction: %s\n", ownership.OwnerAddress, ownership.LastTransactionTimestamp) | ||
|
||
// Check if the user exists or create a new one if not | ||
var user models.User | ||
result := db.Where("wallet_address = ?", ownership.OwnerAddress).First(&user) | ||
if result.Error != nil { | ||
// If the user does not exist, create a new one | ||
if result.Error == gorm.ErrRecordNotFound { | ||
// Generate a new UUID for the user | ||
user = models.User{ | ||
UserId: uuid.New().String(), // UUID generation | ||
WalletAddress: &ownership.OwnerAddress, | ||
} | ||
if err := db.Create(&user).Error; err != nil { | ||
log.Printf("Error creating new user: %v", err) | ||
return userIds, err // Return if error occurs while creating user | ||
} else { | ||
userIds = append(userIds, user.UserId) | ||
// leaderboard.DynamicLeaderBoardUpdate(user.UserId, "reviews") | ||
|
||
} | ||
fmt.Printf("Created new user with UserID: %s\n", user.UserId) | ||
} else { | ||
// If another error occurred, log and return it | ||
log.Printf("Error querying user: %v", result.Error) | ||
return nil, result.Error | ||
} | ||
} else { | ||
// leaderboard.DynamicLeaderBoardUpdate(user.UserId, "reviews") | ||
userIds = append(userIds, user.UserId) | ||
} | ||
} | ||
} | ||
return userIds, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.