Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
13th
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package 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
13th
13th
Commits
3723bd1f
Commit
3723bd1f
authored
2 years ago
by
radek
Browse files
Options
Downloads
Patches
Plain Diff
minor refactoring
parent
64809818
No related branches found
No related tags found
No related merge requests found
Pipeline
#15452
passed
2 years ago
Stage: build
Stage: test
Stage: staging
Stage: smoketest
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/tjts5901/backend/item_api.py
+1
-23
1 addition, 23 deletions
src/tjts5901/backend/item_api.py
src/tjts5901/views.py
+26
-2
26 additions, 2 deletions
src/tjts5901/views.py
with
27 additions
and
25 deletions
src/tjts5901/backend/item_api.py
+
1
−
23
View file @
3723bd1f
...
...
@@ -78,26 +78,4 @@ class AuctionItem (Resource):
#json.dump
#added_item = jsonify(item.serialize())
added_item
=
json
.
dumps
(
item
.
serialize
(),
default
=
str
)
return
{
'
data
'
:
added_item
},
201
def
backend_get
(
item_id
=
None
):
"""
Analogue of GET method for backend use only.
Args:
id (str, optional): id for specif item, if it is not provided it will return all items. Defaults to None.
Returns:
list or dict: representation of item objects type depends on if item_id is provided or not.
"""
item
=
items
.
Item
()
if
not
item_id
:
logger
.
info
(
"
retriving all items! (backend only)
"
)
query_result
=
item
.
get_all
()
item_from_db
=
[
item_from_db
for
item_from_db
in
query_result
]
return
item_from_db
logger
.
info
(
f
"
Trying to retrive a item with id:
{
id
}
(backend only)
"
)
try
:
return
item
.
get_item
(
item_id
)
except
ItemNotFound
as
err
:
return
err
return
{
'
data
'
:
added_item
},
201
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/tjts5901/views.py
+
26
−
2
View file @
3723bd1f
...
...
@@ -2,6 +2,7 @@
Basic views for Application
===========================
"""
import
logging
from
flask
import
Blueprint
,
render_template
,
send_from_directory
,
redirect
...
...
@@ -11,11 +12,12 @@ from flask_jwt_extended import (
#login info handling decorators
from
tjts5901.backend.logincookies
import
logged_in
,
admin_logged_in
from
tjts5901.backend.models.items
import
Item
,
ItemNotFound
#Get item data from db
import
tjts5901.backend.item_api
as
items
logger
=
logging
.
getLogger
(
__name__
)
# Main blueprint.
bp
=
Blueprint
(
'
views
'
,
__name__
)
...
...
@@ -47,7 +49,7 @@ def bidding(item_id) -> str:
"""
#Get requested auction data
a
=
items
.
AuctionItem
.
backend_get
(
item_id
)
a
=
backend_get
(
item_id
)
print
(
"
Item found
"
,
a
)
if
a
==
None
:
#redirect if item not found
...
...
@@ -74,3 +76,25 @@ def terms():
Maybe more precise terms would be useful
"""
return
"
Don
'
t misuse this service or do anything illegal
"
def
backend_get
(
item_id
=
None
):
"""
Analogue of GET method for backend use only.
Args:
id (str, optional): id for specif item, if it is not provided it will return all items. Defaults to None.
Returns:
list or dict: representation of item objects type depends on if item_id is provided or not.
"""
item
=
Item
()
if
not
item_id
:
logger
.
info
(
"
retriving all items! (backend only)
"
)
query_result
=
item
.
get_all
()
item_from_db
=
[
item_from_db
for
item_from_db
in
query_result
]
return
item_from_db
logger
.
info
(
f
"
Trying to retrive a item with id:
{
id
}
(backend only)
"
)
try
:
return
item
.
get_item
(
item_id
)
except
ItemNotFound
as
err
:
return
err
\ No newline at end of file
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