govote/voting/vote/vote.go

36 lines
648 B
Go
Raw Normal View History

2024-05-12 22:47:24 +00:00
package vote
import (
"fmt"
"time"
)
type Vote struct {
Id string
2024-05-13 08:45:38 +00:00
Elector string
Choice Choice
timestamp time.Time
2024-05-12 22:47:24 +00:00
}
func NewVote(id, elector string, choice Choice) Vote {
2024-05-13 08:45:38 +00:00
return Vote{
Id: id,
2024-05-13 08:45:38 +00:00
Elector: elector,
Choice: choice,
timestamp: time.Now().UTC(),
}
2024-05-12 22:47:24 +00:00
}
func NewVoteWithTimestamp(id, elector string, choice Choice, timestamp time.Time) Vote {
2024-05-13 08:45:38 +00:00
return Vote{
Id: id,
2024-05-13 08:45:38 +00:00
Elector: elector,
Choice: choice,
timestamp: timestamp,
}
2024-05-12 22:47:24 +00:00
}
func (vote Vote) String() string {
return fmt.Sprintf("%s %s %s %s", vote.Id, vote.timestamp.Format(time.DateTime), vote.Choice, vote.Elector)
2024-05-12 22:47:24 +00:00
}