govote/voting/vote/vote.go
2024-05-13 13:20:26 +02:00

36 lines
643 B
Go

package vote
import (
"fmt"
"time"
)
type Vote struct {
Id string
Elector string
Choice Choice
timestamp time.Time
}
func NewVote(id, elector string, choice Choice) Vote {
return Vote{
Id: id,
Elector: elector,
Choice: choice,
timestamp: time.Now().UTC(),
}
}
func NewVoteWithTimestamp(id, elector string, choice Choice, timestamp time.Time) Vote {
return Vote{
Id: id,
Elector: elector,
Choice: choice,
timestamp: timestamp,
}
}
func (vote Vote) String() string {
return fmt.Sprintf("%s %s %s %s", vote.Id, vote.timestamp.Format(time.DateTime), vote.Choice, vote.Elector)
}