From 42e01a7cd3227d783a627736ae497bcfc88ff7b9 Mon Sep 17 00:00:00 2001 From: Jared Date: Tue, 17 Jan 2023 00:14:57 -0500 Subject: [PATCH] Rename some variables --- data/context.go | 3 ++- endpoints/closerewardfund.go | 3 ++- endpoints/contributionstream.go | 7 ++++--- endpoints/createqueue.go | 3 ++- endpoints/createrewardfund.go | 5 +++-- endpoints/getqueuemembers.go | 8 ++++++-- endpoints/getrewardfund.go | 17 ++++++++-------- endpoints/login.go | 7 ++++--- endpoints/submitfund.go | 35 +++++++++++++++++---------------- 9 files changed, 50 insertions(+), 38 deletions(-) diff --git a/data/context.go b/data/context.go index 46b0c60..90ee917 100644 --- a/data/context.go +++ b/data/context.go @@ -2,10 +2,11 @@ package data import ( "fmt" + "time" + "github.com/spf13/viper" "gorm.io/driver/postgres" "gorm.io/gorm" - "time" ) type ModelBase struct { diff --git a/endpoints/closerewardfund.go b/endpoints/closerewardfund.go index a54c7a5..a6a9e84 100644 --- a/endpoints/closerewardfund.go +++ b/endpoints/closerewardfund.go @@ -2,9 +2,10 @@ package endpoints import ( "encoding/json" + "net/http" + "github.com/imosed/signet/auth" . "github.com/imosed/signet/data" - "net/http" ) type CloseRewardFundRequest struct { diff --git a/endpoints/contributionstream.go b/endpoints/contributionstream.go index a13585f..eea4965 100644 --- a/endpoints/contributionstream.go +++ b/endpoints/contributionstream.go @@ -2,6 +2,10 @@ package endpoints import ( "fmt" + "net/http" + "strconv" + "strings" + "github.com/gorilla/websocket" . "github.com/imosed/signet/data" "github.com/spf13/viper" @@ -9,9 +13,6 @@ import ( "github.com/stellar/go/protocols/horizon" "github.com/stellar/go/protocols/horizon/operations" "golang.org/x/net/context" - "net/http" - "strconv" - "strings" ) var upgrader = websocket.Upgrader{ diff --git a/endpoints/createqueue.go b/endpoints/createqueue.go index 2a5e92d..7bb78ef 100644 --- a/endpoints/createqueue.go +++ b/endpoints/createqueue.go @@ -2,8 +2,9 @@ package endpoints import ( "encoding/json" - . "github.com/imosed/signet/data" "net/http" + + . "github.com/imosed/signet/data" ) type CreateQueueRequest struct { diff --git a/endpoints/createrewardfund.go b/endpoints/createrewardfund.go index 16261b5..d0897eb 100644 --- a/endpoints/createrewardfund.go +++ b/endpoints/createrewardfund.go @@ -3,12 +3,13 @@ package endpoints import ( "encoding/json" "fmt" + "net/http" + "strconv" + "github.com/imosed/signet/auth" . "github.com/imosed/signet/data" "github.com/stellar/go/clients/horizonclient" "github.com/stellar/go/protocols/horizon" - "net/http" - "strconv" ) type CreateRewardFundRequest struct { diff --git a/endpoints/getqueuemembers.go b/endpoints/getqueuemembers.go index 741124d..e0c5809 100644 --- a/endpoints/getqueuemembers.go +++ b/endpoints/getqueuemembers.go @@ -2,13 +2,16 @@ package endpoints import ( "encoding/json" - . "github.com/imosed/signet/data" "net/http" + + . "github.com/imosed/signet/data" ) type QueueMember struct { + ID uint `json:"id"` Asset string `json:"asset"` Title string `json:"title"` + Order int `json:"order"` } type GetQueueMembersRequest struct { @@ -27,7 +30,8 @@ func GetQueueMembers(w http.ResponseWriter, r *http.Request) { } var members []QueueMember - Db.Table("queue_orders qo").Select("reward_fund_id, asset, title").Where("queue_id = ?", req.ID). + Db.Table("queue_orders qo").Select("rf.id, asset, title, qo.order"). + Where("queue_id = ?", req.ID). Joins("inner join reward_funds rf on qo.reward_fund_id = rf.id"). Scan(&members) diff --git a/endpoints/getrewardfund.go b/endpoints/getrewardfund.go index 86bc320..597b856 100644 --- a/endpoints/getrewardfund.go +++ b/endpoints/getrewardfund.go @@ -2,10 +2,11 @@ package endpoints import ( "encoding/json" - . "github.com/imosed/signet/data" - "gorm.io/gorm/clause" "net/http" "time" + + . "github.com/imosed/signet/data" + "gorm.io/gorm/clause" ) type Total struct { @@ -13,7 +14,7 @@ type Total struct { } type GetRewardFundRequest struct { - Id uint `json:"id"` + ID uint `json:"id"` ConsolidateContributions bool `json:"consolidateContributions"` } @@ -35,7 +36,7 @@ func GetRewardFund(resp http.ResponseWriter, req *http.Request) { panic("Could not read requested fund") } - found := Db.Preload(clause.Associations).Find(&fund, requestedFund.Id).RowsAffected + found := Db.Preload(clause.Associations).Find(&fund, requestedFund.ID).RowsAffected if found == 0 { resp.WriteHeader(404) return @@ -79,7 +80,7 @@ func GetRewardFund(resp http.ResponseWriter, req *http.Request) { } type GetContributionsRequest struct { - Id uint `json:"id"` + ID uint `json:"id"` Offset int `json:"offset"` ForDate string `json:"forDate"` ConsolidateContributions bool `json:"consolidateContributions"` @@ -101,10 +102,10 @@ func GetContributions(w http.ResponseWriter, r *http.Request) { } var resp GetContributionsResponse - baseQuery := Db.Table("contributions").Where("reward_fund_id = ?", req.Id).Offset(req.Offset).Limit(30) - baseCount := Db.Table("contributions").Where("reward_fund_id = ?", req.Id) + baseQuery := Db.Table("contributions").Where("reward_fund_id = ?", req.ID).Offset(req.Offset).Limit(30) + baseCount := Db.Table("contributions").Where("reward_fund_id = ?", req.ID) - Db.Table("contributions").Select("distinct on (created_at::TIMESTAMP::DATE) created_at").Where("reward_fund_id = ?", req.Id).Scan(&resp.Dates) + Db.Table("contributions").Select("distinct on (created_at::TIMESTAMP::DATE) created_at").Where("reward_fund_id = ?", req.ID).Scan(&resp.Dates) if req.ForDate == "" { if req.ConsolidateContributions { diff --git a/endpoints/login.go b/endpoints/login.go index eb16f75..9f966a2 100644 --- a/endpoints/login.go +++ b/endpoints/login.go @@ -2,12 +2,13 @@ package endpoints import ( "encoding/json" + "net/http" + "time" + "github.com/golang-jwt/jwt/v4" "github.com/imosed/signet/auth" . "github.com/imosed/signet/data" "github.com/spf13/viper" - "net/http" - "time" ) type LoginResponse struct { @@ -22,7 +23,7 @@ func Login(w http.ResponseWriter, r *http.Request) { } var userData struct { - Id uint + ID uint Password string Privileges uint } diff --git a/endpoints/submitfund.go b/endpoints/submitfund.go index 0e2b8bc..e882659 100644 --- a/endpoints/submitfund.go +++ b/endpoints/submitfund.go @@ -3,16 +3,17 @@ package endpoints import ( "encoding/json" "fmt" + "net/http" + . "github.com/imosed/signet/data" "github.com/stellar/go/clients/horizonclient" "github.com/stellar/go/protocols/horizon" - "net/http" ) var client = horizonclient.DefaultTestNetClient type SubmitFundRequest struct { - FundId uint `json:"fundId"` + FundID uint `json:"fundId"` } func SubmitFund(w http.ResponseWriter, r *http.Request) { @@ -23,12 +24,12 @@ func SubmitFund(w http.ResponseWriter, r *http.Request) { } var fund RewardFund - Db.Find(&fund, req.FundId) + Db.Find(&fund, req.FundID) - //source := keypair.MustParseFull(fund.FundWallet) - //sourceReq := horizonclient.AccountRequest{AccountID: source.Address()} - //var sourceAcct horizon.Account - //sourceAcct, err = client.AccountDetail(sourceReq) + // source := keypair.MustParseFull(fund.FundWallet) + // sourceReq := horizonclient.AccountRequest{AccountID: source.Address()} + // var sourceAcct horizon.Account + // sourceAcct, err = client.AccountDetail(sourceReq) offerReq := horizonclient.OfferRequest{ Selling: fmt.Sprintf("%s:%s", fund.Asset, fund.IssuerWallet), @@ -45,8 +46,8 @@ func SubmitFund(w http.ResponseWriter, r *http.Request) { } } - //var tx *txnbuild.Transaction - //tx, err = txnbuild.NewTransaction( + // var tx *txnbuild.Transaction + // tx, err = txnbuild.NewTransaction( // txnbuild.TransactionParams{ // SourceAccount: &sourceAcct, // IncrementSequenceNum: true, @@ -69,20 +70,20 @@ func SubmitFund(w http.ResponseWriter, r *http.Request) { // TimeBounds: txnbuild.NewInfiniteTimeout(), // TODO: change from infinite // }, // }) - //if err != nil { + // if err != nil { // panic("Could not submit reward fund") - //} + // } // - //tx, err = tx.Sign(network.TestNetworkPassphrase, source) - //if err != nil { + // tx, err = tx.Sign(network.TestNetworkPassphrase, source) + // if err != nil { // panic("Could not submit fund") - //} + // } // - //var response horizon.Transaction - //response, err = client.SubmitTransaction(tx) + // var response horizon.Transaction + // response, err = client.SubmitTransaction(tx) var resp SuccessResponse - //resp.Success = response.Successful + // resp.Success = response.Successful err = json.NewEncoder(w).Encode(resp) if err != nil {