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
75723912
Commit
75723912
authored
Jul 19, 2021
by
Jiwon Yoon
Browse files
Merge branch 'jiwon'
parents
d2351773
b606631f
Changes
22
Hide whitespace changes
Inline
Side-by-side
server/controllers/movie.controller.js
View file @
75723912
...
...
@@ -3,67 +3,67 @@ import sequelize from 'sequelize';
const
{
Op
}
=
sequelize
import
{
Movie
}
from
'
../db/index.js
'
const
comparePopularMovie
=
async
(
req
,
res
)
=>
{
const
responsePopular
=
await
axios
.
get
(
`https://api.themoviedb.org/3/movie/
popular
?api_key=
${
process
.
env
.
TMDB_APP_KEY
}
&language=ko-KR`
)
const
movies
=
responsePopular
.
data
.
results
const
movieIds
=
[]
movies
.
forEach
(
element
=>
{
movieIds
.
push
(
element
.
id
)
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
TMDB
movies
=
responsePopular
.
data
.
results
const
TMDB
movieIds
=
[]
TMDB
movies
.
forEach
(
element
=>
{
TMDB
movieIds
.
push
(
element
.
id
)
});
console
.
log
(
movieIds
)
console
.
log
(
TMDB
movieIds
)
try
{
const
responseAfterCompare
=
await
Movie
.
findAll
({
where
:
{
movieId
:
{
[
Op
.
or
]:
movieIds
[
Op
.
or
]:
TMDB
movieIds
}
}
})
const
popularM
ovieIds
=
[]
const
m
ovieIds
=
[]
responseAfterCompare
.
forEach
(
el
=>
{
popularM
ovieIds
.
push
(
el
.
movieId
)
m
ovieIds
.
push
(
el
.
movieId
)
})
console
.
log
(
'
popularMovieIds=
'
,
popularMovieIds
)
const
m
=
await
Promise
.
all
(
popularMovieIds
.
map
(
async
(
el
)
=>
{
const
movie
=
await
axios
.
get
(
`https://api.themoviedb.org/3/movie/
${
el
}
?api_key=
${
process
.
env
.
TMDB_APP_KEY
}
&language=ko-KR`
)
console
.
log
(
'
movieIds=
'
,
movieIds
)
req
.
movieIds
=
movieIds
next
()
}
catch
(
error
)
{
console
.
log
(
error
)
}
}
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
})
)
res
.
json
(
m
)
)
console
.
log
(
elements
)
res
.
json
(
elements
)
}
catch
(
error
)
{
console
.
log
(
error
)
}
}
const
upcommingMovie
=
async
(
req
,
res
)
=>
{
const
responsePopular
=
await
axios
.
get
(
`https://api.themoviedb.org/3/movie/upcoming?api_key=
${
process
.
env
.
TMDB_APP_KEY
}
&language=ko-KR&page=1`
)
const
movies
=
responsePopular
.
data
.
results
const
movieIds
=
[]
movies
.
forEach
(
element
=>
{
movieIds
.
push
(
element
.
id
)
});
console
.
log
(
movieIds
)
const
getMovieList
=
async
(
req
,
res
)
=>
{
try
{
const
responseAfterCompare
=
await
Movie
.
findAll
({
where
:
{
movieId
:
{
[
Op
.
or
]:
movieIds
}
}
})
const
popularMovieIds
=
[]
responseAfterCompare
.
forEach
(
el
=>
{
popularMovieIds
.
push
(
el
.
movieId
)
const
movieList
=
await
Movie
.
findAll
()
// console.log(movieList)
const
movieIds
=
[]
movieList
.
forEach
(
el
=>
{
movieIds
.
push
(
el
.
movieId
)
})
console
.
log
(
'
popularMovieIds=
'
,
popularMovieIds
)
const
m
=
await
Promise
.
all
(
popularMovieIds
.
map
(
async
(
el
)
=>
{
const
movie
=
await
axios
.
get
(
`https://api.themoviedb.org/3/movie/
${
el
}
?api_key=
${
process
.
env
.
TMDB_APP_KEY
}
&language=ko-KR`
)
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
})
)
res
.
json
(
m
)
)
console
.
log
(
elements
)
res
.
json
(
elements
)
}
catch
(
error
)
{
console
.
log
(
error
)
}
...
...
@@ -73,13 +73,15 @@ const create = async (req, res) => {
try
{
const
{
movieId
}
=
req
.
params
const
newMovie
=
await
Movie
.
create
({
movieId
:
movieId
});
return
res
.
json
(
newMovie
);
res
.
json
(
newMovie
);
}
catch
(
error
)
{
return
res
.
status
(
500
).
send
(
error
.
message
||
"
영화 등록 중 에러 발생
"
);
res
.
status
(
500
).
send
(
error
.
message
||
"
영화 등록 중 에러 발생
"
);
}
}
export
default
{
comparePopularMovie
,
getMovieByCategory
,
getMovieById
,
getMovieList
,
create
,
}
server/routes/movie.route.js
View file @
75723912
...
...
@@ -5,11 +5,17 @@ const router = express.Router();
router
.
route
(
"
/
"
)
.
post
(
movieCtrl
.
comparePopularMovie
)
.
get
(
movieCtrl
.
comparePopularMovie
)
// .post(movieCtrl.comparePopularMovie)
router
.
route
(
'
/showmovies/:category
'
)
.
get
(
movieCtrl
.
getMovieById
)
router
.
route
(
'
/movielist
'
)
.
get
(
movieCtrl
.
getMovieList
)
router
.
route
(
"
/:movieId
"
)
.
post
(
movieCtrl
.
create
)
router
.
param
(
'
category
'
,
movieCtrl
.
getMovieByCategory
)
export
default
router
;
\ No newline at end of file
Prev
1
2
Next
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