def get_planet_by_name(self, name: str) -> list: query = {"name": {"$regex": name, "$options": "i"}} print(query) logging.info("[GET PLANETS BY NAME]: query %s" % query) planets = self.mongo_client.planets_collection.find(query) planets = list(planets) return [Planet.from_dict(planet) for planet in planets]
def build_insert_planet(planet: dict): logging.info("[BUILDER_INSERT_PLANET]: Insert Planet") if "name" in planet and "climate" in planet and "terrain" in planet: if type(planet["climate"]) == list and type(planet["terrain"]) == list: logging.info("[BUILDER_INSERT_PLANET]: Planet Valid") planet = Planet.from_dict(planet) inserted_id = PlanetRepository().insert(planet.to_dict()) logging.info("[BUILDER_INSERT_PLANET]: Planet %s inserted" % inserted_id) message = "Planeta criado com sucesso id: %s" % inserted_id resp = {"message": message} return resp logging.info("[BUILDER_INSERT_PLANET]: Planet missing required params") return 400
def get_planet_list(self) -> list: planets = self.mongo_client.planets_collection.find() return [Planet.from_dict(planet) for planet in planets]
def get_planet_by_id(self, id: str) -> Planet: adict = self.mongo_client.planets_collection.find_one({"_id": id}) if adict is not None: planet = Planet.from_dict(adict) return planet