def update_drug(drug_id:int, drug: Drug ) -> JSONResponse: if not drugs.get(drug_id): error = {'error': DRUG_NOT_FOUND} return JSONResponse(error, 404) drug_id = drug.id drugs[drug_id] = drug return JSONResponse(Drug(drug), 201)
def get_movie(movie_id: int) -> JSONResponse: # R movie = movies.get(movie_id) if not movie: error = {'error': MOVIE_NOT_FOUND} return JSONResponse(error, 404) return JSONResponse(Movie(movie), 200)
def get_car(car_id: int) -> JSONResponse: car = cars.get(car_id) if not car: error = {'error': CAR_NOT_FOUND} return JSONResponse(error, status_code=404) return JSONResponse(Car(car), status_code=200)
def get_car(car_id: int) -> JSONResponse: car = cars.get(car_id) if not car: error = {'error': CAR_NOT_FOUND} return JSONResponse(error, 400) return JSONResponse(Car(car), 200)
def delete_employe(person_id: int) -> JSONResponse: p = persons.get(person_id) if not p: error = {'error': PERSON_NOT_FOUND} return JSONResponse(error, status_code=404) del (persons[person_id]) return JSONResponse({}, 204)
def update_movie(movie_id: int, movie: Movie) -> JSONResponse: if not movies.get(movie_id): error = {"error": MOVIE_NOT_FOUND} return JSONResponse(error, 404) movie.id = movie_id movies[movie_id] = movie return JSONResponse(Movie(movie), 200)
def delete_movie(movie_id: int) -> JSONResponse: if not movies.get(movie_id): error = {"error": MOVIE_NOT_FOUND} return JSONResponse(error, status_code=404) del movies[movie_id] return JSONResponse({}, status_code=204)
def get_project(project_id: int) -> JSONResponse: project = projects.get(project_id) if not project: error = {'error': PROJECT_NOT_FOUND} return JSONResponse(error, status_code=404) return JSONResponse(project, status_code=200)
def delete_project(project_id: int) -> JSONResponse: if not projects.get(project_id): error = {'error': PROJECT_NOT_FOUND} return JSONResponse(error, status_code=404) del projects[project_id] return JSONResponse({}, status_code=204)
def delete_plant(plant_id: int) -> JSONResponse: if plant_id not in plants: error = {"error": NOT_FOUND.format(plant_id)} return JSONResponse(error, status_code=404) del plants[plant_id] return JSONResponse({}, status_code=204)
def get_sh(sh_id: int) -> JSONResponse: sh = superheros.get(str(sh_id)) if not sh: error = {'error': SUPER_HERO_NOT_FOUND} return JSONResponse(error, status_code=404) return JSONResponse(SuperHero(sh), status_code=200)
def delete_animal(animal_id: int) -> JSONResponse: if not animals.get(animal_id): error = {'error': ANIMAL_NOT_FOUND} return JSONResponse(error, status_code=404) del animals[animal_id] return JSONResponse({}, status_code=204)
def get_animal(animal_id: int) -> JSONResponse: animal = animals.get(animal_id) if not animal: error = {'error': ANIMAL_NOT_FOUND} return JSONResponse(error, status_code=404) return JSONResponse(Animal(animal), status_code=200)
def delete_drug(drug_id:int) -> JSONResponse: if not drugs.get(drug_id): error = {'error': DRUG_NOT_FOUND} return JSONResponse(error, 404) del drugs[drug_id] return JSONResponse({},204)
def create_prisoner(prisoner: Prisoner) -> JSONResponse: ''' Creates the specified prisoner ''' if data.get(prisoner.username): return JSONResponse({'error': 'User already exists!'}, 400) data[prisoner.username] = prisoner return JSONResponse(Prisoner(prisoner), 200)
def get_stock(symbol) -> JSONResponse: stock = stocks.get(symbol) if not stock: error = {'error': STOCK_NOT_FOUND} return JSONResponse(error, status_code=404) return JSONResponse(Stock(stock), status_code=200)
def remove_prisoner(username): ''' Deletes specified user ''' if not data.get(username): return JSONResponse({'error': NOT_FOUND}, 404) del data[username] return JSONResponse({}, 204)
def update_stock(symbol, stock: Stock) -> JSONResponse: if not stocks.get(symbol): error = {'error': STOCK_NOT_FOUND} return JSONResponse(error, status_code=404) stocks[stock.symbol] = stock return JSONResponse(Stock(stock), status_code=200)
def get_movie(movie_id: int) -> JSONResponse: movie = movies.get(movie_id) if not movie: error = {"error": MOVIE_NOT_FOUND} return JSONResponse(error, status_code=404) return JSONResponse(Movie(movie), status_code=200)
def delete_stock(symbol) -> JSONResponse: if not stocks.get(symbol): error = {'error': STOCK_NOT_FOUND} return JSONResponse(error, status_code=404) del stocks[symbol] return JSONResponse({}, status_code=204)
def create_question(question): return JSONResponse(question, status_code=400) question_id = max(questions.keys()) + 1 question.id = question_id question.created = datetime.now() questions[question_id] = question return JSONResponse(Question(question), status_code=201)
def get_contact(email: str) -> JSONResponse: contact = contacts.get(email) if not contact: error = {'error': CONTACT_NOT_FOUND} return JSONResponse(error, status_code=404) details = contacts[email] return JSONResponse(details, status_code=200)
def update_car(car_id: int, car: Car) -> JSONResponse: if not cars.get(car_id): error = {'error': CAR_NOT_FOUND} return JSONResponse(error, 404) car.id = car_id cars[car_id] = car return JSONResponse(Car(car), 200)
def edit_contact(email: str, update_contact: Contact) -> JSONResponse: contact = contacts.get(email) if not contact: error = {'error': CONTACT_NOT_FOUND} return JSONResponse(error, 404) contacts[email] = update_contact return JSONResponse(update_contact, status_code=200)
def update_job(job_id: int, job: Job) -> JSONResponse: if not jobs.get(job_id): error = {'error' : JOB_NOT_FOUND} return JSONResponse(Job(job), status_code=404) job.id = job_id jobs[job_id] = job return JSONResponse(Job(job), status_code=200)
def delete_contact(email: str) -> JSONResponse: contact = contacts.get(email) if not contact: error = {'error': CONTACT_NOT_FOUND} return JSONResponse(error, status_code=404) deleted_contact = contacts.pop(email) return JSONResponse(deleted_contact, status_code=204)
def delete_movie(movie_id: int): # D if not movies.get(movie_id): error = {'error': MOVIE_NOT_FOUND} return JSONResponse(error, 404) del movies[movie_id] return JSONResponse({}, 204)
def delete_business(b_id: int) -> JSONResponse: if not businesses.get(b_id): error = {'error': BUSINESS_NOT_FOUND} return JSONResponse(error, status_code=404) del businesses[b_id] return JSONResponse({}, status_code=204)
def delete_car(car_id: int) -> JSONResponse: if not cars.get(car_id): error = {'error': CAR_NOT_FOUND} return JSONResponse(error, status_code=404) del cars[car_id] return JSONResponse({}, status_code=204)
def delete_car(car_id: int) -> JSONResponse: if not cars.get(car_id): error = {'error': CAR_NOT_FOUND} return JSONResponse(error, status_code=404) # code 404, cannot be found del cars[car_id] return JSONResponse({}, status_code=204) # code 204, content not available