Skip to content

Commit 02e767a

Browse files
committed
typo readme
1 parent 09203d3 commit 02e767a

File tree

4 files changed

+161
-3
lines changed

4 files changed

+161
-3
lines changed

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM node:16-alpine
2+
3+
WORKDIR /YoutubeSearchApi
4+
5+
COPY . .
6+
7+
RUN npm install -g nodemon
8+
9+
RUN npm install
10+
11+
RUN npm run test
12+
13+
CMD ["npm", "run", "start"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Mohit Dilip Makwana
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<details>
2727
<summary> Create a Mongo Atlas Connection URI</summary>
2828
<br>
29+
2930
- Login to Mongo Atlas
3031
- Create a project and build new cluster ( it provides a free sandbox )
3132
- Create Database users and secure network access to your machine's IP only
@@ -43,7 +44,7 @@
4344

4445
- Create a new project and enable the Yt Data API v3 at https://console.cloud.google.com/apis/api/youtube.googleapis.com
4546

46-
- Create Credentials and secure the key to allow access to only the created api, and download credentials into your project folder
47+
- Create Credentials and secure the key to allow access to only the created api, and download credentials into your project folder.
4748

4849
- Preferrably procure multiple keys as the project will automatically cycles through keys, as their request quotas get exhausted.
4950
</details>
@@ -69,8 +70,8 @@ from your project.
6970
### Containerise app
7071
- This requires your machine to have Docker runtime installed. If it isnt already install by refering these
7172
- (Mac OS) https://docs.docker.com/docker-for-mac/install/
72-
(Windows) https://docs.docker.com/docker-for-windows/install/
73-
(Linux) https://docs.docker.com/engine/install/ (Browse by distributions)
73+
- (Windows) https://docs.docker.com/docker-for-windows/install/
74+
- (Linux) https://docs.docker.com/engine/install/ (Browse by distributions)
7475

7576
- Further Install docker compose
7677
https://docs.docker.com/compose/install/

controllers/findControllers.js

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// Importing axios module to make get requests
2+
var fetch = require('axios');
3+
4+
// Importing mongo model for storing search data and video details
5+
var searchData = require('../models/searchModel');
6+
var videoData = require('../models/videoModel').videoData;
7+
8+
// Search Function which regularly refreshes search results
9+
async function findByTitle(Query, title){
10+
11+
try{
12+
var searchDB = await searchData.findOne({ query: Query });
13+
14+
if(searchDB === null){
15+
16+
return null;
17+
}
18+
else{
19+
20+
var data;
21+
for(video in searchDB.videoDetails){
22+
if( searchDB.videoDetails[video].title == title ){
23+
data = searchDB.videoDetails[video];
24+
}
25+
}
26+
return data;
27+
}
28+
}
29+
catch(err){
30+
console.log(err);
31+
return err;
32+
}
33+
}
34+
35+
// Search Function which regularly refreshes search results
36+
async function findByDescription(Query, description){
37+
38+
try{
39+
var searchDB = await searchData.findOne({ query: Query });
40+
41+
if(searchDB === null){
42+
return null;
43+
}
44+
else{
45+
46+
var data;
47+
for(video in searchDB.videoDetails){
48+
if( searchDB.videoDetails[video].description == description ){
49+
data = searchDB.videoDetails[video];
50+
}
51+
}
52+
return data;
53+
}
54+
}
55+
catch(err){
56+
console.log(err);
57+
return err;
58+
}
59+
}
60+
61+
// Search Function which regularly refreshes search results
62+
async function findByTitleAndDescription(Query, title, description){
63+
64+
try{
65+
var searchDB = await searchData.findOne({ query: Query });
66+
67+
if(searchDB === null){
68+
return null;
69+
}
70+
else{
71+
72+
var data;
73+
for(video in searchDB.videoDetails){
74+
if( searchDB.videoDetails[video].title == title && searchDB.videoDetails[video].description == description){
75+
data = searchDB.videoDetails[video];
76+
}
77+
}
78+
return data;
79+
}
80+
}
81+
catch(err){
82+
console.log(err);
83+
return err;
84+
}
85+
}
86+
87+
88+
// Controller to provide results as per request
89+
const provideResults = async (req, res) => {
90+
var maxResults = 2;
91+
var Query = req.params.searchquery;
92+
93+
if(req.query.title && !req.query.description){
94+
95+
var title = req.query.title;
96+
var data = await findByTitle(Query, title);
97+
}
98+
else if(req.query.description && !req.query.title){
99+
100+
var description = req.query.description;
101+
var data = await findByDescription(Query, description);
102+
}
103+
else if(req.query.title && req.query.description){
104+
105+
var title = req.query.title;
106+
var description = req.query.description;
107+
var data = await findByTitleAndDescription(Query, title, description);
108+
}
109+
else{
110+
res.status(400).json({ response: "Please provide either title or description of the required video."});
111+
}
112+
113+
114+
if(data === null){
115+
res.status(400).json({ response: "Please search for a video only after obtaining results through Youtube Api, thus visit the /search/:query URL first."});
116+
}else{
117+
res.status(200).json(data);
118+
}
119+
}
120+
121+
module.exports = {
122+
provideResults
123+
}

0 commit comments

Comments
 (0)