Esempio n. 1
0
    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
Esempio n. 2
0
    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
Esempio n. 3
0
 def get(self, name):
     section = SectionModel.find_by_name(name)
     if section:
         return section.json()
     return {'message': 'Store not found'}, 404
Esempio n. 4
0
    def delete(self, name):
        section = SectionModel.find_by_name(name)
        if section:
            section.delete_from_db()

        return {'message': 'Section deleted'}
Esempio n. 5
0
 def delete(self):
     SectionModel.delete_all()        
     return {'message': 'All sections deleted'}
Esempio n. 6
0
    def delete(self, section_id):
        section = SectionModel.find_by_id(section_id)
        if section:
            section.delete_from_db()

        return {'message': 'Section deleted'}        
Esempio n. 7
0
    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()      
Esempio n. 8
0
 def get(self, section_id):
     section = SectionModel.find_by_id(section_id)
     if section:
         return section.json()
     return {'message': 'Section not found'}, 404