From 4bc8182ae7e56fd6a1c67d1a6e41d14cf5ee07a5 Mon Sep 17 00:00:00 2001 From: Shubham Prajapati Date: Wed, 23 Oct 2024 01:08:20 +0530 Subject: [PATCH] Added new fields to Leaderboard, ScoreBoard, and UserScoreBoard structs; updated corresponding models and database migrations; added new API handlers for BetaGraphqlQueryForLeaderboard and ErebrusQueryForLeaderboard; updated existing API handlers to include --- api/v1/leaderboard/cron.job.operation.go | 48 +++---- .../graphql.leaderboard.opearationss.go | 117 ++++++++++++++++++ .../leaderboard/leaderboard.db.operations.go | 84 ++++++++----- api/v1/leaderboard/leaderboard.go | 108 ++++++++++++---- api/v1/leaderboard/type.go | 48 +++---- config/models/models.go | 20 +-- graphql/betaTestingQuery.go | 28 +++++ graphql/common.function.go | 63 ++++++++++ graphql/erebrusquery.go | 22 ++++ models/Migrate/migrate_models.go | 48 +++---- models/leaderboard.go | 76 ++++++------ 11 files changed, 499 insertions(+), 163 deletions(-) create mode 100644 api/v1/leaderboard/graphql.leaderboard.opearationss.go create mode 100644 graphql/betaTestingQuery.go create mode 100644 graphql/common.function.go create mode 100644 graphql/erebrusquery.go diff --git a/api/v1/leaderboard/cron.job.operation.go b/api/v1/leaderboard/cron.job.operation.go index 665c58d..19f9c57 100644 --- a/api/v1/leaderboard/cron.job.operation.go +++ b/api/v1/leaderboard/cron.job.operation.go @@ -33,17 +33,19 @@ func CronJobLeaderBoardUpdate(column_name string, leaderboard Leaderboard) { if err == gorm.ErrRecordNotFound { CreateScoreBoard(ScoreBoard{ - ID: uuid.New().String(), - Reviews: leaderboard.Reviews, - Domain: leaderboard.Domain, - UserId: leaderboard.UserId, - Nodes: leaderboard.Nodes, - DWifi: leaderboard.DWifi, - Discord: leaderboard.Discord, - Twitter: leaderboard.Twitter, - Telegram: leaderboard.Telegram, - CreatedAt: leaderboard.CreatedAt, - UpdatedAt: leaderboard.UpdatedAt, + ID: uuid.New().String(), + Reviews: leaderboard.Reviews, + Domain: leaderboard.Domain, + UserId: leaderboard.UserId, + Nodes: leaderboard.Nodes, + DWifi: leaderboard.DWifi, + Discord: leaderboard.Discord, + Twitter: leaderboard.Twitter, + Telegram: leaderboard.Telegram, + Subscription: leaderboard.Subscription, + BetaTester: leaderboard.BetaTester, + CreatedAt: leaderboard.CreatedAt, + UpdatedAt: leaderboard.UpdatedAt, }) log.Println("New record inserted and " + column_name + " count initialized successfully!") return @@ -52,17 +54,19 @@ func CronJobLeaderBoardUpdate(column_name string, leaderboard Leaderboard) { } else { err = UpdateScoreBoard(leaderboard.ID, ScoreBoard{ - ID: uuid.New().String(), - Reviews: leaderboard.Reviews, - Domain: leaderboard.Domain, - UserId: leaderboard.UserId, - Nodes: leaderboard.Nodes, - DWifi: leaderboard.DWifi, - Discord: leaderboard.Discord, - Twitter: leaderboard.Twitter, - Telegram: leaderboard.Telegram, - CreatedAt: leaderboard.CreatedAt, - UpdatedAt: leaderboard.UpdatedAt, + ID: uuid.New().String(), + Reviews: leaderboard.Reviews, + Domain: leaderboard.Domain, + UserId: leaderboard.UserId, + Nodes: leaderboard.Nodes, + DWifi: leaderboard.DWifi, + Discord: leaderboard.Discord, + Twitter: leaderboard.Twitter, + Telegram: leaderboard.Telegram, + Subscription: leaderboard.Subscription, + BetaTester: leaderboard.BetaTester, + CreatedAt: leaderboard.CreatedAt, + UpdatedAt: leaderboard.UpdatedAt, }, column_name, data.XP) if err != nil { log.Printf("failed to update the Reviews count: %v", err) diff --git a/api/v1/leaderboard/graphql.leaderboard.opearationss.go b/api/v1/leaderboard/graphql.leaderboard.opearationss.go new file mode 100644 index 0000000..2c1d1e7 --- /dev/null +++ b/api/v1/leaderboard/graphql.leaderboard.opearationss.go @@ -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 +} diff --git a/api/v1/leaderboard/leaderboard.db.operations.go b/api/v1/leaderboard/leaderboard.db.operations.go index d495c9b..f0212ea 100644 --- a/api/v1/leaderboard/leaderboard.db.operations.go +++ b/api/v1/leaderboard/leaderboard.db.operations.go @@ -41,6 +41,10 @@ func DynamicLeaderBoardUpdate(user_id, column_name string) { newLeaderBoard.Twitter = 1 case "telegram": newLeaderBoard.Telegram = 1 + case "subscription": + newLeaderBoard.Subscription = true + case "beta_tester": + newLeaderBoard.BetaTester = 1 default: log.Printf("Invalid column name") return @@ -53,17 +57,19 @@ func DynamicLeaderBoardUpdate(user_id, column_name string) { } else { CreateScoreBoard(ScoreBoard{ - ID: uuid.New().String(), - Reviews: leaderboard.Reviews, - Domain: leaderboard.Domain, - UserId: leaderboard.UserId, - Nodes: leaderboard.Nodes, - DWifi: leaderboard.DWifi, - Discord: leaderboard.Discord, - Twitter: leaderboard.Twitter, - Telegram: leaderboard.Telegram, - CreatedAt: leaderboard.CreatedAt, - UpdatedAt: leaderboard.UpdatedAt, + ID: uuid.New().String(), + Reviews: leaderboard.Reviews, + Domain: leaderboard.Domain, + UserId: leaderboard.UserId, + Nodes: leaderboard.Nodes, + DWifi: leaderboard.DWifi, + Discord: leaderboard.Discord, + Twitter: leaderboard.Twitter, + Telegram: leaderboard.Telegram, + Subscription: leaderboard.Subscription, + BetaTester: leaderboard.BetaTester, + CreatedAt: leaderboard.CreatedAt, + UpdatedAt: leaderboard.UpdatedAt, }) } log.Println("New record inserted and reviews count initialized successfully!") @@ -72,28 +78,44 @@ func DynamicLeaderBoardUpdate(user_id, column_name string) { log.Printf("failed to query the LeaderBoard: %v", err) } - // If user_id exists, increment the Reviews column by 1 - err = db.Debug().Model(&leaderboard).Update(column_name, gorm.Expr(column_name+" + ?", 1)).Error - if err != nil { - log.Printf("failed to update the Reviews count: %v", err) + if column_name == "subscription" { + // If user_id exists, increment the Reviews column by 1 + err = db.Debug().Model(&leaderboard).Update(column_name, true).Error + if err != nil { + log.Printf("failed to update the Reviews count: %v", err) + } + } else { + // If user_id exists, increment the Reviews column by 1 + err = db.Debug().Model(&leaderboard).Update(column_name, gorm.Expr(column_name+" + ?", 1)).Error + if err != nil { + log.Printf("failed to update the Reviews count: %v", err) + } } - data, err := GetActivityUnitXpByActivity(column_name) - if err != nil { - log.Printf("failed to get the ScoreBoard by ID: %v", err) + var data *ActivityUnitXp + + if column_name != "subscription" { + data, err = GetActivityUnitXpByActivity(column_name) + if err != nil { + log.Printf("failed to get the ScoreBoard by ID: %v", err) + } + } else { + data.Activity = "true" } err = UpdateScoreBoard(leaderboard.ID, ScoreBoard{ - ID: uuid.New().String(), - Reviews: leaderboard.Reviews, - Domain: leaderboard.Domain, - UserId: leaderboard.UserId, - Nodes: leaderboard.Nodes, - DWifi: leaderboard.DWifi, - Discord: leaderboard.Discord, - Twitter: leaderboard.Twitter, - Telegram: leaderboard.Telegram, - CreatedAt: leaderboard.CreatedAt, - UpdatedAt: leaderboard.UpdatedAt, + ID: uuid.New().String(), + Reviews: leaderboard.Reviews, + Domain: leaderboard.Domain, + UserId: leaderboard.UserId, + Nodes: leaderboard.Nodes, + DWifi: leaderboard.DWifi, + Discord: leaderboard.Discord, + Twitter: leaderboard.Twitter, + Telegram: leaderboard.Telegram, + Subscription: leaderboard.Subscription, + BetaTester: leaderboard.BetaTester, + CreatedAt: leaderboard.CreatedAt, + UpdatedAt: leaderboard.UpdatedAt, }, column_name, data.XP) if err != nil { log.Println("failed to update the ScoreBoard by ID : ", err.Error()) @@ -166,6 +188,8 @@ func UpdateScoreBoard(id string, updatedScore ScoreBoard, column_name string, va score.Twitter = updatedScore.Twitter * value case "telegram": score.Telegram = updatedScore.Telegram * value + case "subscription": + score.Subscription = true default: log.Printf("Invalid column name: %s", column_name) // return @@ -202,6 +226,8 @@ func UpdateScoreBoard(id string, updatedScore ScoreBoard, column_name string, va columnValue = updatedScore.Twitter * value case "telegram": columnValue = updatedScore.Telegram * value + case "subscription": + score.Subscription = true default: log.Printf("Invalid column name: %s", column_name) // return diff --git a/api/v1/leaderboard/leaderboard.go b/api/v1/leaderboard/leaderboard.go index 8ffcb5d..1b19959 100644 --- a/api/v1/leaderboard/leaderboard.go +++ b/api/v1/leaderboard/leaderboard.go @@ -6,6 +6,7 @@ import ( "log" "net/http" "sort" + "sync" "github.com/NetSepio/gateway/config/dbconfig" "github.com/NetSepio/gateway/models" @@ -31,6 +32,14 @@ func ApplyRoutes(r *gin.RouterGroup) { { u.GET("", UpdateLeaderBoardForAllUsers) } + a := r.Group("/BetaGraphqlQueryForLeaderboard") + { + a.GET("", BetaGraphqlQueryForLeaderboardHandler) + } + b := r.Group("/ErebrusQueryForLeaderboardHandler") + { + b.GET("", ErebrusQueryForLeaderboardHandler) + } } func getLeaderboard(c *gin.Context) { @@ -73,18 +82,20 @@ func getScoreBoard(c *gin.Context) { total := data.Reviews + data.Domain + data.Nodes + data.DWifi + data.Discord + data.Twitter + data.Telegram UserScoreBoard := models.UserScoreBoard{ - ID: data.ID, - Reviews: data.Reviews, - Domain: data.Domain, - UserId: data.UserId, - Nodes: data.Nodes, - DWifi: data.DWifi, - Discord: data.Discord, - Twitter: data.Twitter, - Telegram: data.Telegram, - CreatedAt: data.CreatedAt, - UpdatedAt: data.UpdatedAt, - TotalScore: total, + ID: data.ID, + Reviews: data.Reviews, + Domain: data.Domain, + UserId: data.UserId, + Nodes: data.Nodes, + DWifi: data.DWifi, + Discord: data.Discord, + Twitter: data.Twitter, + Telegram: data.Telegram, + Subscription: data.Subscription, + BetaTester: data.BetaTester, + CreatedAt: data.CreatedAt, + UpdatedAt: data.UpdatedAt, + TotalScore: total, } var user models.User @@ -157,17 +168,19 @@ func getAllUsersScoreBoard(c *gin.Context) { } } else { var data = models.UserScoreBoard{ - ID: scoreBoard.ID, - Reviews: scoreBoard.Reviews, - Domain: scoreBoard.Domain, - UserId: scoreBoard.UserId, - Nodes: scoreBoard.Nodes, - DWifi: scoreBoard.DWifi, - Discord: scoreBoard.Discord, - Twitter: scoreBoard.Twitter, - Telegram: scoreBoard.Telegram, - CreatedAt: scoreBoard.CreatedAt, - UpdatedAt: scoreBoard.UpdatedAt, + ID: scoreBoard.ID, + Reviews: scoreBoard.Reviews, + Domain: scoreBoard.Domain, + UserId: scoreBoard.UserId, + Nodes: scoreBoard.Nodes, + DWifi: scoreBoard.DWifi, + Discord: scoreBoard.Discord, + Twitter: scoreBoard.Twitter, + Telegram: scoreBoard.Telegram, + Subscription: scoreBoard.Subscription, + BetaTester: scoreBoard.BetaTester, + CreatedAt: scoreBoard.CreatedAt, + UpdatedAt: scoreBoard.UpdatedAt, } data.UserDetails = userDetail response = append(response, data) @@ -185,3 +198,52 @@ func UpdateLeaderBoardForAllUsers(c *gin.Context) { httpo.NewSuccessResponseP(200, "Leaderboard updated successfully", response).SendD(c) } + +func BetaGraphqlQueryForLeaderboardHandler(c *gin.Context) { + + var payload interface{} + + userids, err := BetaGraphqlQueryForLeaderboard() + if err != nil { + httpo.NewErrorResponse(500, err.Error()).SendD(c) + + } + + if len(userids) != 0 { + var wg sync.WaitGroup + wg.Add(1) + go func() { + defer wg.Wait() + for _, userId := range userids { + DynamicLeaderBoardUpdate(userId, "beta_tester") + } + }() + wg.Done() + } + + httpo.NewSuccessResponseP(200, "request successfully will be done withing few min, BetaGraphqlQueryForLeaderboardHandler", payload).SendD(c) +} +func ErebrusQueryForLeaderboardHandler(c *gin.Context) { + + var payload interface{} + + userids, err := ErebrusQueryForLeaderboard() + if err != nil { + httpo.NewErrorResponse(500, err.Error()).SendD(c) + + } + + if len(userids) != 0 { + var wg sync.WaitGroup + wg.Add(1) + go func() { + defer wg.Wait() + for _, userId := range userids { + DynamicLeaderBoardUpdate(userId, "subscription") + } + }() + wg.Done() + } + + httpo.NewSuccessResponseP(200, "request successfully will be done withing few min, ErebrusQueryForLeaderboardHandler", payload).SendD(c) +} diff --git a/api/v1/leaderboard/type.go b/api/v1/leaderboard/type.go index b984f25..1000a3a 100644 --- a/api/v1/leaderboard/type.go +++ b/api/v1/leaderboard/type.go @@ -5,17 +5,19 @@ import ( ) type Leaderboard struct { - ID string `gorm:"type:uuid;primary_key"` // 9. Id (Primary Key) - Reviews int `gorm:"not null"` // 1. Reviews - Domain int `gorm:"not null"` // 2. Domain (all projects) - UserId string `gorm:"type:uuid;not null"` // 3. User - Nodes int `gorm:"not null"` // 4. Nodes - DWifi int `gorm:"not null"` // 5. DWifi - Discord int `gorm:"not null"` // 6. Discord - Twitter int `gorm:"not null"` // 7. Twitter - Telegram int `gorm:"not null"` // 8. Telegram - CreatedAt time.Time `gorm:"autoCreateTime"` // 10. CreatedAt - UpdatedAt time.Time `gorm:"autoUpdateTime"` // 11. UpdatedAt + ID string `gorm:"type:uuid;primary_key"` // 9. Id (Primary Key) + Reviews int `gorm:"not null"` // 1. Reviews + Domain int `gorm:"not null"` // 2. Domain (all projects) + UserId string `gorm:"type:uuid;not null"` // 3. User + Nodes int `gorm:"not null"` // 4. Nodes + DWifi int `gorm:"not null"` // 5. DWifi + Discord int `gorm:"not null"` // 6. Discord + Twitter int `gorm:"not null"` // 7. Twitter + Telegram int `gorm:"not null"` // 8. Telegram + Subscription bool `gorm:"default:false"` + BetaTester int `gorm:"default:0" json:"beta_tester"` + CreatedAt time.Time `gorm:"autoCreateTime"` // 10. CreatedAt + UpdatedAt time.Time `gorm:"autoUpdateTime"` // 11. UpdatedAt } type ActivityUnitXp struct { @@ -23,15 +25,17 @@ type ActivityUnitXp struct { XP int `gorm:"not null"` } type ScoreBoard struct { - ID string `gorm:"type:uuid;default:uuid_generate_v4();primary_key"` - Reviews int - Domain int - UserId string `gorm:"type:uuid;not null"` - Nodes int - DWifi int - Discord int - Twitter int - Telegram int - CreatedAt time.Time `gorm:"autoCreateTime"` - UpdatedAt time.Time `gorm:"autoUpdateTime"` + ID string `gorm:"type:uuid;default:uuid_generate_v4();primary_key"` + Reviews int + Domain int + UserId string `gorm:"type:uuid;not null"` + Nodes int + DWifi int + Discord int + Twitter int + Telegram int + Subscription bool `gorm:"default:false"` + BetaTester int `gorm:"default:0" json:"beta_tester"` + CreatedAt time.Time `gorm:"autoCreateTime"` + UpdatedAt time.Time `gorm:"autoUpdateTime"` } diff --git a/config/models/models.go b/config/models/models.go index 417ec93..f2564a0 100644 --- a/config/models/models.go +++ b/config/models/models.go @@ -5,16 +5,16 @@ import ( ) type User struct { - UserId string `gorm:"primary_key" json:"userId,omitempty"` - Name string `json:"name,omitempty"` - WalletAddress *string `json:"walletAddress,omitempty"` - Discord string `json:"discord"` - Twitter string `json:"twitter"` - FlowIds []FlowId `gorm:"foreignkey:UserId" json:"-"` - ProfilePictureUrl string `json:"profilePictureUrl,omitempty"` - Country string `json:"country,omitempty"` - Feedbacks []UserFeedback `gorm:"foreignkey:UserId" json:"userFeedbacks"` - EmailId *string `json:"emailId,omitempty"` + UserId string `gorm:"primary_key" json:"userId,omitempty"` + Name string `json:"name,omitempty"` + WalletAddress *string `json:"walletAddress,omitempty"` + Discord string `json:"discord"` + Twitter string `json:"twitter"` + // FlowIds []FlowId `gorm:"foreignkey:UserId" json:"-"` + ProfilePictureUrl string `json:"profilePictureUrl,omitempty"` + Country string `json:"country,omitempty"` + // Feedbacks []UserFeedback `gorm:"foreignkey:UserId" json:"userFeedbacks"` + EmailId *string `json:"emailId,omitempty"` } type FlowId struct { diff --git a/graphql/betaTestingQuery.go b/graphql/betaTestingQuery.go new file mode 100644 index 0000000..8c53681 --- /dev/null +++ b/graphql/betaTestingQuery.go @@ -0,0 +1,28 @@ +package graphql + +// Function for Beta Test URL query +func BetaTestQuery() (*GraphQLResponse, error) { + url := "https://indexer-testnet.staging.gcp.aptosdev.com/v1/graphql" + query := ` + query MyQuery($_lt: timestamp = "2024-01-16T00:00:00.000000") { + current_token_datas_v2( + where: { + collection_id: {_eq: "0x212ee7ca88024f75e20c79dfee04898048fb9de15cb2da27d793151a6d58db25"}, + current_token_ownerships: {last_transaction_timestamp: {_lt: $_lt}} + } + ) { + token_name + description + current_token_ownerships { + owner_address + last_transaction_timestamp + } + } + } + ` + variables := map[string]interface{}{ + "_lt": "2024-01-16T00:00:00.000000", + } + + return leaderboardQuery(url, query, variables) +} diff --git a/graphql/common.function.go b/graphql/common.function.go new file mode 100644 index 0000000..8e6d16a --- /dev/null +++ b/graphql/common.function.go @@ -0,0 +1,63 @@ +package graphql + +import ( + "bytes" + "encoding/json" + "io/ioutil" + "net/http" +) + +// Struct for GraphQL response parsing +type TokenData struct { + TokenName string `json:"token_name"` + Description string `json:"description"` + CurrentTokenOwnerships []struct { + OwnerAddress string `json:"owner_address"` + LastTransactionTimestamp string `json:"last_transaction_timestamp"` + } `json:"current_token_ownerships"` +} + +type GraphQLResponse struct { + Data struct { + CurrentTokenDatasV2 []TokenData `json:"current_token_datas_v2"` + } `json:"data"` +} + +// Function to perform GraphQL request +func leaderboardQuery(url string, query string, variables map[string]interface{}) (*GraphQLResponse, error) { + payload := map[string]interface{}{ + "query": query, + "variables": variables, + } + + payloadBytes, err := json.Marshal(payload) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", url, bytes.NewBuffer(payloadBytes)) + if err != nil { + return nil, err + } + req.Header.Set("Content-Type", "application/json") + + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + bodyBytes, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, err + } + + var result GraphQLResponse + err = json.Unmarshal(bodyBytes, &result) + if err != nil { + return nil, err + } + + return &result, nil +} diff --git a/graphql/erebrusquery.go b/graphql/erebrusquery.go new file mode 100644 index 0000000..9fbd7a1 --- /dev/null +++ b/graphql/erebrusquery.go @@ -0,0 +1,22 @@ +package graphql + +// Function for APTOS Erebrus URL query +func ErebrusQuery() (*GraphQLResponse, error) { + url := "https://indexer.mainnet.aptoslabs.com/v1/graphql" + query := ` + query MyQuery { + current_token_datas_v2( + where: {collection_id: {_eq: "0x465ebc4eb9718e1555976796a4456fa1a2df8126b4e01ff5df7f9d14fb3eba19"}} + ) { + token_name + description + current_token_ownerships { + owner_address + last_transaction_timestamp + } + } + } + ` + + return leaderboardQuery(url, query, nil) +} diff --git a/models/Migrate/migrate_models.go b/models/Migrate/migrate_models.go index 1481b33..79f035a 100644 --- a/models/Migrate/migrate_models.go +++ b/models/Migrate/migrate_models.go @@ -180,31 +180,35 @@ type Erebrus struct { CollectionId string } type Leaderboard struct { - ID string `gorm:"type:uuid;default:uuid_generate_v4();primary_key"` - Reviews int - Domain int - UserId string `gorm:"type:uuid;not null"` - Nodes int - DWifi int - Discord int - Twitter int - Telegram int - CreatedAt time.Time `gorm:"autoCreateTime"` - UpdatedAt time.Time `gorm:"autoUpdateTime"` + ID string `gorm:"type:uuid;default:uuid_generate_v4();primary_key"` + Reviews int + Domain int + UserId string `gorm:"type:uuid;not null"` + Nodes int + DWifi int + Discord int + Twitter int + Telegram int + Subscription bool `gorm:"default:false"` + BetaTester int `gorm:"default:0" json:"beta_tester"` + CreatedAt time.Time `gorm:"autoCreateTime"` + UpdatedAt time.Time `gorm:"autoUpdateTime"` } type ScoreBoard struct { - ID string `gorm:"type:uuid;default:uuid_generate_v4();primary_key"` - Reviews int - Domain int - UserId string `gorm:"type:uuid;not null"` - Nodes int - DWifi int - Discord int - Twitter int - Telegram int - CreatedAt time.Time `gorm:"autoCreateTime"` - UpdatedAt time.Time `gorm:"autoUpdateTime"` + ID string `gorm:"type:uuid;default:uuid_generate_v4();primary_key"` + Reviews int + Domain int + UserId string `gorm:"type:uuid;not null"` + Nodes int + DWifi int + Discord int + Twitter int + Telegram int + Subscription bool `gorm:"default:false"` + BetaTester int `gorm:"default:0" json:"beta_tester"` + CreatedAt time.Time `gorm:"autoCreateTime"` + UpdatedAt time.Time `gorm:"autoUpdateTime"` } func (l *Leaderboard) BeforeCreate(tx *gorm.DB) (err error) { diff --git a/models/leaderboard.go b/models/leaderboard.go index f2f7682..6d08639 100644 --- a/models/leaderboard.go +++ b/models/leaderboard.go @@ -7,17 +7,19 @@ import ( ) type Leaderboard struct { - ID uuid.UUID `gorm:"type:uuid;primary_key" json:"id"` - Reviews int `gorm:"not null" json:"reviews"` - Domain int `gorm:"not null" json:"domain"` - UserId uuid.UUID `gorm:"type:uuid;not null" json:"userId"` - Nodes int `gorm:"not null" json:"nodes"` - DWifi int `gorm:"not null" json:"dwifi"` - Discord int `gorm:"not null" json:"discord"` - Twitter int `gorm:"not null" json:"twitter"` - Telegram int `gorm:"not null" json:"telegram"` - CreatedAt time.Time `gorm:"autoCreateTime" json:"createdAt"` - UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updatedAt"` + ID uuid.UUID `gorm:"type:uuid;primary_key" json:"id"` + Reviews int `gorm:"not null" json:"reviews"` + Domain int `gorm:"not null" json:"domain"` + UserId uuid.UUID `gorm:"type:uuid;not null" json:"userId"` + Nodes int `gorm:"not null" json:"nodes"` + DWifi int `gorm:"not null" json:"dwifi"` + Discord int `gorm:"not null" json:"discord"` + Twitter int `gorm:"not null" json:"twitter"` + Telegram int `gorm:"not null" json:"telegram"` + Subscription bool `gorm:"default:false"` + BetaTester int `gorm:"default:0" json:"beta_tester"` + CreatedAt time.Time `gorm:"autoCreateTime" json:"createdAt"` + UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updatedAt"` } func (Leaderboard) TableName() string { @@ -25,33 +27,37 @@ func (Leaderboard) TableName() string { } type ScoreBoard struct { - ID string `gorm:"type:uuid;default:uuid_generate_v4();primary_key"` - Reviews int - Domain int - UserId string `gorm:"type:uuid;not null"` - Nodes int - DWifi int - Discord int - Twitter int - Telegram int - CreatedAt time.Time `gorm:"autoCreateTime"` - UpdatedAt time.Time `gorm:"autoUpdateTime"` + ID string `gorm:"type:uuid;default:uuid_generate_v4();primary_key"` + Reviews int + Domain int + UserId string `gorm:"type:uuid;not null"` + Nodes int + DWifi int + Discord int + Twitter int + Telegram int + Subscription bool `gorm:"default:false"` + BetaTester int `gorm:"default:0" json:"beta_tester"` + CreatedAt time.Time `gorm:"autoCreateTime"` + UpdatedAt time.Time `gorm:"autoUpdateTime"` } type UserScoreBoard struct { - ID string `gorm:"type:uuid;default:uuid_generate_v4();primary_key"` - Reviews int - Domain int - UserId string `gorm:"type:uuid;not null"` - Nodes int - DWifi int - Discord int - Twitter int - Telegram int - CreatedAt time.Time `gorm:"autoCreateTime"` - UpdatedAt time.Time `gorm:"autoUpdateTime"` - TotalScore int `json:"totalScore"` - UserDetails User `json:"userDetails"` + ID string `gorm:"type:uuid;default:uuid_generate_v4();primary_key"` + Reviews int + Domain int + UserId string `gorm:"type:uuid;not null"` + Nodes int + DWifi int + Discord int + Twitter int + Telegram int + Subscription bool `gorm:"default:false"` + BetaTester int `gorm:"default:0" json:"beta_tester"` + CreatedAt time.Time `gorm:"autoCreateTime"` + UpdatedAt time.Time `gorm:"autoUpdateTime"` + TotalScore int `json:"totalScore"` + UserDetails User `json:"userDetails"` } type GetProfilePayload struct {