Commit 7261db5e authored by Kim, Subin's avatar Kim, Subin
Browse files

console.log 삭제 및 getListfromDB 추가

parent dca1f6ae
...@@ -3,20 +3,25 @@ import { Movie } from '../db/index.js' ...@@ -3,20 +3,25 @@ import { Movie } from '../db/index.js'
import sequelize from 'sequelize' import sequelize from 'sequelize'
const { Op } = sequelize const { Op } = sequelize
const getListfromDB = async (req, res) => {
try {
const findAll = await Movie.findAll({ attributes: [ 'movieId', 'title', 'release_date' ] })
res.json(findAll)
} catch (error) {
return res.status(500).send(error.message || "영화 목록 가져오기 중 에러 발생");
}
}
const getMovieByCategory = async (req, res, next, category) => { const getMovieByCategory = async (req, res, next, category) => {
try { try {
console.log(category)
const TMDBmovieIds = [] const TMDBmovieIds = []
const movieIds = [] const movieIds = []
console.log(process.env.TMDB_APP_KEY)
const response = await axios.get(`https://api.themoviedb.org/3/movie/${category}?api_key=${process.env.TMDB_APP_KEY}&language=ko-KR&page=1`) const response = await axios.get(`https://api.themoviedb.org/3/movie/${category}?api_key=${process.env.TMDB_APP_KEY}&language=ko-KR&page=1`)
console.log(response.data)
const TMDBmovies = response.data.results const TMDBmovies = response.data.results
TMDBmovies.forEach(element => { TMDBmovies.forEach(element => {
TMDBmovieIds.push(element.id) TMDBmovieIds.push(element.id)
}) })
console.log(TMDBmovies)
const responseAfterCompare = await Movie.findAll({ const responseAfterCompare = await Movie.findAll({
where: { where: {
movieId: { movieId: {
...@@ -27,7 +32,6 @@ const getMovieByCategory = async (req, res, next, category) => { ...@@ -27,7 +32,6 @@ const getMovieByCategory = async (req, res, next, category) => {
responseAfterCompare.forEach(el => { responseAfterCompare.forEach(el => {
movieIds.push(el.movieId) movieIds.push(el.movieId)
}) })
console.log('movieIds=', movieIds)
req.movieIds = movieIds req.movieIds = movieIds
next() next()
} catch (error) { } catch (error) {
...@@ -38,14 +42,12 @@ const getMovieByCategory = async (req, res, next, category) => { ...@@ -38,14 +42,12 @@ const getMovieByCategory = async (req, res, next, category) => {
const getMovieById = async (req, res) => { const getMovieById = async (req, res) => {
try { try {
const movieIds = req.movieIds const movieIds = req.movieIds
console.log(movieIds)
const elements = await Promise.all( const elements = await Promise.all(
movieIds.map(async (movieId) => { movieIds.map(async (movieId) => {
const movie = await axios.get(`https://api.themoviedb.org/3/movie/${movieId}?api_key=${process.env.TMDB_APP_KEY}&language=ko-KR`) const movie = await axios.get(`https://api.themoviedb.org/3/movie/${movieId}?api_key=${process.env.TMDB_APP_KEY}&language=ko-KR`)
return movie.data return movie.data
}) })
) )
console.log(elements)
res.json(elements) res.json(elements)
} catch (error) { } catch (error) {
return res.status(500).send(error.message || "영화 가져오기 중 에러 발생"); return res.status(500).send(error.message || "영화 가져오기 중 에러 발생");
...@@ -107,7 +109,6 @@ const getAllMovie = async (req, res, next) => { ...@@ -107,7 +109,6 @@ const getAllMovie = async (req, res, next) => {
const getMovieList = async(req,res)=>{ const getMovieList = async(req,res)=>{
try { try {
const movieList = await Movie.findAll() const movieList = await Movie.findAll()
// console.log(movieList)
const movieIds=[] const movieIds=[]
movieList.forEach(el => { movieList.forEach(el => {
movieIds.push(el.movieId) movieIds.push(el.movieId)
...@@ -118,7 +119,6 @@ const getMovieList = async(req,res)=>{ ...@@ -118,7 +119,6 @@ const getMovieList = async(req,res)=>{
return movie.data return movie.data
}) })
) )
console.log(elements)
res.json(elements) res.json(elements)
} catch (error) { } catch (error) {
console.log(error) console.log(error)
...@@ -184,6 +184,7 @@ const findaboutAll = async (req, res, next) => { ...@@ -184,6 +184,7 @@ const findaboutAll = async (req, res, next) => {
} }
export default { export default {
getListfromDB,
getMovieByCategory, getMovieByCategory,
getMovieById, getMovieById,
getAllMovie, getAllMovie,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment