Skip to content

Commit

Permalink
Merge pull request #77 from goverland-labs/feature/vote-now
Browse files Browse the repository at this point in the history
Feature/vote now
  • Loading branch information
WertND authored Oct 2, 2024
2 parents 8f1dc1e + abb7aff commit 91e7da3
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 147 deletions.
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25d
github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/goverland-labs/goverland-datasource-snapshot/protocol v0.5.5-0.20240922104205-01052c141176 h1:lWSkLZNd+DxdaImHAt1A/N2xIdmMUc1UDcQLt0a5EWE=
github.com/goverland-labs/goverland-datasource-snapshot/protocol v0.5.5-0.20240922104205-01052c141176/go.mod h1:YEfWXRljVwjMnbPbolcatOwY6+QtjcKy1Tc4oLWCPA0=
github.com/goverland-labs/goverland-datasource-snapshot/protocol v0.5.5-0.20240922121208-510be7ba9c34 h1:rPS4Tfxq/WINYvwr+hY6NrDmSbZZFTrVafvAT83A3eQ=
github.com/goverland-labs/goverland-datasource-snapshot/protocol v0.5.5-0.20240922121208-510be7ba9c34/go.mod h1:YEfWXRljVwjMnbPbolcatOwY6+QtjcKy1Tc4oLWCPA0=
github.com/goverland-labs/goverland-datasource-snapshot/protocol v0.6.2 h1:MlshVgWkFXog+ohQh4KbCwvbFAYOO+sNtSGp1pWsuZM=
github.com/goverland-labs/goverland-datasource-snapshot/protocol v0.6.2/go.mod h1:YEfWXRljVwjMnbPbolcatOwY6+QtjcKy1Tc4oLWCPA0=
github.com/goverland-labs/goverland-helpers-ens-resolver/protocol v0.1.0 h1:Gc0aRk6jL9zJV2Ce5h+bsIl49OJHn3m27IPVeYOJTrE=
Expand Down
3 changes: 2 additions & 1 deletion internal/ensresolver/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ type EnsName struct {

func (r *Repo) BatchCreate(data []EnsName) error {
return r.db.Model(&EnsName{}).Clauses(clause.OnConflict{
DoNothing: true,
Columns: []clause.Column{{Name: "name"}},
DoUpdates: clause.AssignmentColumns([]string{"address"}),
}).CreateInBatches(data, defaultBatchSize).Error
}

Expand Down
12 changes: 12 additions & 0 deletions internal/proposal/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,15 @@ func (f SkipCanceled) Apply(db *gorm.DB) *gorm.DB {

return db.Where(`state != 'canceled'`)
}

type ActiveFilter struct {
}

func (f ActiveFilter) Apply(db *gorm.DB) *gorm.DB {
var (
dummy Proposal
_ = dummy.State
)

return db.Where(`state = 'active'`)
}
4 changes: 4 additions & 0 deletions internal/proposal/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func (s *Server) GetByFilter(_ context.Context, req *storagepb.ProposalByFilterR
filters = append(filters, DaoIDsFilter{DaoIDs: daos})
}

if req.GetOnlyActive() {
filters = append(filters, ActiveFilter{})
}

if req.GetTitle() != "" {
filters = append(filters,
TitleFilter{Title: req.GetTitle()},
Expand Down
11 changes: 10 additions & 1 deletion internal/vote/filters.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package vote

import (
"github.com/goverland-labs/goverland-core-storage/internal/proposal"
"gorm.io/gorm"

"github.com/goverland-labs/goverland-core-storage/internal/proposal"
)

var (
Expand Down Expand Up @@ -60,3 +61,11 @@ type QueryFilter struct {
func (f QueryFilter) Apply(db *gorm.DB) *gorm.DB {
return db.Where("voter = ? or ens_name = ?", f.Query, f.Query)
}

type DaoIDFilter struct {
DaoID string
}

func (f DaoIDFilter) Apply(db *gorm.DB) *gorm.DB {
return db.Where("dao_id = ?", f.DaoID)
}
4 changes: 4 additions & 0 deletions internal/vote/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func (s *Server) GetVotes(_ context.Context, req *storagepb.VotesFilterRequest)
filters = append(filters, QueryFilter{Query: req.GetQuery()})
}

if req.GetDaoId() != "" {
filters = append(filters, DaoIDFilter{DaoID: req.GetDaoId()})
}

list, err := s.sp.GetByFilters(filters, limit, offset, req.GetOrderByVoter())
if err != nil {
log.Error().Err(err).Msgf("get votes by filter: %+v", req)
Expand Down
64 changes: 38 additions & 26 deletions protocol/storagepb/proposal.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions protocol/storagepb/proposal.proto
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ message ProposalByFilterRequest {
optional string order = 6;
optional bool top = 7;
repeated string proposal_ids = 8;
optional bool only_active = 9;
}

message ProposalByFilterResponse {
Expand Down
Loading

0 comments on commit 91e7da3

Please sign in to comment.