Giter Club home page Giter Club logo

go-voting's Introduction

GO-Voting

CI: Test

Subject:

Installation

Install Go.

Clone the repository:

go install github.com/BaptisteBuvron/go-voting/cmd/[email protected]
go install github.com/BaptisteBuvron/go-voting/cmd/[email protected]

Run the server:

server
# go run github.com/BaptisteBuvron/go-voting/cmd/[email protected]

Example commands for client:

client v1 new_ballot majority '2023-11-26T16:27:11+00:00' 'v1,v2,v3' 5 '1,2,3,4,5'
client v1 vote majority-18c0c24a3245e '4,2,3,1,5'
client v1 result majority-18c0c24a3245e

Run tests:

go test '-coverprofile=coverage.txt' -v ./...
go tool cover '-html=coverage.txt'

API

Erreurs communes

Pendant l'utilisation de l'API certaines erreures peuvent se produire. Voici la liste des erreurs possibles :

Code retour Signification
500 Une erreur interne au serveur est survenue
400 La requête est mal formée ou JSON incomplet
405 La ressource n'existe pas

Commande /new_ballot

  • Requête : POST
  • Objet JSON envoyé
propriété type exemple de valeurs possibles
rule string "majority","borda", "approval", "stv", "copeland", "kemeny"
deadline string "2023-10-09T23:05:08+02:00" (format RFC 3339)
voter-ids [string,...] ["ag_id1", "ag_id2", "ag_id3"]
#alts int 12
tie-break [int,...]. [4, 2, 3, 5, 9, 8, 7, 1, 6, 11, 12, 10]

Remarques : la deadline représente la date de fin de vote. Pour celle-ci, utiliser la bibliothèque standard de Go, en particulier le package time. La propriété #alts représente le nombre d'alternatives, numérotées de 1 à #alts.

  • Code retour
Code retour Signification
201 vote créé
400 bad request (il manque une règle ou il n'y a pas au moins un voter d'enregistré ou il n'y a pas au moins deux alternatives, les alternatives données ne sont pas valides, le tie-break ne correspond pas aux nombres d'alternatives)
501 not implemented (la règle de vote choisie n'est pas implémenter dans le système)
500 L'ID aléatoire n'a pas pu être généré
  • Objet JSON renvoyé (si 201)
propriété type exemple de valeurs possibles
ballot-id string "majority-18c0c24a3245e"

Commande /vote

  • Requête : POST
  • Objet JSON envoyé
propriété type exemple de valeurs possibles
agent-id string "ag_id1"
ballot-id string "majority-18c0c24a3245e"
prefs [int,...] [1, 2, 4, 3]
options [int,...] [3]

Remarque :options est facultatif et permet de passer des renseignements supplémentaires (par exemple le seuil d'acceptation en approval)

  • code retour
Code retour Signification
200 vote pris en compte
400 bad request (erreur dans les préférences de vote)
403 vote déjà effectué ou la personne n'a pas accès au vote
404 le ballot de vote n'existe pas
503 la deadline est dépassée

Nous n'avons pas utilisé le code 501 Not Implemented. Nous avons ajouté le code 404 Not Found quand le ballot n'existe pas.

Commande /result

  • Requête : POST
  • Objet JSON envoyé
propriété type exemple de valeurs possibles
ballot-id string "majority-18c0c24a3245e"
  • code retour
Code retour Signification
200 OK
425 Too early
404 Not Found
  • Objet JSON renvoyé (si 200)
propriété type exemple de valeurs possibles
winner int 4
ranking [int,...] [2, 1, 4, 3]

Remarque : la propriété ranking est facultative.

go-voting's People

Contributors

dashstrom avatar baptistebuvron avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.