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
7d059049
Commit
7d059049
authored
3 years ago
by
Josef Olsson
Browse files
Options
Downloads
Patches
Plain Diff
Comment media API
parent
da122cae
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/media.py
+15
-3
15 additions, 3 deletions
server/app/apis/media.py
with
15 additions
and
3 deletions
server/app/apis/media.py
+
15
−
3
View file @
7d059049
"""
All API calls concerning media.
Default route: /api/media
"""
import
app.core.files
as
files
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
MediaDTO
from
app.core.parsers
import
search_parser
from
app.core.parsers
import
search_parser
,
sentinel
from
app.database.models
import
Media
from
flask
import
request
from
flask_jwt_extended
import
get_jwt_identity
from
flask_restx
import
Resource
from
flask_uploads
import
UploadNotAllowed
from
sqlalchemy
import
exc
import
app.core.files
as
files
from
app.core.parsers
import
sentinel
api
=
MediaDTO
.
api
image_set
=
MediaDTO
.
image_set
...
...
@@ -25,12 +29,16 @@ media_parser_search.add_argument("filename", type=str, default=sentinel, locatio
class
ImageList
(
Resource
):
@protect_route
(
allowed_roles
=
[
"
*
"
])
def
get
(
self
):
"""
Gets a list of all images with the specified filename.
"""
args
=
media_parser_search
.
parse_args
(
strict
=
True
)
items
,
total
=
dbc
.
search
.
image
(
**
args
)
return
list_response
(
list_schema
.
dump
(
items
),
total
)
@protect_route
(
allowed_roles
=
[
"
*
"
])
def
post
(
self
):
"""
Posts the specified image.
"""
if
"
image
"
not
in
request
.
files
:
api
.
abort
(
codes
.
BAD_REQUEST
,
"
Missing image in request.files
"
)
try
:
...
...
@@ -51,11 +59,15 @@ class ImageList(Resource):
class
ImageList
(
Resource
):
@protect_route
(
allowed_roles
=
[
"
*
"
],
allowed_views
=
[
"
*
"
])
def
get
(
self
,
ID
):
"""
Gets the specified image.
"""
item
=
dbc
.
get
.
one
(
Media
,
ID
)
return
item_response
(
schema
.
dump
(
item
))
@protect_route
(
allowed_roles
=
[
"
*
"
])
def
delete
(
self
,
ID
):
"""
Deletes the specified image.
"""
item
=
dbc
.
get
.
one
(
Media
,
ID
)
try
:
files
.
delete_image_and_thumbnail
(
item
.
filename
)
...
...
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