Skip to content

Commit

Permalink
Feat: Add GET all sections endpoint (#116)
Browse files Browse the repository at this point in the history
* add get all sections endpoint

* applied suggested changes

* added find prefix

Co-authored-by: Anna Bauza <[email protected]>
  • Loading branch information
Rahulm2310 and annabauza authored Mar 10, 2021
1 parent db3142d commit f2c6ff2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/api/controllers/section.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from flask_restplus import Namespace, Resource
from flask import request
from sqlalchemy.exc import SQLAlchemyError

from app.api.models.section import *
from app.api.validations.section import *
from app.api.dao.section_dao import SectionDAO
Expand Down Expand Up @@ -45,6 +44,11 @@ def post(self):
return {"message": f"Data cannot be persisted. Original error: {e}"}, 500
return map_to_dto(section), 201

def get(self):
sections = SectionDAO.find_all_sections()
result = list(map(lambda section: map_to_dto(section), sections))
return {"sections": result}, 200


@section_ns.route("/<int:id>")
class UpdateSection(Resource):
Expand Down
4 changes: 4 additions & 0 deletions app/api/dao/section_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def find_sections_by_ids(ids: List[int]) -> List["SectionModel"]:
"""
return SectionModel.query.filter(SectionModel.id.in_(ids))

@staticmethod
def find_all_sections():
return SectionModel.query.all()

@staticmethod
def update_section(section, **kwargs):
return section.update(**kwargs)
Expand Down

0 comments on commit f2c6ff2

Please sign in to comment.