Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ELC_elections
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
Container Registry
Model registry
Operate
Environments
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
gestion-des-assemblees
ELC_elections
Commits
fe014295
Commit
fe014295
authored
4 years ago
by
Alexis POYEN
Browse files
Options
Downloads
Patches
Plain Diff
Refactor : factorize code to get capturer and deskround
parent
c9a3870f
No related branches found
Branches containing commit
No related tags found
Loading
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
internal/models/capturerDeskRound.go
+17
-15
17 additions, 15 deletions
internal/models/capturerDeskRound.go
with
17 additions
and
15 deletions
internal/models/capturerDeskRound.go
+
17
−
15
View file @
fe014295
...
...
@@ -48,14 +48,9 @@ func (d *DataHandler) postCapturerDeskRound(w http.ResponseWriter, r *http.Reque
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
}
var
capturer
Capturer
if
err
:=
d
.
db
.
First
(
&
capturer
,
o
.
CapturerID
)
.
Error
;
err
!=
nil
{
http
.
Error
(
w
,
ErrorIDDoesNotExist
,
http
.
StatusNotFound
)
return
}
var
deskRound
DeskRound
if
err
:=
d
.
db
.
First
(
&
deskRound
,
o
.
DeskRoundID
)
.
Error
;
err
!=
nil
{
flag
,
capturer
,
deskRound
:=
d
.
checkCapturerAnd
DeskRound
(
o
)
if
!
flag
{
http
.
Error
(
w
,
ErrorIDDoesNotExist
,
http
.
StatusNotFound
)
return
}
...
...
@@ -72,18 +67,25 @@ func (d *DataHandler) deleteCapturerDeskRound(w http.ResponseWriter, r *http.Req
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
}
var
capturer
Capturer
if
err
:=
d
.
db
.
First
(
&
capturer
,
o
.
CapturerID
)
.
Error
;
err
!=
nil
{
http
.
Error
(
w
,
ErrorIDDoesNotExist
,
http
.
StatusNotFound
)
return
}
var
deskRound
DeskRound
if
err
:=
d
.
db
.
First
(
&
deskRound
,
o
.
DeskRoundID
)
.
Error
;
err
!=
nil
{
flag
,
capturer
,
deskRound
:=
d
.
checkCapturerAnd
DeskRound
(
o
)
if
!
flag
{
http
.
Error
(
w
,
ErrorIDDoesNotExist
,
http
.
StatusNotFound
)
return
}
d
.
db
.
Model
(
&
capturer
)
.
Association
(
"DeskRounds"
)
.
Delete
(
&
deskRound
)
json
.
NewEncoder
(
w
)
.
Encode
(
capturer
)
}
func
(
d
*
DataHandler
)
checkCapturerAndDeskRound
(
o
capturerDeskRound
)
(
bool
,
Capturer
,
DeskRound
)
{
var
capturer
Capturer
var
deskRound
DeskRound
if
err
:=
d
.
db
.
First
(
&
capturer
,
o
.
CapturerID
)
.
Error
;
err
!=
nil
{
return
false
,
capturer
,
deskRound
}
if
err
:=
d
.
db
.
First
(
&
deskRound
,
o
.
DeskRoundID
)
.
Error
;
err
!=
nil
{
return
false
,
capturer
,
deskRound
}
return
true
,
capturer
,
deskRound
}
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