-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_proposal_details.go
47 lines (39 loc) · 1.12 KB
/
get_proposal_details.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package election
import (
"context"
"github.com/inklabs/vote/internal/electionrepository"
)
// GetProposalDetails returns the full details of a Proposal.
type GetProposalDetails struct {
ProposalID string
}
type GetProposalDetailsResponse struct {
ElectionID string
ProposalID string
OwnerUserID string
Name string
Description string
ProposedAt int
}
type getProposalDetailsHandler struct {
repository electionrepository.Repository
}
func NewGetProposalDetailsHandler(repository electionrepository.Repository) *getProposalDetailsHandler {
return &getProposalDetailsHandler{
repository: repository,
}
}
func (h *getProposalDetailsHandler) On(ctx context.Context, query GetProposalDetails) (GetProposalDetailsResponse, error) {
proposal, err := h.repository.GetProposal(ctx, query.ProposalID)
if err != nil {
return GetProposalDetailsResponse{}, err
}
return GetProposalDetailsResponse{
ElectionID: proposal.ElectionID,
ProposalID: proposal.ProposalID,
OwnerUserID: proposal.OwnerUserID,
Name: proposal.Name,
Description: proposal.Description,
ProposedAt: proposal.ProposedAt,
}, nil
}