Toggle navigation
Toggle navigation
This project
Loading...
Sign in
MotherProject
/
myYoutube
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Flare-k
2020-06-09 00:54:15 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
541dc5b5279455bf7284567cb04e32003158ffc6
541dc5b5
1 parent
154f701c
[Modified] Searching videos
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
8 deletions
controllers/videoController.js
db.js
views/search.pug
views/videoDetail.pug
controllers/videoController.js
View file @
541dc5b
/* eslint-disable no-console */
import
routes
from
"../routes"
;
import
Video
from
"../models/Video"
;
...
...
@@ -15,10 +16,18 @@ export const home = async (req, res) => {
}
};
export
const
search
=
(
req
,
res
)
=>
{
export
const
search
=
async
(
req
,
res
)
=>
{
const
{
query
:
{
term
:
searchingBy
},
}
=
req
;
// == const searchingBy = req.query.term;
let
videos
=
[];
try
{
videos
=
await
Video
.
find
({
title
:
{
$regex
:
searchingBy
,
$options
:
"i"
},
// i를 옵션으로 추가하면 insensitive.. 대소문자 구분 안함.
});
}
catch
(
error
)
{
console
.
log
(
error
);
}
res
.
render
(
"search"
,
{
pageTitle
:
"Search"
,
searchingBy
,
videos
});
};
...
...
db.js
View file @
541dc5b
/* eslint-disable no-console */
import
mongoose
from
"mongoose"
;
import
dotenv
from
"dotenv"
;
dotenv
.
config
();
mongoose
.
connect
(
process
.
env
.
MONGO_URL
,
{
useNewUrlParser
:
true
,
useFindAndModify
:
false
,
useNewUrlParser
:
true
,
useFindAndModify
:
false
,
});
const
db
=
mongoose
.
connection
;
const
handleOpen
=
()
=>
{
console
.
log
(
"✅ Connected to DB"
);
console
.
log
(
"✅ Connected to DB"
);
};
const
handleError
=
(
error
)
=>
console
.
log
(
`🔴 Error on DB Connection:
${
error
}
`
);
console
.
log
(
`🔴 Error on DB Connection:
${
error
}
`
);
db
.
once
(
"open"
,
handleOpen
);
//connection을 열고 성공여부를 확인할 수 있는 function을 만들 것이다.
db
.
on
(
"error"
,
handleError
);
\ No newline at end of file
db
.
once
(
"open"
,
handleOpen
);
// connection을 열고 성공여부를 확인할 수 있는 function을 만들 것이다.
db
.
on
(
"error"
,
handleError
);
...
...
views/search.pug
View file @
541dc5b
...
...
@@ -5,9 +5,13 @@ block content
.search__header
h3 Searching for: #{searchingBy}
.search__videos
if videos.length === 0
h5 No Videos Found
each item in videos
+videoBlock({
title : item.title,
views: item.views,
videoFile:item.videoFile
videoFile:item.videoFile,
id: item.id
})
\ No newline at end of file
...
...
views/videoDetail.pug
View file @
541dc5b
...
...
@@ -7,4 +7,9 @@ block content
a(href=routes.editVideo(video.id)) Edit video
h5.video__title=video.title
span.video__views=video.views
p.video__description=video.description
\ No newline at end of file
p.video__description=video.description
.video__comment
if video.comments.length === 1
span.video__comment-number 1 comment
else
span.video__comment-number #{video.comments.length} comments
\ No newline at end of file
...
...
Please
register
or
login
to post a comment