def tearDown(self): #delete all from users PlaceBook.delete().execute() Place.delete().execute() User.delete().execute() City.delete().execute() State.delete().execute()
def setUp(self): #connect to db and delete everyone in the users table PlaceBook.delete().execute() Place.delete().execute() User.delete().execute() City.delete().execute() State.delete().execute()
def delete_place(place_id): """ Delete place with id as place_id """ try: place = Place.get(Place.id == place_id) except Exception: return {'code': 404, 'msg': 'Place not found'}, 404 delete_place = Place.delete().where(Place.id == place_id) delete_place.execute() response = {} response['code'] = 200 response['msg'] = "Place was deleted successfully" return response, 200
def delete_place(place_id): """ Delete the given place Deletes the given place in the database. --- tags: - Place parameters: - in: path name: place_id type: integer required: True description: ID of the place responses: 200: description: Place deleted successfully schema: $ref: '#/definitions/delete_amenity_delete_delete_200' 404: description: Place was not found 500: description: Request could not be processed """ try: ''' Check if place_id exists ''' query = Place.select().where(Place.id == place_id) if not query.exists(): raise LookupError('place_id') ''' Delete the given place ''' delete_place = Place.delete().where(Place.id == place_id) delete_place.execute() response = {} response['code'] = 200 response['msg'] = "Place was deleted" return response, 200 except LookupError as e: abort(404) except Exception as e: abort(505)
def handle_place_id(place_id): '''Select the place with the id from the database and store as the variable `place`. Return that place's hash with a GET request method. Update the attributes, excepting `owner` and `city` of the place with PUT request method. Remove the the place with this id from the database with a DELETE request method. Will not set attribute passed as `updated_at`, `created_at`, `owner`, or `city`. Keyword arguments: place_id: The id of the place. ''' try: place = Place.select().where(Place.id == place_id).get() except Place.DoesNotExist: raise Exception("There is no place with this id.") if request.method == 'GET': return jsonify(place.to_dict()), 200 elif request.method == 'PUT': params = request.values for key in params: if key == 'owner' or key == 'city': return jsonify(msg="You may not update the %s." % key), 409 if key == 'updated_at' or key == 'created_at': continue else: setattr(place, key, params.get(key)) place.save() return jsonify(msg="Place information updated successfully."), 200 elif request.method == 'DELETE': try: place = Place.delete().where(Place.id == place_id) except Place.DoesNotExist: raise Exception("There is no place with this id.") place.execute() return jsonify(msg="Place deleted successfully."), 200
def tearDown(self): #delete all from places Place.delete().execute() User.delete().execute() City.delete().execute() State.delete().execute()