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
686017d9
Commit
686017d9
authored
1 year ago
by
Balthazar Wilson
Browse files
Options
Downloads
Patches
Plain Diff
finish: vote feature
parent
7cec03a3
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/vote.go
+23
-12
23 additions, 12 deletions
agt/ballotagent/vote.go
with
23 additions
and
12 deletions
agt/ballotagent/vote.go
+
23
−
12
View file @
686017d9
...
...
@@ -8,7 +8,7 @@ import (
cs
"gitlab.utc.fr/gvandevi/ia04binome2a/comsoc"
)
func
contains
[
S
[]
string
|
[]
rad
.
Ballot
,
E
string
|
rad
.
Ballot
](
s
S
,
e
E
)
bool
{
func
contains
[
S
string
|
rad
.
Ballot
](
s
[]
S
,
e
S
)
bool
{
for
_
,
a
:=
range
s
{
if
a
==
e
{
return
true
...
...
@@ -25,6 +25,18 @@ func intToAlt(s []int) []cs.Alternative {
return
res
}
func
removeFromSlice
(
slice
[]
string
,
elem
string
)
[]
string
{
res
:=
make
([]
string
,
0
)
i
:=
0
for
_
,
el
:=
range
slice
{
if
el
!=
elem
{
res
=
append
(
res
,
el
)
i
++
}
}
return
res
}
func
(
rsa
*
BallotServerAgent
)
receiveVote
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
// mise à jour du nombre de requêtes
rsa
.
Lock
()
...
...
@@ -55,7 +67,7 @@ func (rsa *BallotServerAgent) receiveVote(w http.ResponseWriter, r *http.Request
ballots
[
i
]
=
k
i
++
}
if
!
contains
[
[]
rad
.
Ballot
,
rad
.
Ballot
](
ballots
,
voteBallot
)
{
if
!
contains
[
rad
.
Ballot
](
ballots
,
voteBallot
)
{
w
.
WriteHeader
(
http
.
StatusBadRequest
)
msg
:=
fmt
.
Sprintf
(
"The ballot '%s' does not exist"
,
scrutin
)
w
.
Write
([]
byte
(
msg
))
...
...
@@ -90,15 +102,14 @@ func (rsa *BallotServerAgent) receiveVote(w http.ResponseWriter, r *http.Request
}
// Register the vote
ballot
.
profile
=
append
(
ballot
.
profile
,
intToAlt
(
req
.
Prefs
))
if
len
(
req
.
Options
)
!=
0
{
ballot
.
options
=
append
(
ballot
.
options
,
req
.
Options
)
}
// On elève l'agent de la liste des agents votants
for
i
,
agt
:=
range
ballot
.
votersId
{
if
agt
==
req
.
AgentID
{
ballot
.
votersId
[
i
]
=
ballot
.
votersId
[
len
(
ballot
.
votersId
)
-
1
]
ballot
.
votersId
=
ballot
.
votersId
[
:
len
(
ballot
.
votersId
)
-
1
]
}
rsa
.
ballots
[
voteBallot
]
=
BallotInfo
{
profile
:
append
(
ballot
.
profile
,
intToAlt
(
req
.
Prefs
)),
// add preferences to profile
options
:
append
(
ballot
.
options
,
req
.
Options
),
// add options to all options
votersId
:
removeFromSlice
(
rsa
.
ballots
[
voteBallot
]
.
votersId
,
req
.
AgentID
),
// remove voter from the list of voters
nbAlts
:
rsa
.
ballots
[
voteBallot
]
.
nbAlts
,
isOpen
:
true
,
results
:
rad
.
ResultResponse
{},
}
fmt
.
Println
(
rsa
.
ballots
[
voteBallot
])
}
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