def get(self): """ASWP-API Species GET Returns: type[Response]: Flask JSON Response with list of Species """ species = [Specie.to_dict(s) for s in Specie.get_all()] species_safe = [{ "id": s["id"], "name": s["name"], "animals_count": Animal.get_count_by_specie(s["id"]) } for s in species] return jsonify(species=species_safe)
def get(self, specie_id): """ASWP-API Specie GET Args: specie_id (int): Specie ID Returns: type[Response]: Flask JSON Response with Specie data tuple: Tuple with error message and status code """ specie = Specie.get_by_id(specie_id) if specie: specie = Specie.to_dict(specie) else: return {"error": "Specie not found"}, 404 specie_animals = [ Animal.to_safe_dict(a) for a in Animal.get_all_by_specie(specie_id) ] specie["animals"] = specie_animals return jsonify(specie=specie)