def post(self): data = request.json validation_result = validate_section_data(data) if validation_result is not None: return validation_result title, category_title = data["title"], data["category"] existing_section = SectionDAO.find_section_by_title(title) if existing_section is not None: return SECTION_ALREADY_EXISTS, 400 try: section = SectionDAO.create_section(title) category = CategoryDAO.create_or_find_category(category_title) category.add_category_section(section) except SQLAlchemyError as e: return {"message": f"Data cannot be persisted. Original error: {e}"}, 500 return map_to_dto(section), 201
def get(self, id): category = CategoryDAO.find_category_by_id(id) if not category: return RESOURCE_NOT_FOUND, 404 sections = SectionDAO.find_sections_by_category(category) return map_to_dto_list(sections), 200