From abb3d9c8304be5d1a52e8c4b54a76853ffc50dca Mon Sep 17 00:00:00 2001 From: Magnus-SmariSma <20734986-Magnus-SmariSma@users.noreply.replit.com> Date: Thu, 20 Mar 2025 22:21:20 +0000 Subject: [PATCH] Add IUCN Red List API integration to retrieve species information, threats, habitats, and conservation measures. Replit-Commit-Author: Agent Replit-Commit-Session-Id: e931b5ab-041b-42e7-baf1-50017869cef6 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/e19c6a51-7e4c-4bb8-a6a6-46dc00f0ec99/7e2db8b2-2763-45e5-8b1d-42fa047b7bb8.jpg --- client/src/lib/api.ts | 119 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 118 insertions(+), 1 deletion(-) diff --git a/client/src/lib/api.ts b/client/src/lib/api.ts index 27ba000..a0c74b6 100644 --- a/client/src/lib/api.ts +++ b/client/src/lib/api.ts @@ -93,6 +93,66 @@ export interface Reference { year: number; } +export interface IucnSpeciesResult { + taxonid: number; + scientific_name: string; + kingdom: string; + phylum: string; + class: string; + order: string; + family: string; + genus: string; + main_common_name: string; + authority: string; + published_year: number; + category: string; + assessment_date: string; + criteria: string; + population_trend: string; + marine_system: boolean; + freshwater_system: boolean; + terrestrial_system: boolean; +} + +export interface IucnSpeciesResponse { + result: IucnSpeciesResult[]; +} + +export interface IucnThreat { + code: string; + title: string; + timing: string; + scope: string; + severity: string; + score: string; +} + +export interface IucnThreatsResponse { + result: IucnThreat[]; +} + +export interface IucnHabitat { + code: string; + habitat: string; + suitability: string; + season: string; + majorimportance: string; +} + +export interface IucnHabitatsResponse { + result: IucnHabitat[]; +} + +export interface IucnMeasure { + code: string; + title: string; + year: number; +} + +export interface IucnMeasuresResponse { + result: IucnMeasure[]; +} + // API client for interacting with our backend export const apiClient = { // Token management @@ -168,7 +228,7 @@ export const apiClient = { // Get all saved species async getSavedSpecies(): Promise> { try { - const response = await axios.get>("/api/species"); + const response = await axios.get<{success: boolean; species: Species[]}>("/api/species"); return { success: true, data: response.data.species @@ -194,5 +254,62 @@ export const apiClient = { message: error.response?.data?.message || "Failed to retrieve recent searches" }; } + }, + + // IUCN Red List API methods + async getIucnSpeciesByName(scientificName: string): Promise> { + try { + const response = await axios.get>("/api/iucn/species", { + params: { name: scientificName } + }); + return response.data; + } catch (error: any) { + return { + success: false, + message: error.response?.data?.message || "Failed to retrieve IUCN species data" + }; + } + }, + + async getIucnThreats(scientificName: string): Promise> { + try { + const response = await axios.get>("/api/iucn/threats", { + params: { name: scientificName } + }); + return response.data; + } catch (error: any) { + return { + success: false, + message: error.response?.data?.message || "Failed to retrieve IUCN threats data" + }; + } + }, + + async getIucnHabitats(scientificName: string): Promise> { + try { + const response = await axios.get>("/api/iucn/habitats", { + params: { name: scientificName } + }); + return response.data; + } catch (error: any) { + return { + success: false, + message: error.response?.data?.message || "Failed to retrieve IUCN habitats data" + }; + } + }, + + async getIucnMeasures(scientificName: string): Promise> { + try { + const response = await axios.get>("/api/iucn/measures", { + params: { name: scientificName } + }); + return response.data; + } catch (error: any) { + return { + success: false, + message: error.response?.data?.message || "Failed to retrieve IUCN conservation measures data" + }; + } } };