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
This commit is contained in:
@ -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<ApiResponse<Species[]>> {
|
||||
try {
|
||||
const response = await axios.get<ApiResponse<{ species: Species[] }>>("/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<ApiResponse<IucnSpeciesResponse>> {
|
||||
try {
|
||||
const response = await axios.get<ApiResponse<IucnSpeciesResponse>>("/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<ApiResponse<IucnThreatsResponse>> {
|
||||
try {
|
||||
const response = await axios.get<ApiResponse<IucnThreatsResponse>>("/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<ApiResponse<IucnHabitatsResponse>> {
|
||||
try {
|
||||
const response = await axios.get<ApiResponse<IucnHabitatsResponse>>("/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<ApiResponse<IucnMeasuresResponse>> {
|
||||
try {
|
||||
const response = await axios.get<ApiResponse<IucnMeasuresResponse>>("/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"
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user