-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5837706
commit 87005af
Showing
29 changed files
with
282 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
import { sanitizeUrl } from "@/utils/url"; | ||
import { prepareUrl, sanitizeUrl } from "@/utils/url"; | ||
import APIClient from "@/api/client"; | ||
|
||
const CORE_API_URL = sanitizeUrl(process.env.NEXT_PUBLIC_API_URL || ""); | ||
|
||
export async function fetchFromApi<T>( | ||
endpoint: string, | ||
queryParams: Record<string, any>, | ||
tag?: string, | ||
): Promise<T> { | ||
try { | ||
const url = prepareUrl(endpoint, queryParams); | ||
const config = tag ? { tag } : { noStoreCache: true }; | ||
return await coreApiClient.get<T>(url, config); | ||
} catch (error) { | ||
console.error(`Error fetching data from ${endpoint}:`, error); | ||
throw error; | ||
} | ||
} | ||
|
||
export const coreApiClient = new APIClient(CORE_API_URL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
import { LanguageQueryParams } from "@/types/repository"; | ||
import tags from "@/utils/tags"; | ||
import { prepareUrl } from "@/utils/url"; | ||
import { coreApiClient } from "./_client"; | ||
import { mergeWithDefaultFilters } from "@/utils/url"; | ||
import { fetchFromApi } from "./_client"; | ||
import { languageQueryParamsToDto } from "./_transformers"; | ||
import { DEFAULT_QUERY_FILTERS } from "@/data/fetch"; | ||
|
||
const LANGUAGES_PATH = "/languages"; | ||
|
||
export async function getAllLanguages(query?: LanguageQueryParams) { | ||
const queryDto = languageQueryParamsToDto(query); | ||
const url = prepareUrl(`${LANGUAGES_PATH}`, queryDto); | ||
export async function getAllLanguages(query: LanguageQueryParams) { | ||
const mergedQuery = mergeWithDefaultFilters(query, DEFAULT_QUERY_FILTERS); | ||
const queryDto = languageQueryParamsToDto(mergedQuery); | ||
|
||
const response = await coreApiClient.get<string[]>(url, { | ||
tag: tags.languages, | ||
}); | ||
|
||
const uniqueLanguages = Array.from( | ||
const response = await fetchFromApi<string[]>( | ||
LANGUAGES_PATH, | ||
queryDto, | ||
tags.languages, | ||
); | ||
return Array.from( | ||
new Set(response.map((language) => language.toLowerCase())), | ||
); | ||
|
||
return uniqueLanguages; | ||
} | ||
|
||
export default { getAllLanguages }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.