def create_new(params): """ Create a new car :param params: :return: """ auto = Auto() auto.load_json(params) auto.generate_vin() id_ = database.insert_document(auto_collection, auto.serialize()) auto._id = str(id_) return auto.serialize()
def get_one(id_): """ Get one car :param id_: :return: """ db_data = database.find_document(auto_collection, {'_id': ObjectId(id_)}) if not db_data: raise exceptions.NotFound("Object not found") auto_obj = Auto() auto_obj.load_json(db_data) return auto_obj.serialize()
def get_all(params): """ Get all cars :param params: :return: """ autos = database.find_document(auto_collection, params, True) result = [] for auto in autos: auto_obj = Auto() auto_obj.load_json(auto) result.append(auto_obj.serialize()) return result