def post(self): data = Section.parser.parse_args() section = SectionModel(**data) try: section.save_to_db() except: return {"message": "An error occurred inserting the item."}, 500 return section.json(), 201
def post(self, name): if SectionModel.find_by_name(name): return { 'message': "A section with name '{}' already exists.".format(name) }, 400 section = SectionModel(name) try: section.save_to_db() except: return {"message": "An error occurred creating the section."}, 500 return section.json(), 201
def get(self, name): section = SectionModel.find_by_name(name) if section: return section.json() return {'message': 'Store not found'}, 404
def delete(self, name): section = SectionModel.find_by_name(name) if section: section.delete_from_db() return {'message': 'Section deleted'}
def delete(self): SectionModel.delete_all() return {'message': 'All sections deleted'}
def delete(self, section_id): section = SectionModel.find_by_id(section_id) if section: section.delete_from_db() return {'message': 'Section deleted'}
def put(self, section_id): data = Section.parser.parse_args() section = SectionModel.find_by_id(section_id) if section is None: section = SectionModel(**data) else: section.chapter_id = data['chapter_id'] section.section_name = data['section_name'] section.section_description = data['section_description'] section.section_order = data['section_order'] section.section_update = datetime.now() section.save_to_db() return section.json()
def get(self, section_id): section = SectionModel.find_by_id(section_id) if section: return section.json() return {'message': 'Section not found'}, 404