From c3cb24ea640c59fd1d751ed11b5cfa77b417defd Mon Sep 17 00:00:00 2001 From: Leandro Date: Wed, 24 Jan 2024 16:25:04 -0300 Subject: [PATCH] feat: helper functions --- lib/repository-metadata/index.ts | 60 ++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 lib/repository-metadata/index.ts diff --git a/lib/repository-metadata/index.ts b/lib/repository-metadata/index.ts new file mode 100644 index 0000000..1154d64 --- /dev/null +++ b/lib/repository-metadata/index.ts @@ -0,0 +1,60 @@ +import { FilterOption } from "@/types/filters"; + +export async function fetchInterests(): Promise { + const url = + "https://kudos-ink.github.io/repository-classification/interests.json"; + + try { + const response = await fetch(url); + + if (!response.ok) { + throw new Error(`Failed to fetch data. Status: ${response.status}`); + } + + const jsonData: { interests: FilterOption[] } = await response.json(); + const { interests } = jsonData; + return interests; + } catch (error) { + console.error("Error fetching data:", error); + throw new Error("Failed to fetch interests data"); + } +} + +export async function fetchLanguages(): Promise { + const url = + "https://kudos-ink.github.io/repository-classification/languages.json"; + + try { + const response = await fetch(url); + + if (!response.ok) { + throw new Error(`Failed to fetch data. Status: ${response.status}`); + } + + const languages: FilterOption[] = await response.json(); + return languages; + } catch (error) { + console.error("Error fetching data:", error); + throw new Error("Failed to fetch languages data"); + } +} + +export async function fetchRepositories(): Promise { + const url = + "https://kudos-ink.github.io/repository-classification/repository_full.json"; + + try { + const response = await fetch(url); + + if (!response.ok) { + throw new Error(`Failed to fetch data. Status: ${response.status}`); + } + + const jsonData: { repositories: FilterOption[] } = await response.json(); + const { repositories } = jsonData; + return repositories; + } catch (error) { + console.error("Error fetching data:", error); + throw new Error("Failed to fetch projects data"); + } +}