def getLocationByIds(self): """Returns JSON object of locations""" data = request.get_json(force=True) locations = [] for x in data: location = Location.findLocationById(x) locations.append(location) return list(map(lambda x: x.json(), locations))
def removeLocation(self, id): """Returns JSON object of deleted location""" location = Location.findLocationById(id) if location: location.delete() return {"message": "The location with id '{}' is deleted!".format(id)} else: return "The Location does not exist!"
def addLocation(self, id): """Returns JSON object of the created location""" try: data = LocationService.parser.parse_args() location = Location.findLocationById(id) if location: return "The location already exists!" else: location = Location(id, data["code"], data["description"], data["x_coor"], data["y_coor"], data["waterschap_id"], data["watertype_id"], data["watertype_krw_id"]) location.save() return location.json() except exc.IntegrityError: return "The code already exists!"
def getLocation(self, id): """Returns JSON object of a location""" location = Location.findLocationById(id) if location: return location.json(), 201 return {"message": "The location is not found in the database."}, 404