Skip to content
Snippets Groups Projects
Commit 5c128f38 authored by Josef Olsson's avatar Josef Olsson
Browse files

Add documentation for dbc.get

parent 95cb52fe
No related branches found
No related tags found
No related merge requests found
...@@ -25,7 +25,7 @@ class ComponentByID(Resource): ...@@ -25,7 +25,7 @@ class ComponentByID(Resource):
def put(self, CID, SOrder, component_id): def put(self, CID, SOrder, component_id):
args = component_parser.parse_args() args = component_parser.parse_args()
item = dbc.get.one(Component, component_id) item = dbc.get.one(Component, component_id)
item = dbc.edit.component(item,**args) item = dbc.edit.component(item, **args)
return item_response(schema.dump(item)) return item_response(schema.dump(item))
@jwt_required @jwt_required
......
...@@ -23,7 +23,7 @@ class TeamsList(Resource): ...@@ -23,7 +23,7 @@ class TeamsList(Resource):
@jwt_required @jwt_required
def post(self, CID): def post(self, CID):
args = team_parser.parse_args(strict=True) args = team_parser.parse_args(strict=True)
item_comp = dbc.get.one(Competition,CID) item_comp = dbc.get.one(Competition, CID)
item_team = dbc.add.team(args["name"], item_comp) item_team = dbc.add.team(args["name"], item_comp)
return item_response(schema.dump(item_team)) return item_response(schema.dump(item_team))
......
"""
This file contains functionality to get data from the database.
"""
from app.core import db from app.core import db
from app.database.models import (City, Code, Competition, Component, from app.database.models import (
ComponentType, MediaType, Question, City,
QuestionType, Role, Slide, Team, User, Code,
ViewType) Competition,
Component,
ComponentType,
MediaType,
Question,
QuestionType,
Role,
Slide,
Team,
User,
ViewType,
)
def all(db_type): def all(db_type):
""" Gets all elements in the provided table. """
return db_type.query.all() return db_type.query.all()
def one(db_type, id, required=True, error_msg=None): def one(db_type, id, required=True, error_msg=None):
""" Gets the element in the table that has the same id. """
return db_type.query.filter(db_type.id == id).first_extended(required, error_msg) return db_type.query.filter(db_type.id == id).first_extended(required, error_msg)
def user_exists(email): def user_exists(email):
""" Checks if an user has that email. """
return User.query.filter(User.email == email).count() > 0 return User.query.filter(User.email == email).count() > 0
def code_by_code(code): def code_by_code(code):
""" Gets the code object associated with the provided code. """
return Code.query.filter(Code.code == code.upper()).first() return Code.query.filter(Code.code == code.upper()).first()
def user(UID, required=True, error_msg=None): def user(UID, required=True, error_msg=None):
""" Gets the user object associated with the provided id. """
return User.query.filter(User.id == UID).first_extended(required, error_msg) return User.query.filter(User.id == UID).first_extended(required, error_msg)
def user_by_email(email, required=True, error_msg=None): def user_by_email(email, required=True, error_msg=None):
""" Gets the user object associated with the provided email. """
return User.query.filter(User.email == email).first_extended(required, error_msg) return User.query.filter(User.email == email).first_extended(required, error_msg)
def slide(CID, SOrder, required=True, error_msg=None): def slide(CID, SOrder, required=True, error_msg=None):
""" Gets the slide object associated with the provided id and order. """
filters = (Slide.competition_id == CID) & (Slide.order == SOrder) filters = (Slide.competition_id == CID) & (Slide.order == SOrder)
return Slide.query.filter(filters).first_extended(required, error_msg) return Slide.query.filter(filters).first_extended(required, error_msg)
def team(CID, TID, required=True, error_msg=None): def team(CID, TID, required=True, error_msg=None):
""" Gets the team object associated with the provided id and competition id. """
return Team.query.filter((Team.competition_id == CID) & (Team.id == TID)).first_extended(required, error_msg) return Team.query.filter((Team.competition_id == CID) & (Team.id == TID)).first_extended(required, error_msg)
def question(CID, SOrder, QID, required=True, error_msg=None): def question(CID, SOrder, QID, required=True, error_msg=None):
""" Gets the question object associated with the provided id, slide order and competition id. """
join_filters = (Slide.competition_id == CID) & (Slide.order == SOrder) & (Slide.id == Question.slide_id) join_filters = (Slide.competition_id == CID) & (Slide.order == SOrder) & (Slide.id == Question.slide_id)
return Question.query.join(Slide, join_filters).filter(Question.id == QID).first_extended(required, error_msg) return Question.query.join(Slide, join_filters).filter(Question.id == QID).first_extended(required, error_msg)
def code_list(competition_id): def code_list(competition_id):
""" Gets a list of all code objects associated with a the provided competition. """
team_view_id = 1 team_view_id = 1
join_filters = (Code.view_type_id == team_view_id) & (Team.id == Code.pointer) join_filters = (Code.view_type_id == team_view_id) & (Team.id == Code.pointer)
filters = ((Code.view_type_id != team_view_id) & (Code.pointer == competition_id))( filters = ((Code.view_type_id != team_view_id) & (Code.pointer == competition_id))(
...@@ -53,22 +88,32 @@ def code_list(competition_id): ...@@ -53,22 +88,32 @@ def code_list(competition_id):
def question_list(CID): def question_list(CID):
""" Gets a list of all question objects associated with a the provided competition. """
join_filters = (Slide.competition_id == CID) & (Slide.id == Question.slide_id) join_filters = (Slide.competition_id == CID) & (Slide.id == Question.slide_id)
return Question.query.join(Slide, join_filters).all() return Question.query.join(Slide, join_filters).all()
def component_list(CID, SOrder): def component_list(CID, SOrder):
""" Gets a list of all component objects associated with a the provided competition id and slide order. """
join_filters = (Slide.competition_id == CID) & (Slide.order == SOrder) & (Component.slide_id == Slide.id) join_filters = (Slide.competition_id == CID) & (Slide.order == SOrder) & (Component.slide_id == Slide.id)
return Component.query.join(Slide, join_filters).all() return Component.query.join(Slide, join_filters).all()
def team_list(CID): def team_list(CID):
""" Gets a list of all team objects associated with a the provided competition. """
return Team.query.filter(Team.competition_id == CID).all() return Team.query.filter(Team.competition_id == CID).all()
def slide_list(CID): def slide_list(CID):
""" Gets a list of all slide objects associated with a the provided competition. """
return Slide.query.filter(Slide.competition_id == CID).all() return Slide.query.filter(Slide.competition_id == CID).all()
def slide_count(CID): def slide_count(CID):
""" Gets the number of slides in the provided competition. """
return Slide.query.filter(Slide.competition_id == CID).count() return Slide.query.filter(Slide.competition_id == CID).count()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment