Exemple #1
0
    def post(cls, name: str):
        if StoreModel.find_by_name(name):
            return {"message": NAME_ALREADY_EXISTS.format(name)}, 400

        store = StoreModel(name=name)
        try:
            store.save_to_db()
        except:
            return {"message": ERROR_INSERTING}, 500

        return store_schema.dump(store), 201
Exemple #2
0
    def delete(cls, name: str):
        store = StoreModel.find_by_name(name)
        if store:
            store.delete_from_db()
            return {"message": STORE_DELETED}, 200

        return {"message": STORE_NOT_FOUND}, 404
Exemple #3
0
    def post(cls, name):
        if StoreModel.find_by_name(name):
            return (
                {
                    "message": NAME_ALREADY_EXISTS.format(name)
                },
                400,
            )

        store = StoreModel(name)
        try:
            store.save_to_db()
        except:
            return {"message": ERROR_CREATING}, 500

        return store.json(), 201
Exemple #4
0
 def get(cls):
     return {"stores": [x.json() for x in StoreModel.find_all()]}
Exemple #5
0
    def delete(cls, name):
        store = StoreModel.find_by_name(name)
        if store:
            store.delete_from_db()

        return {"message": STORE_DELETED}
Exemple #6
0
 def get(cls, name):
     store = StoreModel.find_by_name(name)
     if store:
         return store.json()
     return {"message": STORE_NOT_FOUND}, 404
Exemple #7
0
 def get(cls):
     return {"stores": store_list_schema.dump(StoreModel.find_all())}, 200
Exemple #8
0
 def get(cls, name: str):
     store = StoreModel.find_by_name(name)
     if store:
         return store_schema.dump(store), 200
     return {"message": STORE_NOT_FOUND}, 404