-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathdto.go
More file actions
135 lines (109 loc) · 3.19 KB
/
Copy pathdto.go
File metadata and controls
135 lines (109 loc) · 3.19 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package votings
import (
"net/http"
"github.com/google/uuid"
)
type Vote struct {
Voting uuid.UUID `json:"voting"`
Note uuid.UUID `json:"note"`
User uuid.UUID `json:"user"`
}
func (v *Vote) From(vote DatabaseVote) *Vote {
v.Voting = vote.Voting
v.Note = vote.Note
v.User = vote.User
return v
}
func Votes(votes []DatabaseVote) []*Vote {
if votes == nil {
return nil
}
list := make([]*Vote, len(votes))
for index, vote := range votes {
list[index] = new(Vote).From(vote)
}
return list
}
// VoteRequest represents the request to add or delete a vote.
type VoteRequest struct {
Note uuid.UUID `json:"note"`
Board uuid.UUID `json:"-"`
User uuid.UUID `json:"-"`
}
// VotingCreateRequest represents the request to create a new voting session.
type VotingCreateRequest struct {
Board uuid.UUID `json:"-"`
VoteLimit int `json:"voteLimit"`
AllowMultipleVotes bool `json:"allowMultipleVotes"`
ShowVotesOfOthers bool `json:"showVotesOfOthers"`
IsAnonymous bool `json:"isAnonymous"`
}
// VotingCloseRequest represents the request to update a voting session.
type VotingCloseRequest struct {
ID uuid.UUID `json:"-"`
Board uuid.UUID `json:"-"`
Status VotingStatus `json:"status"`
}
// Voting is the response for all voting requests.
type Voting struct {
ID uuid.UUID `json:"id"`
VoteLimit int `json:"voteLimit"`
AllowMultipleVotes bool `json:"allowMultipleVotes"`
ShowVotesOfOthers bool `json:"showVotesOfOthers"`
Status VotingStatus `json:"status"`
VotingResults *VotingResults `json:"votes,omitempty"`
IsAnonymous bool `json:"isAnonymous"`
}
func (v *Voting) From(voting DatabaseVoting, votes []DatabaseVote) *Voting {
v.ID = voting.ID
v.VoteLimit = voting.VoteLimit
v.AllowMultipleVotes = voting.AllowMultipleVotes
v.ShowVotesOfOthers = voting.ShowVotesOfOthers
v.Status = voting.Status
v.VotingResults = getVotingWithResults(voting, votes)
v.IsAnonymous = voting.IsAnonymous
return v
}
func (*Voting) Render(_ http.ResponseWriter, _ *http.Request) error {
return nil
}
type VotingResults struct {
Total int `json:"total"`
Votes map[uuid.UUID]VotingResultsPerNote `json:"votesPerNote"`
}
type VotingResultsPerUser struct {
ID uuid.UUID `json:"id"`
Total int `json:"total"`
}
type VotingResultsPerNote struct {
Total int `json:"total"`
Users *[]VotingResultsPerUser `json:"userVotes,omitempty"`
}
type VotingUpdated struct {
Notes []Note `json:"notes"`
Voting *Voting `json:"voting"`
}
type VoteFilter struct {
Voting *uuid.UUID
User *uuid.UUID
Note *uuid.UUID
}
type Note struct {
// The id of the note
ID uuid.UUID `json:"id"`
// The author of the note.
Author uuid.UUID `json:"author"`
// The text of the note.
Text string `json:"text"`
Edited bool `json:"edited"`
// The position of the note.
Position NotePosition `json:"position"`
}
type NotePosition struct {
// The column of the note.
Column uuid.UUID `json:"column"`
// The parent note for this note in a stack.
Stack uuid.NullUUID `json:"stack"`
// The note rank.
Rank int `json:"rank"`
}