2025-02-23
2025-02-24
This commit is contained in:
parent
2212f4fc14
commit
0f52ff0cef
40 changed files with 846 additions and 75 deletions
33
src/services/tmdb-api.ts
Normal file
33
src/services/tmdb-api.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { createGetHttpRequest, createUrlWithParams, DebugHttpClient as Dhc } from "@/libs/apis/clients";
|
||||
import { TMDB_ROUTE_SEARCH_MOVIE } from "@/libs/apis/routes";
|
||||
import { type TmdbMovieSearchQueryParams, TmdbMovieSearchResponse } from "@/libs/apis/tmdb/schemas";
|
||||
import { HttpClient, HttpClientRequest, HttpClientResponse } from "@effect/platform";
|
||||
import { Data, Effect, pipe } from "effect";
|
||||
|
||||
export class DebugHttpClient extends Effect.Service<DebugHttpClient>()("DebugHttpClient", {
|
||||
effect: Dhc,
|
||||
}) {}
|
||||
|
||||
export class TmdbApi extends Effect.Service<TmdbApi>()("TmdbApi", {
|
||||
effect: Effect.gen(function*() {
|
||||
yield* Effect.logDebug("--- TMDB-API ---");
|
||||
const client = yield* Dhc;
|
||||
|
||||
return {
|
||||
searchMovie: (args: TmdbMovieSearchQueryParams) =>
|
||||
pipe(
|
||||
createUrlWithParams(TMDB_ROUTE_SEARCH_MOVIE)({ ...args }),
|
||||
Effect.andThen((url: URL) => createGetHttpRequest(url)),
|
||||
Effect.andThen((request: HttpClientRequest.HttpClientRequest) => client.execute(request)),
|
||||
// NOTE: Essentiel à désactiver pour des APIs externes
|
||||
HttpClient.withTracerPropagation(false),
|
||||
Effect.andThen((response: HttpClientResponse.HttpClientResponse) =>
|
||||
HttpClientResponse.schemaBodyJson(TmdbMovieSearchResponse)(response)
|
||||
),
|
||||
Effect.scoped,
|
||||
),
|
||||
};
|
||||
}),
|
||||
}) {}
|
||||
|
||||
export class TmdbApiError extends Data.TaggedError("TmdbApiError")<{ cause: unknown }> {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue