Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
teknikattan-scoring-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
tddd96-grupp1
teknikattan-scoring-system
Commits
fc186393
Commit
fc186393
authored
3 years ago
by
Victor Löfgren
Browse files
Options
Downloads
Patches
Plain Diff
Add slide api
parent
be0494ff
No related branches found
No related tags found
1 merge request
!161
Resolve "replace-restx-with-smorest"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/app/apis/__init__.py
+2
-0
2 additions, 0 deletions
server/app/apis/__init__.py
server/app/apis/slides.py
+54
-51
54 additions, 51 deletions
server/app/apis/slides.py
with
56 additions
and
51 deletions
server/app/apis/__init__.py
+
2
−
0
View file @
fc186393
...
@@ -142,6 +142,7 @@ def init_api():
...
@@ -142,6 +142,7 @@ def init_api():
from
.competitions
import
blp
as
competitions_blp
from
.competitions
import
blp
as
competitions_blp
from
.media
import
blp
as
media_blp
from
.media
import
blp
as
media_blp
from
.misc
import
blp
as
misc_blp
from
.misc
import
blp
as
misc_blp
from
.slides
import
blp
as
slide_blp
from
.users
import
blp
as
user_blp
from
.users
import
blp
as
user_blp
flask_api
.
register_blueprint
(
user_blp
)
flask_api
.
register_blueprint
(
user_blp
)
...
@@ -149,3 +150,4 @@ def init_api():
...
@@ -149,3 +150,4 @@ def init_api():
flask_api
.
register_blueprint
(
competitions_blp
)
flask_api
.
register_blueprint
(
competitions_blp
)
flask_api
.
register_blueprint
(
misc_blp
)
flask_api
.
register_blueprint
(
misc_blp
)
flask_api
.
register_blueprint
(
media_blp
)
flask_api
.
register_blueprint
(
media_blp
)
flask_api
.
register_blueprint
(
slide_blp
)
This diff is collapsed.
Click to expand it.
server/app/apis/slides.py
+
54
−
51
View file @
fc186393
...
@@ -3,93 +3,96 @@ All API calls concerning question alternatives.
...
@@ -3,93 +3,96 @@ All API calls concerning question alternatives.
Default route: /api/competitions/<competition_id>/slides
Default route: /api/competitions/<competition_id>/slides
"""
"""
import
app.core.http_codes
as
codes
import
app.database.controller
as
dbc
import
app.database.controller
as
dbc
from
app.apis
import
item_response
,
list_response
,
protect_route
from
app.apis
import
protect_route
from
app.core.dto
import
SlideDTO
from
app.core
import
ma
from
app.core.parsers
import
sentinel
from
app.core.schemas
import
BaseSchema
,
SlideSchema
from
app.database
import
models
from
app.database.models
import
Competition
,
Slide
from
app.database.models
import
Competition
,
Slide
from
flask
_restx
import
Resource
,
reqparse
from
flask
.views
import
MethodView
from
flask_rest
x.errors
import
abort
from
flask_
smo
rest
import
Blueprint
,
abort
api
=
SlideDTO
.
api
from
.
import
http_codes
schema
=
SlideDTO
.
schema
list_schema
=
SlideDTO
.
list_schema
slide_parser_edit
=
reqparse
.
RequestParser
()
blp
=
Blueprint
(
slide_parser_edit
.
add_argument
(
"
order
"
,
type
=
int
,
default
=
sentinel
,
location
=
"
json
"
)
"
slide
"
,
slide_parser_edit
.
add_argument
(
"
title
"
,
type
=
str
,
default
=
sentinel
,
location
=
"
json
"
)
"
slide
"
,
slide_parser_edit
.
add_argument
(
"
timer
"
,
type
=
int
,
default
=
sentinel
,
location
=
"
json
"
)
url_prefix
=
"
/api/competitions/<competition_id>/slides
"
,
slide_parser_edit
.
add_argument
(
"
order
"
,
type
=
in
t
,
de
fault
=
sentinel
,
location
=
"
json
"
)
description
=
"
Adding, updat
in
g
, de
leting and searching for slide
"
,
slide_parser_edit
.
add_argument
(
"
background_image_id
"
,
default
=
sentinel
,
type
=
int
,
location
=
"
json
"
)
)
@api.route
(
""
)
class
SlideEditArgsSchema
(
BaseSchema
):
@api.param
(
"
competition_id
"
)
class
Meta
(
BaseSchema
.
Meta
):
class
SlidesList
(
Resource
):
model
=
models
.
Slide
order
=
ma
.
auto_field
(
required
=
False
)
title
=
ma
.
auto_field
(
required
=
False
)
timer
=
ma
.
auto_field
(
required
=
False
)
order
=
ma
.
auto_field
(
required
=
False
)
background_image_id
=
ma
.
auto_field
(
required
=
False
)
@blp.route
(
""
)
class
Slides
(
MethodView
):
@protect_route
(
allowed_roles
=
[
"
*
"
])
@protect_route
(
allowed_roles
=
[
"
*
"
])
@blp.response
(
http_codes
.
OK
,
SlideSchema
(
many
=
True
))
def
get
(
self
,
competition_id
):
def
get
(
self
,
competition_id
):
"""
Gets all slides from the specified competition.
"""
"""
Gets all slides from the specified competition.
"""
return
dbc
.
get
.
slide_list
(
competition_id
)
items
=
dbc
.
get
.
slide_list
(
competition_id
)
return
list_response
(
list_schema
.
dump
(
items
))
@protect_route
(
allowed_roles
=
[
"
*
"
])
@protect_route
(
allowed_roles
=
[
"
*
"
])
@blp.response
(
http_codes
.
OK
,
SlideSchema
)
@blp.alt_response
(
http_codes
.
CONFLICT
,
None
,
description
=
"
Can
'
t add slide
"
)
def
post
(
self
,
competition_id
):
def
post
(
self
,
competition_id
):
"""
Posts a new slide to the specified competition.
"""
"""
Posts a new slide to the specified competition.
"""
return
dbc
.
add
.
slide
(
competition_id
)
item_slide
=
dbc
.
add
.
slide
(
competition_id
)
return
item_response
(
schema
.
dump
(
item_slide
))
@blp.route
(
"
/<slide_id>
"
)
@api.route
(
"
/<slide_id>
"
)
class
Slides
(
MethodView
):
@api.param
(
"
competition_id, slide_id
"
)
class
Slides
(
Resource
):
@protect_route
(
allowed_roles
=
[
"
*
"
])
@protect_route
(
allowed_roles
=
[
"
*
"
])
@blp.response
(
http_codes
.
OK
,
SlideSchema
)
@blp.alt_response
(
http_codes
.
NOT_FOUND
,
None
)
def
get
(
self
,
competition_id
,
slide_id
):
def
get
(
self
,
competition_id
,
slide_id
):
"""
Gets the specified slide.
"""
"""
Gets the specified slide.
"""
return
dbc
.
get
.
slide
(
competition_id
,
slide_id
)
item_slide
=
dbc
.
get
.
slide
(
competition_id
,
slide_id
)
return
item_response
(
schema
.
dump
(
item_slide
))
@protect_route
(
allowed_roles
=
[
"
*
"
])
@protect_route
(
allowed_roles
=
[
"
*
"
])
def
put
(
self
,
competition_id
,
slide_id
):
@blp.arguments
(
SlideEditArgsSchema
)
@blp.response
(
http_codes
.
OK
,
SlideSchema
)
@blp.alt_response
(
http_codes
.
CONFLICT
,
None
,
description
=
"
Can
'
t edit slide
"
)
@blp.alt_response
(
http_codes
.
BAD_REQUEST
,
None
,
description
=
"
Can
'
t edit slide with the provided arguments
"
)
def
put
(
self
,
competition_id
,
slide_id
,
args
):
"""
Edits the specified slide using the provided arguments.
"""
"""
Edits the specified slide using the provided arguments.
"""
args
=
slide_parser_edit
.
parse_args
(
strict
=
True
)
item_slide
=
dbc
.
get
.
slide
(
competition_id
,
slide_id
)
item_slide
=
dbc
.
get
.
slide
(
competition_id
,
slide_id
)
new_order
=
args
.
pop
(
"
order
"
)
new_order
=
args
.
pop
(
"
order
"
)
if
new_order
is
not
senti
ne
l
and
item_slide
.
order
!=
new_order
:
if
new_order
is
not
No
ne
and
item_slide
.
order
!=
new_order
:
if
not
(
0
<=
new_order
<
dbc
.
utils
.
count
(
Slide
,
{
"
competition_id
"
:
competition_id
})):
if
not
(
0
<=
new_order
<
dbc
.
utils
.
count
(
Slide
,
{
"
competition_id
"
:
competition_id
})):
abort
(
codes
.
BAD_REQUEST
,
f
"
Cant change to invalid slide order
'
{
new_order
}
'"
)
abort
(
http_
codes
.
BAD_REQUEST
,
f
"
Cant change to invalid slide order
'
{
new_order
}
'"
)
item_competition
=
dbc
.
get
.
one
(
Competition
,
competition_id
)
item_competition
=
dbc
.
get
.
one
(
Competition
,
competition_id
)
dbc
.
utils
.
move_order
(
item_competition
.
slides
,
"
order
"
,
item_slide
.
order
,
new_order
)
dbc
.
utils
.
move_order
(
item_competition
.
slides
,
"
order
"
,
item_slide
.
order
,
new_order
)
item_slide
=
dbc
.
edit
.
default
(
item_slide
,
**
args
)
return
dbc
.
edit
.
default
(
item_slide
,
**
args
)
return
item_response
(
schema
.
dump
(
item_slide
))
@protect_route
(
allowed_roles
=
[
"
*
"
])
@protect_route
(
allowed_roles
=
[
"
*
"
])
@blp.response
(
http_codes
.
NO_CONTENT
,
None
)
@blp.alt_response
(
http_codes
.
NOT_FOUND
,
None
,
description
=
"
Slide not found
"
)
@blp.alt_response
(
http_codes
.
CONFLICT
,
None
,
description
=
"
Can
'
t delete slide
"
)
def
delete
(
self
,
competition_id
,
slide_id
):
def
delete
(
self
,
competition_id
,
slide_id
):
"""
Deletes the specified slide.
"""
"""
Deletes the specified slide.
"""
dbc
.
delete
.
slide
(
dbc
.
get
.
slide
(
competition_id
,
slide_id
))
item_slide
=
dbc
.
get
.
slide
(
competition_id
,
slide_id
)
return
None
dbc
.
delete
.
slide
(
item_slide
)
return
{},
codes
.
NO_CONTENT
@api.route
(
"
/<slide_id>/copy
"
)
@blp.route
(
"
/<slide_id>/copy
"
)
@api.param
(
"
competition_id,slide_id
"
)
class
SlideCopy
(
MethodView
):
class
SlideCopy
(
Resource
):
@protect_route
(
allowed_roles
=
[
"
*
"
])
@protect_route
(
allowed_roles
=
[
"
*
"
])
@blp.response
(
http_codes
.
OK
,
SlideSchema
)
@blp.alt_response
(
http_codes
.
NOT_FOUND
,
None
,
description
=
"
Can
'
t find slide
"
)
def
post
(
self
,
competition_id
,
slide_id
):
def
post
(
self
,
competition_id
,
slide_id
):
"""
Creates a deep copy of the specified slide.
"""
"""
Creates a deep copy of the specified slide.
"""
return
dbc
.
copy
.
slide
(
dbc
.
get
.
slide
(
competition_id
,
slide_id
))
item_slide
=
dbc
.
get
.
slide
(
competition_id
,
slide_id
)
item_slide_copy
=
dbc
.
copy
.
slide
(
item_slide
)
return
item_response
(
schema
.
dump
(
item_slide_copy
))
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