-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from f-lab-edu/feature/24-now-playing-movie-list
구현 - 현재 상영중인 영화 목록 추가
- Loading branch information
Showing
32 changed files
with
264 additions
and
9 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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { tmdbHttp } from "@/shared/api"; | ||
import { camelCaseObjMapper } from "@/shared/lib"; | ||
|
||
import { GenresReqParams } from "./request-types"; | ||
import { GenresDTO } from "./response-types"; | ||
|
||
const genresBaseURL = "genre"; | ||
|
||
export default class GenresApi { | ||
/** | ||
* 영화 장르 목록 | ||
*/ | ||
static async getMovieGenres( | ||
{ language, ...axiosConfig }: GenresReqParams = { language: "ko-KR" }, | ||
): Promise<GenresDTO> { | ||
return tmdbHttp | ||
.get(`${genresBaseURL}/movie/list`, { params: { language }, ...axiosConfig }) | ||
.then((res) => camelCaseObjMapper(res.data)); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from "./genres-api"; | ||
export * from "./request-types"; | ||
export * from "./response-types"; | ||
export * from "./queries"; |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./query-keys"; | ||
export * from "./use-movie-genres-query"; |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { GenresReqParams } from "../request-types"; | ||
|
||
export const genresQueryKeys = { | ||
movieGenres: ({ language }: GenresReqParams) => ["movie-genres", { language }] as const, | ||
}; |
16 changes: 16 additions & 0 deletions
16
apps/web/src/entities/genres/api/queries/use-movie-genres-query.ts
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
|
||
import { Genres } from "../../models"; | ||
import GenresApi from "../genres-api"; | ||
import { GenresReqParams } from "../request-types"; | ||
|
||
import { genresQueryKeys } from "./query-keys"; | ||
|
||
export const useMovieGenresQuery = ({ language }: GenresReqParams = { language: "ko-KR" }) => { | ||
return useQuery({ | ||
queryKey: [...genresQueryKeys.movieGenres({ language })], | ||
queryFn: () => GenresApi.getMovieGenres({ language }), | ||
select: (data) => new Genres(data), | ||
staleTime: 10 * 1000 * 60, | ||
}); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { BaseAxiosReq } from "@/shared/api"; | ||
|
||
export interface GenresReqParams extends BaseAxiosReq { | ||
language: string; | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./genres"; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface GenresDTO { | ||
genres: { id: number; name: string }[]; | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./genres"; |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./api"; | ||
export * from "./models"; |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createBaseModel } from "@/shared/lib"; | ||
|
||
import { GenresDTO } from "../api"; | ||
|
||
export class Genres extends createBaseModel<GenresDTO>() { | ||
constructor(private genresList: GenresDTO) { | ||
super(genresList); | ||
} | ||
|
||
get GenresList() { | ||
return this.genresList.genres.reduce((prev, { id, name }) => { | ||
return prev.set(id, { id, name }); | ||
}, new Map<number, GenresDTO["genres"][0]>()); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./genres"; |
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
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./use-now-playing-movie-list-query"; | ||
export * from "./query-keys"; |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { MovieListReqParams } from "../request-types"; | ||
|
||
export const movieListQueryKeys = { | ||
nowPlayingMovieList: ({ page, language, region }: MovieListReqParams) => | ||
["now-playing-movie-list", { page, language, region }] as const, | ||
}; |
21 changes: 21 additions & 0 deletions
21
apps/web/src/entities/movie-list/api/queries/use-now-playing-movie-list-query.ts
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
|
||
import { useMovieGenresQuery } from "@/entities/genres"; | ||
|
||
import { NowPlayingMovieList } from "../../model/now-playing-movie-list"; | ||
import MovieListApi from "../movie-list-api"; | ||
import { MovieListReqParams } from "../request-types"; | ||
|
||
import { movieListQueryKeys } from "./query-keys"; | ||
|
||
export const useNowPlayingMovieListQuery = ( | ||
{ page, language, region }: MovieListReqParams = { page: 1, language: "ko-KR", region: "KR" }, | ||
) => { | ||
const { data: movieGenres } = useMovieGenresQuery(); | ||
|
||
return useQuery({ | ||
queryKey: [...movieListQueryKeys.nowPlayingMovieList({ page, language, region })], | ||
queryFn: () => MovieListApi.getNowPlayingMovieList({ page, language, region }), | ||
select: (data) => new NowPlayingMovieList(data, movieGenres), | ||
}); | ||
}; |
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
8 changes: 8 additions & 0 deletions
8
apps/web/src/entities/movie-list/api/response-types/now-playing-movie-list.ts
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { MovieListDTO } from "./movie-list"; | ||
|
||
export interface NowPlayingMovieListDTO extends MovieListDTO { | ||
dates: { | ||
maximum: string; | ||
minimum: string; | ||
}; | ||
} |
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,15 +1,21 @@ | ||
import { Genres } from "@/entities/genres"; | ||
import { createBaseModel } from "@/shared/lib"; | ||
|
||
import { MovieListDTO } from "../api/response-types/movie-list"; | ||
|
||
import { MovieListItem } from "./movie-list-item"; | ||
|
||
export abstract class MovieList extends createBaseModel<MovieListDTO>() { | ||
constructor(private movieList: MovieListDTO) { | ||
constructor( | ||
private movieList: MovieListDTO, | ||
private genresModel?: Genres, | ||
) { | ||
super(movieList); | ||
} | ||
|
||
get GeneralAudienceMovies() { | ||
return this.movieList.results.filter(({ adult }) => !adult).map((item) => new MovieListItem(item)); | ||
return this.movieList.results | ||
.filter(({ adult }) => !adult) | ||
.map((item) => new MovieListItem(item, this.genresModel)); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
apps/web/src/entities/movie-list/model/now-playing-movie-list.ts
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { MovieList } from "./movie-list"; | ||
|
||
export class NowPlayingMovieList extends MovieList {} |
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,2 +1,3 @@ | ||
export * from "./popular-movie-card/popular-movie-card"; | ||
export * from "./upcoming-movie-card/upcoming-movie-card"; | ||
export * from "./now-playing-movie-card/now-playing-movie-card"; |
37 changes: 37 additions & 0 deletions
37
apps/web/src/entities/movie-list/ui/now-playing-movie-card/now-playing-movie-card.tsx
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { AspectRatio } from "@repo/ui/aspect-ratio"; | ||
import Image from "next/image"; | ||
|
||
import { MovieInfoCard } from "@/shared/ui/movie-info-card"; | ||
import { Text } from "@/shared/ui/text"; | ||
|
||
import { MovieListItem } from "../../model"; | ||
|
||
export function NowPlayingMovieCard({ movieInfo }: { movieInfo: MovieListItem }) { | ||
const { posterPath, title, Genres } = movieInfo; | ||
|
||
return ( | ||
<MovieInfoCard> | ||
<MovieInfoCard.Poster> | ||
<AspectRatio ratio={4 / 3}> | ||
<Image | ||
alt={`${title} poster image`} | ||
height={300} | ||
src={`${process.env.NEXT_PUBLIC_TMDB_RESOURCE_BASE_URL}/t/p/w400${posterPath}`} | ||
style={{ width: "100%", height: "100%" }} | ||
width={200} | ||
/> | ||
</AspectRatio> | ||
</MovieInfoCard.Poster> | ||
|
||
<MovieInfoCard.Title> | ||
<Text lineHeight="short" size="md"> | ||
{title} | ||
</Text> | ||
</MovieInfoCard.Title> | ||
|
||
<MovieInfoCard.Description> | ||
<Text size="xs">{Genres}</Text> | ||
</MovieInfoCard.Description> | ||
</MovieInfoCard> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./ui"; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./now-playing-movie-list/now-playing-movie-list"; |
36 changes: 36 additions & 0 deletions
36
.../features/get-now-playing-movie-list/ui/now-playing-movie-list/now-playing-movie-list.tsx
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Swiper, SwiperSlide } from "swiper/react"; | ||
import { SwiperOptions } from "swiper/types"; | ||
|
||
import { NowPlayingMovieCard, useNowPlayingMovieListQuery } from "@/entities/movie-list"; | ||
import { screenBreakPoints } from "@/shared/styles"; | ||
|
||
const swiperBreakPoints: SwiperOptions["breakpoints"] = { | ||
[parseInt(screenBreakPoints.sm)]: { slidesPerView: 4, spaceBetween: 12 }, | ||
[parseInt(screenBreakPoints.md)]: { slidesPerView: 5, spaceBetween: 16 }, | ||
}; | ||
|
||
export function NowPlayingMovieList() { | ||
const { data: nowPlayingMovieList, status: nowPlayingMovieListStatus } = useNowPlayingMovieListQuery(); | ||
|
||
// useQueries(movieListQueries.nowPlayingMovieList()); | ||
|
||
if (nowPlayingMovieListStatus === "pending") { | ||
return <div>Loading...</div>; | ||
} | ||
|
||
if (nowPlayingMovieListStatus === "error") { | ||
return <div>Error...</div>; | ||
} | ||
|
||
return ( | ||
<Swiper breakpoints={swiperBreakPoints} slidesPerView={3} spaceBetween={8}> | ||
{nowPlayingMovieList.GeneralAudienceMovies?.map((movieInfo) => { | ||
return ( | ||
<SwiperSlide key={movieInfo.id}> | ||
<NowPlayingMovieCard movieInfo={movieInfo} /> | ||
</SwiperSlide> | ||
); | ||
})} | ||
</Swiper> | ||
); | ||
} |
Oops, something went wrong.