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
a95d2300
Commit
a95d2300
authored
4 years ago
by
Josef Olsson
Browse files
Options
Downloads
Patches
Plain Diff
Commented component API
parent
47e82eac
No related branches found
No related tags found
1 merge request
!130
Resolve "Comment apis"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/app/apis/components.py
+38
-18
38 additions, 18 deletions
server/app/apis/components.py
with
38 additions
and
18 deletions
server/app/apis/components.py
+
38
−
18
View file @
a95d2300
"""
All API calls concerning competitions.
Default route: /api/competitions/<competition_id>/slides/<slide_id>/components
"""
import
app.core.http_codes
as
codes
import
app.database.controller
as
dbc
from
app.apis
import
item_response
,
list_response
,
protect_route
from
app.core.dto
import
ComponentDTO
from
flask_restx
import
Resource
from
flask_restx
import
reqparse
from
app.core.parsers
import
sentinel
from
flask_restx
import
Resource
,
reqparse
api
=
ComponentDTO
.
api
schema
=
ComponentDTO
.
schema
...
...
@@ -31,16 +35,39 @@ component_parser_edit.add_argument("media_id", type=int, default=sentinel, locat
component_parser_edit
.
add_argument
(
"
question_id
"
,
type
=
int
,
default
=
sentinel
,
location
=
"
json
"
)
@api.route
(
""
)
@api.param
(
"
competition_id, slide_id
"
)
class
ComponentList
(
Resource
):
@protect_route
(
allowed_roles
=
[
"
*
"
],
allowed_views
=
[
"
*
"
])
def
get
(
self
,
competition_id
,
slide_id
):
"""
Gets all components in the specified slide and competition.
"""
items
=
dbc
.
get
.
component_list
(
competition_id
,
slide_id
)
return
list_response
(
list_schema
.
dump
(
items
))
@protect_route
(
allowed_roles
=
[
"
*
"
])
def
post
(
self
,
competition_id
,
slide_id
):
"""
Posts a new component to the specified slide.
"""
args
=
component_parser_add
.
parse_args
()
item
=
dbc
.
add
.
component
(
slide_id
=
slide_id
,
**
args
)
return
item_response
(
schema
.
dump
(
item
))
@api.route
(
"
/<component_id>
"
)
@api.param
(
"
competition_id, slide_id, component_id
"
)
class
ComponentByID
(
Resource
):
@protect_route
(
allowed_roles
=
[
"
*
"
],
allowed_views
=
[
"
*
"
])
def
get
(
self
,
competition_id
,
slide_id
,
component_id
):
"""
Gets the specified component.
"""
item
=
dbc
.
get
.
component
(
competition_id
,
slide_id
,
component_id
)
return
item_response
(
schema
.
dump
(
item
))
@protect_route
(
allowed_roles
=
[
"
*
"
])
def
put
(
self
,
competition_id
,
slide_id
,
component_id
):
"""
Edits the specified component with the provided arguments.
"""
args
=
component_parser_edit
.
parse_args
(
strict
=
True
)
item
=
dbc
.
get
.
component
(
competition_id
,
slide_id
,
component_id
)
args_without_sentinel
=
{
key
:
value
for
key
,
value
in
args
.
items
()
if
value
is
not
sentinel
}
...
...
@@ -49,6 +76,8 @@ class ComponentByID(Resource):
@protect_route
(
allowed_roles
=
[
"
*
"
])
def
delete
(
self
,
competition_id
,
slide_id
,
component_id
):
"""
Deletes the specified component.
"""
item
=
dbc
.
get
.
component
(
competition_id
,
slide_id
,
component_id
)
dbc
.
delete
.
component
(
item
)
return
{},
codes
.
NO_CONTENT
...
...
@@ -59,21 +88,12 @@ class ComponentByID(Resource):
class
ComponentList
(
Resource
):
@protect_route
(
allowed_roles
=
[
"
*
"
])
def
post
(
self
,
competition_id
,
slide_id
,
component_id
,
view_type_id
):
item_component
=
dbc
.
get
.
component
(
competition_id
,
slide_id
,
component_id
)
item
=
dbc
.
copy
.
component
(
item_component
,
slide_id
,
view_type_id
)
return
item_response
(
schema
.
dump
(
item
))
@api.route
(
""
)
@api.param
(
"
competition_id, slide_id
"
)
class
ComponentList
(
Resource
):
@protect_route
(
allowed_roles
=
[
"
*
"
],
allowed_views
=
[
"
*
"
])
def
get
(
self
,
competition_id
,
slide_id
):
items
=
dbc
.
get
.
component_list
(
competition_id
,
slide_id
)
return
list_response
(
list_schema
.
dump
(
items
))
"""
Creates a deep copy of the specified component.
"""
@protect_route
(
allowed_roles
=
[
"
*
"
])
def
post
(
self
,
competition_id
,
slide_id
):
args
=
component_parser_add
.
parse_args
()
item
=
dbc
.
add
.
component
(
slide_id
=
slide_id
,
**
args
)
item_component
=
dbc
.
get
.
component
(
competition_id
,
slide_id
,
component_id
,
)
item
=
dbc
.
copy
.
component
(
item_component
,
slide_id
,
view_type_id
)
return
item_response
(
schema
.
dump
(
item
))
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