47 lines
1008 B
Go
47 lines
1008 B
Go
|
package cmd
|
||
|
|
||
|
import (
|
||
|
"code.c-base.org/baccenfutter/govote/store"
|
||
|
"code.c-base.org/baccenfutter/govote/voting/vote"
|
||
|
"github.com/google/uuid"
|
||
|
"github.com/urfave/cli/v2"
|
||
|
)
|
||
|
|
||
|
var voteCmd = &cli.Command{
|
||
|
Name: "vote",
|
||
|
Usage: "📄 Place vote",
|
||
|
Flags: []cli.Flag{
|
||
|
&cli.StringFlag{
|
||
|
Name: "voting-id",
|
||
|
Usage: "Voting ID",
|
||
|
Aliases: []string{"V"},
|
||
|
Required: true,
|
||
|
},
|
||
|
&cli.StringFlag{
|
||
|
Name: "elector",
|
||
|
Usage: "Elector",
|
||
|
Aliases: []string{"E"},
|
||
|
Required: true,
|
||
|
},
|
||
|
&cli.StringFlag{
|
||
|
Name: "choice",
|
||
|
Usage: "Choice",
|
||
|
Aliases: []string{"C"},
|
||
|
Required: true,
|
||
|
},
|
||
|
},
|
||
|
Action: func(ctx *cli.Context) error {
|
||
|
var (
|
||
|
id = uuid.New().String()
|
||
|
votingID = ctx.String("voting-id")
|
||
|
elector = ctx.String("elector")
|
||
|
)
|
||
|
choice, err := vote.ChoiceFromString(ctx.String("choice"))
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
err = store.PlaceVote(id, votingID, elector, choice)
|
||
|
return err
|
||
|
},
|
||
|
}
|