Exemple #1
0
def main(id_):
    """Get a single instrument from the database."""
    ins = api_models.InstrumentInDB.parse_obj(
        InstrumentModel.get(id_).attribute_values)
    photo_urls = generate_photo_urls(ins.photo) if ins.photo else None
    ins_out = api_models.InstrumentOut(**ins.dict(), photoUrls=photo_urls)
    return success(ins_out.dict())
def main(id_):
    """Delete an instrument"""
    item = InstrumentModel.get(id_)
    if getattr(item, "photo", None):
        delete_photos(item.photo)
    item.delete()
    return success("Delete successful", 204)
def full(new_instrument: api_models.Instrument, path_id):
    """Update a full record"""
    ins = InstrumentModel.get(path_id)
    for key, value in new_instrument.dict().items():
        setattr(ins, key, value)
    ins.save()
    ins_db = api_models.InstrumentInDB.parse_obj(ins.attribute_values)
    ins_out = api_models.InstrumentOut.parse_obj(ins_db)
    return success({"message": "Update Successful", "item": ins_out.dict()})
def photo(data, path_id):
    """Change or add a photo"""
    if not path_id:
        return failure("Record ID must be in url", 400)
    ins = InstrumentModel.get(path_id)
    if ins.photo:
        delete_photos(ins.photo)
    ins.photo = handle_photo(data["photoUrl"])
    ins.save()
    return success({"message": "Photo successfully updated"})