Esempio n. 1
0
 def post(self, location_id):
     if LocationModel.find_by_id(location_id):
         return {"msg": "Location already exist"}, 400
     data = self.parser.parse_args()
     new_loc = LocationModel(location_id, **data)
     new_loc.save_to_db()
     return new_loc.json(), 201
Esempio n. 2
0
    def put(self, location_id):
        data = self.parser.parse_args()

        location = LocationModel.find_by_id(location_id)

        if location is None:
            location = LocationModel(location_id, **data)

        else:
            location.location_name = data["location_name"]

        location.save_to_db()
        return location.json()
Esempio n. 3
0
 def delete(self, location_id):
     location = LocationModel.find_by_id(location_id)
     if location:
         location.delete_from_db()
         return {"msg": "Location Deleted"}, 200
     return {"msg": "Location Not Found"}, 404
Esempio n. 4
0
 def get(self, location_id):
     location = LocationModel.find_by_id(location_id)
     if location:
         return location.json(), 200
     return {"msg": "Location Not Found"}, 404