From bb995c1363be9bc3d58db3cf1013058ff78f01ca Mon Sep 17 00:00:00 2001 From: ag502 Date: Mon, 4 Nov 2024 23:22:21 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20discover=20movie=20api=20=EB=9D=BC?= =?UTF-8?q?=EC=9A=B0=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web/pages/api/discover/movie.ts | 40 +++++++++++++++ apps/web/src/entities/discover/api/index.ts | 2 + .../discover/api/request-types/index.ts | 1 + .../api/request-types/movie.server.ts | 49 +++++++++++++++++++ .../discover/api/response-types/index.ts | 1 + .../api/response-types/movie.server.ts | 3 ++ apps/web/src/entities/discover/index.ts | 1 + 7 files changed, 97 insertions(+) create mode 100644 apps/web/pages/api/discover/movie.ts create mode 100644 apps/web/src/entities/discover/api/index.ts create mode 100644 apps/web/src/entities/discover/api/request-types/index.ts create mode 100644 apps/web/src/entities/discover/api/request-types/movie.server.ts create mode 100644 apps/web/src/entities/discover/api/response-types/index.ts create mode 100644 apps/web/src/entities/discover/api/response-types/movie.server.ts create mode 100644 apps/web/src/entities/discover/index.ts diff --git a/apps/web/pages/api/discover/movie.ts b/apps/web/pages/api/discover/movie.ts new file mode 100644 index 0000000..7f73a66 --- /dev/null +++ b/apps/web/pages/api/discover/movie.ts @@ -0,0 +1,40 @@ +import { + DiscoveredMovieList, + discoveredMovieListQuerySchema, + SDiscoveredMovieListReqParams, +} from "@/entities/discover"; +import { tmdbHttpServer, withCommonRoute } from "@/shared/api"; +import { camelCaseObjMapper } from "@/shared/lib"; + +export default withCommonRoute( + async (req, res) => { + const queries = req.query as unknown as SDiscoveredMovieListReqParams; + + const result = await tmdbHttpServer.get("discover/movie", { + params: { + certification_country: queries.certificationCountry, + include_adult: queries.includeAdult, + include_video: queries.includeVideo, + language: queries.language, + page: queries.page, + "release_date.gte": queries.releaseDateGte, + "release_date.lte": queries.releaseDateLte, + sort_by: queries.sortBy, + "vote_average.gte": queries.voteAverageGte, + "vote_average.lte": queries.voteAverageLte, + "vote_count.gte": queries.voteCountGte, + "vote_count.lte": queries.voteCountLte, + watch_region: queries.watchRegion, + with_genre: queries.withGenre, + with_release_type: queries.withReleaseType && queries.withReleaseType.join("|"), + "with_run_time.gte": queries.withRunTimeGte, + "with_run_time.lte": queries.withRunTimeLte, + }, + }); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + return res.status(200).send(camelCaseObjMapper(result.data)); + }, + ["GET"], + discoveredMovieListQuerySchema, +); diff --git a/apps/web/src/entities/discover/api/index.ts b/apps/web/src/entities/discover/api/index.ts new file mode 100644 index 0000000..ef64242 --- /dev/null +++ b/apps/web/src/entities/discover/api/index.ts @@ -0,0 +1,2 @@ +export * from "./request-types"; +export * from "./response-types"; diff --git a/apps/web/src/entities/discover/api/request-types/index.ts b/apps/web/src/entities/discover/api/request-types/index.ts new file mode 100644 index 0000000..bde8ada --- /dev/null +++ b/apps/web/src/entities/discover/api/request-types/index.ts @@ -0,0 +1 @@ +export * from "./movie.server"; diff --git a/apps/web/src/entities/discover/api/request-types/movie.server.ts b/apps/web/src/entities/discover/api/request-types/movie.server.ts new file mode 100644 index 0000000..a4ce037 --- /dev/null +++ b/apps/web/src/entities/discover/api/request-types/movie.server.ts @@ -0,0 +1,49 @@ +import { z } from "zod"; + +export const discoveredMovieListQuerySchema = z.object({ + certificationCountry: z.string().optional(), + includeAdult: z.coerce.boolean().optional(), + includeVideo: z.coerce.boolean().optional(), + language: z.string().optional(), + page: z.coerce.number().optional(), + releaseDateGte: z.coerce.date().optional(), + releaseDateLte: z.coerce.date().optional(), + sortBy: z + .enum([ + "original_title.asc", + "original_title_desc", + "popularity.asc", + "popularity.desc", + "title.asc", + "title.desc", + "vote_average.asc", + "vote_average.desc", + "vote_count.asc", + "vote_count.desc", + ]) + .optional(), + voteAverageGte: z.coerce.number().optional(), + voteAverageLte: z.coerce.number().optional(), + voteCountGte: z.coerce.number().optional(), + voteCountLte: z.coerce.number().optional(), + watchRegion: z.string().optional(), + withGenre: z.string().optional(), + withReleaseType: z.enum(["1", "2", "3", "4", "5"]).array().optional(), + withRunTimeGte: z.coerce.number().optional(), + withRunTimeLte: z.coerce.number().optional(), +}); + +/** + * ``` + * voteAverage - 사용자 점수 + * voteCount - 투표수 + * withReleaseType + * 1 - Premiere + * 2 - Theatrical (limited) + * 3 - Theatrical + * 4 - Digital + * 5 - Physical + * 6 - TV + * ``` + */ +export type SDiscoveredMovieListReqParams = z.infer; diff --git a/apps/web/src/entities/discover/api/response-types/index.ts b/apps/web/src/entities/discover/api/response-types/index.ts new file mode 100644 index 0000000..bde8ada --- /dev/null +++ b/apps/web/src/entities/discover/api/response-types/index.ts @@ -0,0 +1 @@ +export * from "./movie.server"; diff --git a/apps/web/src/entities/discover/api/response-types/movie.server.ts b/apps/web/src/entities/discover/api/response-types/movie.server.ts new file mode 100644 index 0000000..e20e4ed --- /dev/null +++ b/apps/web/src/entities/discover/api/response-types/movie.server.ts @@ -0,0 +1,3 @@ +import { MovieList } from "@/entities/movie-list/api/response-types/movie-list.server"; + +export interface DiscoveredMovieList extends MovieList {} diff --git a/apps/web/src/entities/discover/index.ts b/apps/web/src/entities/discover/index.ts new file mode 100644 index 0000000..d158c57 --- /dev/null +++ b/apps/web/src/entities/discover/index.ts @@ -0,0 +1 @@ +export * from "./api"; From e9f143a0978129b3d235207bf2df3babefb18c52 Mon Sep 17 00:00:00 2001 From: ag502 Date: Tue, 5 Nov 2024 00:27:05 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20discover=20api=20=EC=9A=94=EC=B2=AD?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/entities/discover/api/discover-api.ts | 26 +++++++++++++++++++ apps/web/src/entities/discover/api/index.ts | 1 + .../discover/api/request-types/movie.ts | 3 +++ .../discover/api/response-types/index.ts | 4 +++ .../discover/api/response-types/movie.ts | 3 +++ 5 files changed, 37 insertions(+) create mode 100644 apps/web/src/entities/discover/api/discover-api.ts create mode 100644 apps/web/src/entities/discover/api/request-types/movie.ts create mode 100644 apps/web/src/entities/discover/api/response-types/movie.ts diff --git a/apps/web/src/entities/discover/api/discover-api.ts b/apps/web/src/entities/discover/api/discover-api.ts new file mode 100644 index 0000000..0a7f4a1 --- /dev/null +++ b/apps/web/src/entities/discover/api/discover-api.ts @@ -0,0 +1,26 @@ +import { AxiosRequestConfig } from "axios"; + +import { DiscoveredMovieListDTO } from "@/entities/discover"; +import { DiscoveredMovieListReqParams } from "@/entities/discover/api/request-types/movie"; +import { localHttp } from "@/shared/api"; + +const discoverBaseURL = "discover"; + +export default class DiscoverApi { + /** + * 영화 필터 + */ + static async getFilterMovies( + args: DiscoveredMovieListReqParams, + axiosRequestConfig?: AxiosRequestConfig, + ): Promise { + const { page = 1, language = "ko-KR", watchRegion = "KR", ...restArgs } = args; + + return localHttp + .get(`${discoverBaseURL}/discover/movie`, { + params: { page, language, watchRegion, ...restArgs }, + ...axiosRequestConfig, + }) + .then((res) => res.data); + } +} diff --git a/apps/web/src/entities/discover/api/index.ts b/apps/web/src/entities/discover/api/index.ts index ef64242..b5663e0 100644 --- a/apps/web/src/entities/discover/api/index.ts +++ b/apps/web/src/entities/discover/api/index.ts @@ -1,2 +1,3 @@ export * from "./request-types"; export * from "./response-types"; +export * from "./discover-api"; diff --git a/apps/web/src/entities/discover/api/request-types/movie.ts b/apps/web/src/entities/discover/api/request-types/movie.ts new file mode 100644 index 0000000..64237cf --- /dev/null +++ b/apps/web/src/entities/discover/api/request-types/movie.ts @@ -0,0 +1,3 @@ +import { SDiscoveredMovieListReqParams } from "@/entities/discover"; + +export interface DiscoveredMovieListReqParams extends SDiscoveredMovieListReqParams {} diff --git a/apps/web/src/entities/discover/api/response-types/index.ts b/apps/web/src/entities/discover/api/response-types/index.ts index bde8ada..f9acd5e 100644 --- a/apps/web/src/entities/discover/api/response-types/index.ts +++ b/apps/web/src/entities/discover/api/response-types/index.ts @@ -1 +1,5 @@ +// server export * from "./movie.server"; + +// client +export * from "./movie"; diff --git a/apps/web/src/entities/discover/api/response-types/movie.ts b/apps/web/src/entities/discover/api/response-types/movie.ts new file mode 100644 index 0000000..2133d0d --- /dev/null +++ b/apps/web/src/entities/discover/api/response-types/movie.ts @@ -0,0 +1,3 @@ +import { MovieListDTO } from "@/entities/movie-list"; + +export interface DiscoveredMovieListDTO extends MovieListDTO {} From 7cdd94180ae766afe6b73a4d9aa6849f6ad41434 Mon Sep 17 00:00:00 2001 From: ag502 Date: Sat, 9 Nov 2024 22:08:19 +0900 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20use-filtered-movie-list=20react-que?= =?UTF-8?q?ry=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/entities/discover/api/discover-api.ts | 6 ++--- .../entities/discover/api/queries/index.ts | 2 ++ .../discover/api/queries/query-keys.ts | 7 ++++++ .../api/queries/use-filtered-movie-list.ts | 24 +++++++++++++++++++ apps/web/src/entities/discover/index.ts | 1 + .../discover/model/discovered-movie-list.ts | 7 ++++++ apps/web/src/entities/discover/model/index.ts | 0 7 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 apps/web/src/entities/discover/api/queries/index.ts create mode 100644 apps/web/src/entities/discover/api/queries/query-keys.ts create mode 100644 apps/web/src/entities/discover/api/queries/use-filtered-movie-list.ts create mode 100644 apps/web/src/entities/discover/model/discovered-movie-list.ts create mode 100644 apps/web/src/entities/discover/model/index.ts diff --git a/apps/web/src/entities/discover/api/discover-api.ts b/apps/web/src/entities/discover/api/discover-api.ts index 0a7f4a1..c4e95fe 100644 --- a/apps/web/src/entities/discover/api/discover-api.ts +++ b/apps/web/src/entities/discover/api/discover-api.ts @@ -14,11 +14,9 @@ export default class DiscoverApi { args: DiscoveredMovieListReqParams, axiosRequestConfig?: AxiosRequestConfig, ): Promise { - const { page = 1, language = "ko-KR", watchRegion = "KR", ...restArgs } = args; - return localHttp - .get(`${discoverBaseURL}/discover/movie`, { - params: { page, language, watchRegion, ...restArgs }, + .get(`${discoverBaseURL}/movie`, { + params: args, ...axiosRequestConfig, }) .then((res) => res.data); diff --git a/apps/web/src/entities/discover/api/queries/index.ts b/apps/web/src/entities/discover/api/queries/index.ts new file mode 100644 index 0000000..dd1c8d8 --- /dev/null +++ b/apps/web/src/entities/discover/api/queries/index.ts @@ -0,0 +1,2 @@ +export * from "./query-keys"; +export * from "./use-filtered-movie-list"; diff --git a/apps/web/src/entities/discover/api/queries/query-keys.ts b/apps/web/src/entities/discover/api/queries/query-keys.ts new file mode 100644 index 0000000..ee3ea4f --- /dev/null +++ b/apps/web/src/entities/discover/api/queries/query-keys.ts @@ -0,0 +1,7 @@ +import { DiscoveredMovieListReqParams } from "@/entities/discover/api/request-types/movie"; + +export const filteredMediaListQueryKeys = { + all: ["filter"] as const, + filteredMovieList: (args: DiscoveredMovieListReqParams) => + [...filteredMediaListQueryKeys.all, "filtered-movie-list", { ...args }] as const, +}; diff --git a/apps/web/src/entities/discover/api/queries/use-filtered-movie-list.ts b/apps/web/src/entities/discover/api/queries/use-filtered-movie-list.ts new file mode 100644 index 0000000..c60c3e6 --- /dev/null +++ b/apps/web/src/entities/discover/api/queries/use-filtered-movie-list.ts @@ -0,0 +1,24 @@ +import { useQuery } from "@tanstack/react-query"; + +import DiscoverApi from "@/entities/discover/api/discover-api"; +import { filteredMediaListQueryKeys } from "@/entities/discover/api/queries/query-keys"; +import { DiscoveredMovieListReqParams } from "@/entities/discover/api/request-types/movie"; +import DiscoveredMovieListModel from "@/entities/discover/model/discovered-movie-list"; + +export const useFilteredMovieList = (args: DiscoveredMovieListReqParams = {}) => { + const { page = 1, watchRegion = "KR", certificationCountry = "KR", language = "ko-KR", ...restArgs } = args; + + const reqArgs = { + page, + watchRegion, + certificationCountry, + language, + ...restArgs, + }; + + return useQuery({ + queryKey: [...filteredMediaListQueryKeys.all, ...filteredMediaListQueryKeys.filteredMovieList(reqArgs)], + queryFn: () => DiscoverApi.getFilterMovies(reqArgs), + select: (data) => new DiscoveredMovieListModel(data), + }); +}; diff --git a/apps/web/src/entities/discover/index.ts b/apps/web/src/entities/discover/index.ts index d158c57..53d0ae8 100644 --- a/apps/web/src/entities/discover/index.ts +++ b/apps/web/src/entities/discover/index.ts @@ -1 +1,2 @@ export * from "./api"; +export * from "./model"; diff --git a/apps/web/src/entities/discover/model/discovered-movie-list.ts b/apps/web/src/entities/discover/model/discovered-movie-list.ts new file mode 100644 index 0000000..dc1d5ba --- /dev/null +++ b/apps/web/src/entities/discover/model/discovered-movie-list.ts @@ -0,0 +1,7 @@ +import { MovieListDTO, MovieListModel } from "@/entities/movie-list"; + +export default class DiscoveredMovieListModel extends MovieListModel { + constructor(data: MovieListDTO) { + super(data); + } +} diff --git a/apps/web/src/entities/discover/model/index.ts b/apps/web/src/entities/discover/model/index.ts new file mode 100644 index 0000000..e69de29 From 4af5f795bd2ae743b2978c714a26c47d993b7184 Mon Sep 17 00:00:00 2001 From: ag502 Date: Sat, 9 Nov 2024 22:14:47 +0900 Subject: [PATCH 4/4] =?UTF-8?q?rename:=20discover=20api=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EB=B3=80=EC=88=98?= =?UTF-8?q?=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * discover -> filter로 변수명 변경 --- .../pages/api/{discover => filter}/movie.ts | 17 ++++++------- .../discover/api/queries/query-keys.ts | 7 ------ .../api/queries/use-filtered-movie-list.ts | 24 ------------------- .../discover/api/request-types/movie.ts | 3 --- .../discover/api/response-types/movie.ts | 3 --- .../api/filter-api.ts} | 12 +++++----- .../{discover => filter}/api/index.ts | 2 +- .../{discover => filter}/api/queries/index.ts | 0 .../entities/filter/api/queries/query-keys.ts | 6 +++++ .../api/queries/use-filtered-movie-list.ts | 24 +++++++++++++++++++ .../api/request-types/index.ts | 0 .../api/request-types/movie.server.ts | 4 ++-- .../filter/api/request-types/movie.ts | 3 +++ .../api/response-types/index.ts | 0 .../api/response-types/movie.server.ts | 2 +- .../filter/api/response-types/movie.ts | 3 +++ .../entities/{discover => filter}/index.ts | 0 .../model/filtered-movie-list.ts} | 2 +- .../{discover => filter}/model/index.ts | 0 19 files changed, 56 insertions(+), 56 deletions(-) rename apps/web/pages/api/{discover => filter}/movie.ts (79%) delete mode 100644 apps/web/src/entities/discover/api/queries/query-keys.ts delete mode 100644 apps/web/src/entities/discover/api/queries/use-filtered-movie-list.ts delete mode 100644 apps/web/src/entities/discover/api/request-types/movie.ts delete mode 100644 apps/web/src/entities/discover/api/response-types/movie.ts rename apps/web/src/entities/{discover/api/discover-api.ts => filter/api/filter-api.ts} (54%) rename apps/web/src/entities/{discover => filter}/api/index.ts (67%) rename apps/web/src/entities/{discover => filter}/api/queries/index.ts (100%) create mode 100644 apps/web/src/entities/filter/api/queries/query-keys.ts create mode 100644 apps/web/src/entities/filter/api/queries/use-filtered-movie-list.ts rename apps/web/src/entities/{discover => filter}/api/request-types/index.ts (100%) rename apps/web/src/entities/{discover => filter}/api/request-types/movie.server.ts (89%) create mode 100644 apps/web/src/entities/filter/api/request-types/movie.ts rename apps/web/src/entities/{discover => filter}/api/response-types/index.ts (100%) rename apps/web/src/entities/{discover => filter}/api/response-types/movie.server.ts (60%) create mode 100644 apps/web/src/entities/filter/api/response-types/movie.ts rename apps/web/src/entities/{discover => filter}/index.ts (100%) rename apps/web/src/entities/{discover/model/discovered-movie-list.ts => filter/model/filtered-movie-list.ts} (64%) rename apps/web/src/entities/{discover => filter}/model/index.ts (100%) diff --git a/apps/web/pages/api/discover/movie.ts b/apps/web/pages/api/filter/movie.ts similarity index 79% rename from apps/web/pages/api/discover/movie.ts rename to apps/web/pages/api/filter/movie.ts index 7f73a66..54ba8ce 100644 --- a/apps/web/pages/api/discover/movie.ts +++ b/apps/web/pages/api/filter/movie.ts @@ -1,16 +1,17 @@ -import { - DiscoveredMovieList, - discoveredMovieListQuerySchema, - SDiscoveredMovieListReqParams, -} from "@/entities/discover"; import { tmdbHttpServer, withCommonRoute } from "@/shared/api"; import { camelCaseObjMapper } from "@/shared/lib"; +import { + FilteredMovieList, + filteredMovieListQuerySchema, + SFilteredMovieListReqParams, +} from "../../../src/entities/filter"; + export default withCommonRoute( async (req, res) => { - const queries = req.query as unknown as SDiscoveredMovieListReqParams; + const queries = req.query as unknown as SFilteredMovieListReqParams; - const result = await tmdbHttpServer.get("discover/movie", { + const result = await tmdbHttpServer.get("discover/movie", { params: { certification_country: queries.certificationCountry, include_adult: queries.includeAdult, @@ -36,5 +37,5 @@ export default withCommonRoute( return res.status(200).send(camelCaseObjMapper(result.data)); }, ["GET"], - discoveredMovieListQuerySchema, + filteredMovieListQuerySchema, ); diff --git a/apps/web/src/entities/discover/api/queries/query-keys.ts b/apps/web/src/entities/discover/api/queries/query-keys.ts deleted file mode 100644 index ee3ea4f..0000000 --- a/apps/web/src/entities/discover/api/queries/query-keys.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { DiscoveredMovieListReqParams } from "@/entities/discover/api/request-types/movie"; - -export const filteredMediaListQueryKeys = { - all: ["filter"] as const, - filteredMovieList: (args: DiscoveredMovieListReqParams) => - [...filteredMediaListQueryKeys.all, "filtered-movie-list", { ...args }] as const, -}; diff --git a/apps/web/src/entities/discover/api/queries/use-filtered-movie-list.ts b/apps/web/src/entities/discover/api/queries/use-filtered-movie-list.ts deleted file mode 100644 index c60c3e6..0000000 --- a/apps/web/src/entities/discover/api/queries/use-filtered-movie-list.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { useQuery } from "@tanstack/react-query"; - -import DiscoverApi from "@/entities/discover/api/discover-api"; -import { filteredMediaListQueryKeys } from "@/entities/discover/api/queries/query-keys"; -import { DiscoveredMovieListReqParams } from "@/entities/discover/api/request-types/movie"; -import DiscoveredMovieListModel from "@/entities/discover/model/discovered-movie-list"; - -export const useFilteredMovieList = (args: DiscoveredMovieListReqParams = {}) => { - const { page = 1, watchRegion = "KR", certificationCountry = "KR", language = "ko-KR", ...restArgs } = args; - - const reqArgs = { - page, - watchRegion, - certificationCountry, - language, - ...restArgs, - }; - - return useQuery({ - queryKey: [...filteredMediaListQueryKeys.all, ...filteredMediaListQueryKeys.filteredMovieList(reqArgs)], - queryFn: () => DiscoverApi.getFilterMovies(reqArgs), - select: (data) => new DiscoveredMovieListModel(data), - }); -}; diff --git a/apps/web/src/entities/discover/api/request-types/movie.ts b/apps/web/src/entities/discover/api/request-types/movie.ts deleted file mode 100644 index 64237cf..0000000 --- a/apps/web/src/entities/discover/api/request-types/movie.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { SDiscoveredMovieListReqParams } from "@/entities/discover"; - -export interface DiscoveredMovieListReqParams extends SDiscoveredMovieListReqParams {} diff --git a/apps/web/src/entities/discover/api/response-types/movie.ts b/apps/web/src/entities/discover/api/response-types/movie.ts deleted file mode 100644 index 2133d0d..0000000 --- a/apps/web/src/entities/discover/api/response-types/movie.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { MovieListDTO } from "@/entities/movie-list"; - -export interface DiscoveredMovieListDTO extends MovieListDTO {} diff --git a/apps/web/src/entities/discover/api/discover-api.ts b/apps/web/src/entities/filter/api/filter-api.ts similarity index 54% rename from apps/web/src/entities/discover/api/discover-api.ts rename to apps/web/src/entities/filter/api/filter-api.ts index c4e95fe..09df7c4 100644 --- a/apps/web/src/entities/discover/api/discover-api.ts +++ b/apps/web/src/entities/filter/api/filter-api.ts @@ -1,19 +1,19 @@ import { AxiosRequestConfig } from "axios"; -import { DiscoveredMovieListDTO } from "@/entities/discover"; -import { DiscoveredMovieListReqParams } from "@/entities/discover/api/request-types/movie"; +import { FilteredMovieListDTO } from "@/entities/filter"; +import { FilteredMovieListReqParams } from "@/entities/filter/api/request-types/movie"; import { localHttp } from "@/shared/api"; -const discoverBaseURL = "discover"; +const discoverBaseURL = "filter"; -export default class DiscoverApi { +export default class FilterApi { /** * 영화 필터 */ static async getFilterMovies( - args: DiscoveredMovieListReqParams, + args: FilteredMovieListReqParams, axiosRequestConfig?: AxiosRequestConfig, - ): Promise { + ): Promise { return localHttp .get(`${discoverBaseURL}/movie`, { params: args, diff --git a/apps/web/src/entities/discover/api/index.ts b/apps/web/src/entities/filter/api/index.ts similarity index 67% rename from apps/web/src/entities/discover/api/index.ts rename to apps/web/src/entities/filter/api/index.ts index b5663e0..150ec46 100644 --- a/apps/web/src/entities/discover/api/index.ts +++ b/apps/web/src/entities/filter/api/index.ts @@ -1,3 +1,3 @@ export * from "./request-types"; export * from "./response-types"; -export * from "./discover-api"; +export * from "./filter-api"; diff --git a/apps/web/src/entities/discover/api/queries/index.ts b/apps/web/src/entities/filter/api/queries/index.ts similarity index 100% rename from apps/web/src/entities/discover/api/queries/index.ts rename to apps/web/src/entities/filter/api/queries/index.ts diff --git a/apps/web/src/entities/filter/api/queries/query-keys.ts b/apps/web/src/entities/filter/api/queries/query-keys.ts new file mode 100644 index 0000000..e942ea5 --- /dev/null +++ b/apps/web/src/entities/filter/api/queries/query-keys.ts @@ -0,0 +1,6 @@ +import { FilteredMovieListReqParams } from "@/entities/filter/api/request-types/movie"; + +export const filteredMediaListQueryKeys = { + all: ["filter"] as const, + filteredMovieList: (args: FilteredMovieListReqParams) => ["filtered-movie-list", { ...args }] as const, +}; diff --git a/apps/web/src/entities/filter/api/queries/use-filtered-movie-list.ts b/apps/web/src/entities/filter/api/queries/use-filtered-movie-list.ts new file mode 100644 index 0000000..6fd377c --- /dev/null +++ b/apps/web/src/entities/filter/api/queries/use-filtered-movie-list.ts @@ -0,0 +1,24 @@ +import { useQuery } from "@tanstack/react-query"; + +import FilterApi from "@/entities/filter/api/filter-api"; +import { filteredMediaListQueryKeys } from "@/entities/filter/api/queries/query-keys"; +import { FilteredMovieListReqParams } from "@/entities/filter/api/request-types/movie"; +import FilteredMovieListModel from "@/entities/filter/model/filtered-movie-list"; + +export const useFilteredMovieList = (args: FilteredMovieListReqParams = {}) => { + const { page = 1, watchRegion = "KR", certificationCountry = "KR", language = "ko-KR", ...restArgs } = args; + + const reqArgs = { + page, + watchRegion, + certificationCountry, + language, + ...restArgs, + }; + + return useQuery({ + queryKey: [...filteredMediaListQueryKeys.all, ...filteredMediaListQueryKeys.filteredMovieList(reqArgs)], + queryFn: () => FilterApi.getFilterMovies(reqArgs), + select: (data) => new FilteredMovieListModel(data), + }); +}; diff --git a/apps/web/src/entities/discover/api/request-types/index.ts b/apps/web/src/entities/filter/api/request-types/index.ts similarity index 100% rename from apps/web/src/entities/discover/api/request-types/index.ts rename to apps/web/src/entities/filter/api/request-types/index.ts diff --git a/apps/web/src/entities/discover/api/request-types/movie.server.ts b/apps/web/src/entities/filter/api/request-types/movie.server.ts similarity index 89% rename from apps/web/src/entities/discover/api/request-types/movie.server.ts rename to apps/web/src/entities/filter/api/request-types/movie.server.ts index a4ce037..b5d67e7 100644 --- a/apps/web/src/entities/discover/api/request-types/movie.server.ts +++ b/apps/web/src/entities/filter/api/request-types/movie.server.ts @@ -1,6 +1,6 @@ import { z } from "zod"; -export const discoveredMovieListQuerySchema = z.object({ +export const filteredMovieListQuerySchema = z.object({ certificationCountry: z.string().optional(), includeAdult: z.coerce.boolean().optional(), includeVideo: z.coerce.boolean().optional(), @@ -46,4 +46,4 @@ export const discoveredMovieListQuerySchema = z.object({ * 6 - TV * ``` */ -export type SDiscoveredMovieListReqParams = z.infer; +export type SFilteredMovieListReqParams = z.infer; diff --git a/apps/web/src/entities/filter/api/request-types/movie.ts b/apps/web/src/entities/filter/api/request-types/movie.ts new file mode 100644 index 0000000..3d2541d --- /dev/null +++ b/apps/web/src/entities/filter/api/request-types/movie.ts @@ -0,0 +1,3 @@ +import { SFilteredMovieListReqParams } from "../."; + +export interface FilteredMovieListReqParams extends SFilteredMovieListReqParams {} diff --git a/apps/web/src/entities/discover/api/response-types/index.ts b/apps/web/src/entities/filter/api/response-types/index.ts similarity index 100% rename from apps/web/src/entities/discover/api/response-types/index.ts rename to apps/web/src/entities/filter/api/response-types/index.ts diff --git a/apps/web/src/entities/discover/api/response-types/movie.server.ts b/apps/web/src/entities/filter/api/response-types/movie.server.ts similarity index 60% rename from apps/web/src/entities/discover/api/response-types/movie.server.ts rename to apps/web/src/entities/filter/api/response-types/movie.server.ts index e20e4ed..ebfff6a 100644 --- a/apps/web/src/entities/discover/api/response-types/movie.server.ts +++ b/apps/web/src/entities/filter/api/response-types/movie.server.ts @@ -1,3 +1,3 @@ import { MovieList } from "@/entities/movie-list/api/response-types/movie-list.server"; -export interface DiscoveredMovieList extends MovieList {} +export interface FilteredMovieList extends MovieList {} diff --git a/apps/web/src/entities/filter/api/response-types/movie.ts b/apps/web/src/entities/filter/api/response-types/movie.ts new file mode 100644 index 0000000..c55f0da --- /dev/null +++ b/apps/web/src/entities/filter/api/response-types/movie.ts @@ -0,0 +1,3 @@ +import { MovieListDTO } from "@/entities/movie-list"; + +export interface FilteredMovieListDTO extends MovieListDTO {} diff --git a/apps/web/src/entities/discover/index.ts b/apps/web/src/entities/filter/index.ts similarity index 100% rename from apps/web/src/entities/discover/index.ts rename to apps/web/src/entities/filter/index.ts diff --git a/apps/web/src/entities/discover/model/discovered-movie-list.ts b/apps/web/src/entities/filter/model/filtered-movie-list.ts similarity index 64% rename from apps/web/src/entities/discover/model/discovered-movie-list.ts rename to apps/web/src/entities/filter/model/filtered-movie-list.ts index dc1d5ba..26e1515 100644 --- a/apps/web/src/entities/discover/model/discovered-movie-list.ts +++ b/apps/web/src/entities/filter/model/filtered-movie-list.ts @@ -1,6 +1,6 @@ import { MovieListDTO, MovieListModel } from "@/entities/movie-list"; -export default class DiscoveredMovieListModel extends MovieListModel { +export default class FilteredMovieListModel extends MovieListModel { constructor(data: MovieListDTO) { super(data); } diff --git a/apps/web/src/entities/discover/model/index.ts b/apps/web/src/entities/filter/model/index.ts similarity index 100% rename from apps/web/src/entities/discover/model/index.ts rename to apps/web/src/entities/filter/model/index.ts