Skip to content

Commit

Permalink
Merge pull request #82 from goverland-labs/feature/76-dont-use-sessio…
Browse files Browse the repository at this point in the history
…n-id-in-voting

Add vote meta info for vote validation
  • Loading branch information
WertND authored Dec 24, 2024
2 parents 2d3cf64 + dd1464b commit c346620
Show file tree
Hide file tree
Showing 12 changed files with 237 additions and 131 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ require (
)

require (
cloud.google.com/go/compute/metadata v0.5.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down
6 changes: 6 additions & 0 deletions internal/vote/dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ type ValidateResponse struct {

VotingPower float64
ValidationError *ValidationError
VoteStatus VoteStatus
}

type VoteStatus struct {
Voted bool
Choice json.RawMessage
}

type ValidationError struct {
Expand Down
6 changes: 6 additions & 0 deletions internal/vote/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ func (s *Server) Validate(ctx context.Context, req *storagepb.ValidateRequest) (
Ok: validateResp.OK,
VotingPower: validateResp.VotingPower,
ValidationError: validationError,
VoteStatus: &storagepb.VoteStatus{
Voted: validateResp.VoteStatus.Voted,
Choice: &protoany.Any{
Value: validateResp.VoteStatus.Choice,
},
},
}, nil
}

Expand Down
17 changes: 17 additions & 0 deletions internal/vote/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,27 @@ func (s *Service) Validate(ctx context.Context, req ValidateRequest) (ValidateRe
}
}

voted, err := s.repo.GetByFilters([]Filter{
VoterFilter{Voter: req.Voter},
ProposalIDsFilter{ProposalIDs: []string{req.Proposal}},
}, 1, 0, "")
if err != nil {
return ValidateResponse{}, fmt.Errorf("get by filters: %w", err)
}

var votedStatus VoteStatus
if len(voted.Votes) > 0 {
votedStatus = VoteStatus{
Voted: true,
Choice: voted.Votes[0].Choice,
}
}

return ValidateResponse{
OK: resp.GetOk(),
VotingPower: resp.GetVotingPower(),
ValidationError: validationError,
VoteStatus: votedStatus,
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion protocol/storagepb/base.pb.go

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

2 changes: 1 addition & 1 deletion protocol/storagepb/dao.pb.go

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

2 changes: 1 addition & 1 deletion protocol/storagepb/delegate.pb.go

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

2 changes: 1 addition & 1 deletion protocol/storagepb/ens.pb.go

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

2 changes: 1 addition & 1 deletion protocol/storagepb/proposal.pb.go

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

2 changes: 1 addition & 1 deletion protocol/storagepb/stats.pb.go

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

Loading

0 comments on commit c346620

Please sign in to comment.