Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
IA04 TP3
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
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
Mohamed Fall
IA04 TP3
Commits
b3f76e42
Commit
b3f76e42
authored
2 years ago
by
Antoine Kryus
Browse files
Options
Downloads
Patches
Plain Diff
add server functions, response and request types, utils function ranking to give ballot result
parent
e79d7a20
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ia04/agt/ballotagent/ballotAgent.go
+17
-17
17 additions, 17 deletions
ia04/agt/ballotagent/ballotAgent.go
with
17 additions
and
17 deletions
ia04/agt/ballotagent/ballotAgent.go
+
17
−
17
View file @
b3f76e42
...
...
@@ -126,6 +126,7 @@ func (rba *RestBallotAgent) doNewBallot(w http.ResponseWriter, r *http.Request)
return
}
// traitement de la requête
var
resp
ResponseNewBallot
...
...
@@ -141,27 +142,29 @@ func (rba *RestBallotAgent) doNewBallot(w http.ResponseWriter, r *http.Request)
rba
.
alts
[
i
]
=
Alternative
(
i
)
}
deadline
,
err
:=
time
.
Parse
(
"Mon Jan _2 15:04:05 MST 2006"
,
req
.
deadline
)
if
err
!=
nil
{
if
rba
.
rule
!=
"majority"
&&
rba
.
rule
!=
"approval"
&&
rba
.
rule
!=
"borda"
&&
rba
.
rule
!=
"copeland"
&&
rba
.
rule
!=
"condorcet"
{
w
.
WriteHeader
(
http
.
StatusNotImplemented
)
msg
:=
fmt
.
Sprintf
(
"
Deadlin
e
\"
'%s'
\"
is not i
n a correct format"
,
req
.
deadlin
e
)
r
.
Write
([]
byte
(
msg
))
msg
:=
fmt
.
Sprintf
(
"
501: vote rul
e
\"
'%s'
\"
is not i
mpemented in the system"
,
req
.
rul
e
)
w
.
Write
([]
byte
(
msg
))
return
}
time
.
AfterFunc
(
time
.
Until
(
deadline
),
closeVote
(
rba
))
// treat deadline
deadline
,
err
:=
time
.
Parse
(
"Mon Jan _2 15:04:05 MST 2006"
,
req
.
deadline
)
// Unixdate layout
if
err
!=
nil
{
w
.
WriteHeader
(
http
.
StatusBadRequest
)
msg
:=
fmt
.
Sprintf
(
"Deadline
\"
'%s'
\"
is not in a correct format"
,
req
.
deadline
)
w
.
Write
([]
byte
(
msg
))
return
}
// close vote after deadline
_
=
time
.
AfterFunc
(
time
.
Until
(
deadline
),
func
(){
rba
.
isOpen
=
false
})
w
.
WriteHeader
(
http
.
StatusOK
)
serial
,
_
:=
json
.
Marshal
(
resp
)
w
.
Write
(
serial
)
w
.
WriteHeader
(
http
.
StatusCreated
)
// 201
}
func
(
rba
*
RestBallotAgent
)
doVote
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
@@ -190,7 +193,7 @@ func (rba *RestBallotAgent) doVote(w http.ResponseWriter, r *http.Request) {
if
comsoc
.
CheckProfileAlternative
(
rba
.
pfl
,
req
.
Vote
)
!=
nil
{
w
.
WriteHeader
(
http
.
StatusNotImplemented
)
msg
:=
fmt
.
Sprintf
(
"Vote of voter '%s' is not correct"
,
req
.
ID
)
r
.
Write
([]
byte
(
msg
))
w
.
Write
([]
byte
(
msg
))
return
}
...
...
@@ -235,9 +238,6 @@ func (rba *RestBallotAgent) doResult(w http.ResponseWriter, r *http.Request) {
w
.
Write
(
serial
)
}
func
closeVote
(
rba
*
RestBallotAgent
)
{
rba
.
status
=
0
}
func
(
rba
*
RestBallotAgent
)
Start
()
{
// création du routeur
...
...
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