Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
butter-studio
Commits
39c7caed
Commit
39c7caed
authored
Jul 19, 2021
by
Kim, Subin
Browse files
movie route&controller 추가
parent
77a77140
Changes
2
Hide whitespace changes
Inline
Side-by-side
server/controllers/movie.controller.js
View file @
39c7caed
import
axios
from
'
axios
'
import
{
Movie
}
from
"
../db/index.js
"
;
import
sequelize
from
'
sequelize
'
;
const
{
Op
}
=
sequelize
const
comparePopularMovie
=
async
(
req
,
res
)
=>
{
const
response
=
await
axios
.
get
(
'
https://api.themoviedb.org/3/movie/popular?api_key=1477348488076cafd4dcf973a314957d&language=ko-KR
'
)
...
...
@@ -8,7 +10,52 @@ const comparePopularMovie = async (req, res) => {
try
{
}
catch
(
error
)
{
return
res
.
status
(
500
).
send
(
error
.
message
||
"
영화 가져오기 중 에러 발생
"
);
}
}
const
getMovieByCategory
=
async
(
req
,
res
,
next
,
category
)
=>
{
const
responsePopular
=
await
axios
.
get
(
`https://api.themoviedb.org/3/movie/
${
category
}
?api_key=
${
process
.
env
.
TMDB_APP_KEY
}
&language=ko-KR&page=1`
)
const
TMDBmovies
=
responsePopular
.
data
.
results
const
TMDBmovieIds
=
[]
TMDBmovies
.
forEach
(
element
=>
{
TMDBmovieIds
.
push
(
element
.
id
)
});
console
.
log
(
TMDBmovieIds
)
try
{
const
responseAfterCompare
=
await
Movie
.
findAll
({
where
:
{
movieId
:
{
[
Op
.
or
]:
TMDBmovieIds
}
}
})
const
movieIds
=
[]
responseAfterCompare
.
forEach
(
el
=>
{
movieIds
.
push
(
el
.
movieId
)
})
console
.
log
(
'
movieIds=
'
,
movieIds
)
req
.
movieIds
=
movieIds
next
()
}
catch
(
error
)
{
return
res
.
status
(
500
).
send
(
error
.
message
||
"
영화 가져오기 중 에러 발생
"
);
}
}
const
getMovieById
=
async
(
req
,
res
)
=>
{
try
{
const
movieIds
=
req
.
movieIds
console
.
log
(
movieIds
)
const
elements
=
await
Promise
.
all
(
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`
)
return
movie
.
data
})
)
console
.
log
(
elements
)
res
.
json
(
elements
)
}
catch
(
error
)
{
return
res
.
status
(
500
).
send
(
error
.
message
||
"
영화 가져오기 중 에러 발생
"
);
}
}
...
...
@@ -24,5 +71,7 @@ const create = async (req, res) => {
export
default
{
comparePopularMovie
,
getMovieByCategory
,
getMovieById
,
create
,
}
\ No newline at end of file
server/routes/movie.route.js
View file @
39c7caed
...
...
@@ -12,4 +12,10 @@ router
.
route
(
"
/:movieId
"
)
.
post
(
movieCtrl
.
create
)
router
.
route
(
'
/showmovie/:category
'
)
.
get
(
movieCtrl
.
getMovieById
)
router
.
param
(
'
category
'
,
movieCtrl
.
getMovieByCategory
)
export
default
router
;
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment