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
15dff40b
Commit
15dff40b
authored
Jul 21, 2021
by
Kim, Subin
Browse files
findonlyTitle, findaboutAll, movieforAdmin
parent
1f3acca1
Changes
1
Show whitespace changes
Inline
Side-by-side
server/controllers/movie.controller.js
View file @
15dff40b
...
@@ -58,27 +58,38 @@ const getMovieById = async (req, res) => {
...
@@ -58,27 +58,38 @@ const getMovieById = async (req, res) => {
}
}
}
}
const
getAllMovie
=
async
(
req
,
res
)
=>
{
const
movieforAdmin
=
async
(
req
,
res
)
=>
{
try
{
try
{
const
{
pageNum
}
=
req
.
query
const
TMDBmovieIds
=
[]
const
TMDBmovieIds
=
[]
const
now
=
new
Date
()
const
TMDBmovies
=
req
.
TMDBmovies
const
monthAgo
=
new
Date
(
now
.
setMonth
(
now
.
getMonth
()
-
1
)).
toJSON
().
split
(
/T/
)[
0
]
const
response
=
await
axios
.
get
(
`https://api.themoviedb.org/3/discover/movie?api_key=
${
process
.
env
.
TMDB_APP_KEY
}
&language=ko-KR®ion=KR&sort_by=release_date.asc&release_date.gte=
${
monthAgo
}
&page=
${
pageNum
}
`
)
const
TMDBmovies
=
response
.
data
.
results
TMDBmovies
.
forEach
(
element
=>
{
TMDBmovies
.
forEach
(
element
=>
{
TMDBmovieIds
.
push
(
element
.
id
)
TMDBmovieIds
.
push
(
element
.
id
)
})
})
const
findDirectorResult
=
await
Promise
.
all
(
TMDBmovieIds
.
map
(
async
(
movieId
)
=>
{
let
newObj
=
{
id
:
movieId
,
name
:
""
}
const
{
data
}
=
await
axios
.
get
(
`https://api.themoviedb.org/3/movie/
${
movieId
}
/credits?api_key=
${
process
.
env
.
TMDB_APP_KEY
}
&language=ko-KR`
)
const
findDirectors
=
await
data
.
crew
.
filter
(
element
=>
element
.
job
===
"
Director
"
)
if
(
findDirectors
.
length
!==
0
)
{
const
name
=
findDirectors
.
reduce
((
acc
,
cur
,
idx
)
=>
{
if
(
idx
!==
0
)
return
acc
+
'
,
'
+
cur
.
name
else
return
acc
+
cur
.
name
},
''
)
newObj
.
name
=
name
}
else
newObj
.
name
=
"
없음
"
return
newObj
}))
findDirectorResult
.
forEach
(
element
=>
TMDBmovies
.
forEach
(
movie
=>
{
if
(
element
.
id
===
movie
.
id
)
movie
.
director
=
element
.
name
}))
const
responseAfterCompare
=
await
Movie
.
findAll
({
const
responseAfterCompare
=
await
Movie
.
findAll
({
where
:
{
where
:
{
movieId
:
TMDBmovieIds
movieId
:
TMDBmovieIds
},
},
attributes
:
[
'
movieId
'
]
attributes
:
[
'
movieId
'
]
})
})
responseAfterCompare
.
forEach
(
element
=>
TMDBmovies
.
find
((
movie
)
=>
{
responseAfterCompare
.
forEach
(
element
=>
TMDBmovies
.
forEach
((
movie
)
=>
{
if
(
movie
.
existed
!==
true
&&
movie
.
id
===
element
.
movieId
)
{
if
(
movie
.
existed
!==
true
&&
movie
.
id
===
element
.
movieId
)
movie
.
existed
=
true
movie
.
existed
=
true
else
if
(
movie
.
existed
!==
true
)
movie
.
existed
=
false
}
else
if
(
movie
.
existed
!==
true
)
movie
.
existed
=
false
}))
}))
return
res
.
json
(
TMDBmovies
)
return
res
.
json
(
TMDBmovies
)
}
catch
(
error
)
{
}
catch
(
error
)
{
...
@@ -86,6 +97,19 @@ const getAllMovie = async (req, res) => {
...
@@ -86,6 +97,19 @@ const getAllMovie = async (req, res) => {
}
}
}
}
const
getAllMovie
=
async
(
req
,
res
,
next
)
=>
{
try
{
const
{
pageNum
}
=
req
.
query
const
now
=
new
Date
()
const
monthAgo
=
new
Date
(
now
.
setMonth
(
now
.
getMonth
()
-
1
)).
toJSON
().
split
(
/T/
)[
0
]
const
response
=
await
axios
.
get
(
`https://api.themoviedb.org/3/discover/movie?api_key=
${
process
.
env
.
TMDB_APP_KEY
}
&language=ko-KR®ion=KR&sort_by=release_date.asc&release_date.gte=
${
monthAgo
}
&page=
${
pageNum
}
`
)
req
.
TMDBmovies
=
response
.
data
.
results
next
()
}
catch
(
error
)
{
return
res
.
status
(
500
).
send
(
error
.
message
||
"
영화 가져오는 중 에러 발생
"
)
}
}
const
create
=
async
(
req
,
res
)
=>
{
const
create
=
async
(
req
,
res
)
=>
{
try
{
try
{
const
{
movieId
}
=
req
.
params
const
{
movieId
}
=
req
.
params
...
@@ -107,14 +131,14 @@ const remove = async (req, res) => {
...
@@ -107,14 +131,14 @@ const remove = async (req, res) => {
}
}
}
}
const
find
forKeyword
=
async
(
req
,
res
)
=>
{
const
find
onlyTitle
=
async
(
req
,
res
)
=>
{
try
{
try
{
const
{
title
}
=
req
.
query
const
{
keyword
}
=
req
.
query
const
movieIds
=
[]
const
movieIds
=
[]
const
{
count
,
rows
}
=
await
Movie
.
findAndCountAll
({
const
{
count
,
rows
}
=
await
Movie
.
findAndCountAll
({
where
:
{
where
:
{
title
:
{
title
:
{
[
Op
.
substring
]:
title
[
Op
.
substring
]:
keyword
}
}
}
}
});
});
...
@@ -133,6 +157,17 @@ const findforKeyword = async (req, res) => {
...
@@ -133,6 +157,17 @@ const findforKeyword = async (req, res) => {
}
}
}
}
const
findaboutAll
=
async
(
req
,
res
,
next
)
=>
{
try
{
const
{
keyword
}
=
req
.
query
const
response
=
await
axios
.
get
(
`https://api.themoviedb.org/3/search/movie?api_key=
${
process
.
env
.
TMDB_APP_KEY
}
&language=kr-KR&query=
${
encodeURI
(
keyword
)}
®ion=KR`
)
req
.
TMDBmovies
=
response
.
data
.
results
next
()
}
catch
(
error
)
{
return
res
.
status
(
500
).
send
(
error
.
message
||
"
영화 검색 중 에러 발생
"
);
}
}
export
default
{
export
default
{
comparePopularMovie
,
comparePopularMovie
,
getMovieByCategory
,
getMovieByCategory
,
...
@@ -140,5 +175,7 @@ export default {
...
@@ -140,5 +175,7 @@ export default {
getAllMovie
,
getAllMovie
,
create
,
create
,
remove
,
remove
,
findforKeyword
findonlyTitle
,
findaboutAll
,
movieforAdmin
}
}
\ 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