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