Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
IA04binôme2A
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gabrielle Van De Vijver
IA04binôme2A
Commits
b9271e96
Commit
b9271e96
authored
1 year ago
by
Balthazar Wilson
Browse files
Options
Downloads
Patches
Plain Diff
add: now possible to check results at the end of the vote
parent
3d08c833
No related branches found
No related tags found
1 merge request
!8
implémentation des votants par Balthazar
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
agt/ballotagent/result.go
+60
-0
60 additions, 0 deletions
agt/ballotagent/result.go
with
60 additions
and
0 deletions
agt/ballotagent/result.go
0 → 100644
+
60
−
0
View file @
b9271e96
package
ballotagent
import
(
"encoding/json"
"fmt"
"net/http"
rad
"gitlab.utc.fr/gvandevi/ia04binome2a"
)
func
(
rsa
*
BallotServerAgent
)
sendResults
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
// mise à jour du nombre de requêtes
rsa
.
Lock
()
defer
rsa
.
Unlock
()
rsa
.
reqCount
++
// vérification de la méthode de la requête
if
!
rsa
.
checkMethod
(
"POST"
,
w
,
r
)
{
return
}
// décodage de la requête
req
,
err
:=
decodeRequest
[
rad
.
Ballot
](
r
)
if
err
!=
nil
{
w
.
WriteHeader
(
http
.
StatusBadRequest
)
fmt
.
Fprint
(
w
,
err
.
Error
())
return
}
// recupération des infos
scrutin
:=
req
.
BallotID
voteBallot
:=
rad
.
Ballot
{
BallotID
:
scrutin
}
ballots
:=
make
([]
rad
.
Ballot
,
len
(
rsa
.
ballots
))
// Check if ballot exists
i
:=
0
for
k
:=
range
rsa
.
ballots
{
ballots
[
i
]
=
k
i
++
}
if
!
contains
[
rad
.
Ballot
](
ballots
,
voteBallot
)
{
w
.
WriteHeader
(
http
.
StatusNotFound
)
msg
:=
fmt
.
Sprintf
(
"The ballot '%s' does not exist"
,
scrutin
)
w
.
Write
([]
byte
(
msg
))
return
}
ballot
:=
rsa
.
ballots
[
voteBallot
]
// Check que la deadline n'est pas déjà passée
if
ballot
.
isOpen
{
w
.
WriteHeader
(
http
.
StatusTooEarly
)
msg
:=
fmt
.
Sprintf
(
"The ballot '%s' is not closed yet."
,
scrutin
)
w
.
Write
([]
byte
(
msg
))
return
}
w
.
WriteHeader
(
http
.
StatusOK
)
serial
,
_
:=
json
.
Marshal
(
rsa
.
ballots
[
voteBallot
]
.
results
)
w
.
Write
(
serial
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment