Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code review #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion models/shows.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
// No tab necessary
mongoose.Promise = global.Promise;


var ShowSchema = new Schema({
Expand All @@ -10,6 +11,7 @@ var ShowSchema = new Schema({
poster: String,
overview: String,
backdrop: String,
// Should this be an vote count? or an array of users?
users: String
})

Expand Down
84 changes: 7 additions & 77 deletions public/scripts/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,25 @@ var allShows = [];
$(document).ready(function () {
console.log("JS is working")

// Notice how you use the same #shoeCheck 3 times in this file and it's the same
// for each use. You only need 1 for all requests.
// For example, you could have given the form a class named showCheck
// and then created 1 event for form submission.
// See HTML file for matching changes.


$('#showCheck').on('submit', function (e) {
$('.showCheck').on('submit', function (e) {
e.preventDefault();
showData = $(this).serialize();
search = (tvShow + showData);
$.ajax({
method: "GET",
// I think you intended to use the search variable here
url: tvShow + showData,
success: onSuccess,
error: onError
});
});

$('#showCheck1').on('submit', function (e) {
e.preventDefault();
showData = $(this).serialize();
search = (tvShow + showData);
$.ajax({
method: "GET",
url: tvShow + showData,
success: onSuccess1,
error: onError1
});
});

$('#showCheck2').on('submit', function (e) {
e.preventDefault();
showData = $(this).serialize();
search = (tvShow + showData);
$.ajax({
method: "GET",
url: tvShow + showData,
success: onSuccess2,
error: onError2
});
});

$('#enterUser').on('click', function (e) {
e.preventDefault();
var uData = $('#userName').val()
Expand Down Expand Up @@ -96,57 +77,6 @@ function onError(a, b, c) {
console.log(c);
}


function onSuccess1(json) {
console.log("SUCCESS: ", json.results[0]);
$("#showTarget1").empty();
$("#showTarget1").append('<img src="' + imgLocation + json.results[0].poster_path + '">');
$("#showTarget1").append('</br>')
$("#showTarget1").append(json.results[0].name);
$("#1Show").empty();
$("#1Date").empty();
$('#1Img').empty();
$("#1Overview").empty();
$('#1Backdrop').empty();
$("#1Show").val(json.results[0].name);
$("#1Date").val(json.results[0].first_air_date);
$('#1Img').val('<img src="' + imgLocation + json.results[0].poster_path + '">');
$('#1Poster').val('<img class="resize" src="' + imgPoster + json.results[0].poster_path + '">');
$("#1Overview").val(json.results[0].overview + ' ^');
$('#1Backdrop').val('<img src="' + backdropLocation + json.results[0].backdrop_path + '">');
$('#1vote').attr('hidden', false);
};

function onError1(a, b, c) {
console.log(b);
console.log(c);
}

function onSuccess2(json) {
console.log("SUCCESS: ", json.results[0]);
$("#showTarget2").empty();
$("#showTarget2").append('<img src="' + imgLocation + json.results[0].poster_path + '">');
$("#showTarget2").append('</br>')
$("#showTarget2").append(json.results[0].name);
$("#2Show").empty();
$("#2Date").empty();
$('#2Img').empty();
$("#2Overview").empty();
$('#2Backdrop').empty();
$("#2Show").val(json.results[0].name);
$("#2Date").val(json.results[0].first_air_date);
$('#2Img').val('<img src="' + imgLocation + json.results[0].poster_path + '">');
$('#2Poster').val('<img class="resize" src="' + imgPoster + json.results[0].poster_path + '">');
$("#2Overview").val(json.results[0].overview);
$('#2Backdrop').val('<img src="' + backdropLocation + json.results[0].backdrop_path + '">');
$('#2vote').attr('hidden', false);
};

function onError2(a, b, c) {
console.log(b);
console.log(c);
}

function handleSuccess(json) {
allShows = json;
console.log(allShows);
Expand Down
6 changes: 5 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ app.get('/', function homepage(req, res) {

//create a show
app.post('/api/shows', function (req, res) {
// Very interesting configuration you have going here :)
// But usually you will use your frontend (data.js) speak to your backend (server.js)
// and the backend will make all API requests. Backend usually handles the data.
var newShow = new db.Show({
show: req.body.show,
date: req.body.date,
img: req.body.img,
poster: req.body.poster,
overview: req.body.overview,
backdrop: req.body.backdrop,
// This would usually be req.body.user
users: req.body.users
});
newShow.save(function (err, show) {
Expand All @@ -59,7 +63,7 @@ app.get('/api/shows', function(req, res) {




// Faaaaar too many spaces here :)


app.listen(process.env.PORT || 3000, function () {
Expand Down
6 changes: 3 additions & 3 deletions views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@
<!-- api filter that pushs data to new form -->
<div class="row resposive">
<div class="col-md-4">
<form id="showCheck" class="checkForms border title" method="GET" action="https://api.themoviedb.org/3/search/tv?api_key=43e0d3b323afff75bed93507a243605d&language=en-US&page=1&">
<form class="checkForms border title showCheck" method="GET" action="https://api.themoviedb.org/3/search/tv?api_key=43e0d3b323afff75bed93507a243605d&language=en-US&page=1&">
<input name="query" id="input" accept="" placeholder="Halt and Catch Fire" >
<input type="submit" id="check" value="Check" class="btn-primary" >
<h3 id="showTarget">
</h3>
</form>
</div>
<div class="col-md-4">
<form id="showCheck1" class="checkForms border" method="GET" action="https://api.themoviedb.org/3/search/tv?api_key=43e0d3b323afff75bed93507a243605d&language=en-US&page=1&">
<form class="checkForms border showCheck" method="GET" action="https://api.themoviedb.org/3/search/tv?api_key=43e0d3b323afff75bed93507a243605d&language=en-US&page=1&">
<input name="query" id="1input" placeholder="Mr. Robot" >
<input type="submit" id="1check" value="Check" class="btn-primary">
<h3 id="showTarget1">
</h3>
</form>
</div>
<div class="col-md-4">
<form id="showCheck2" class="checkForms border" method="GET" action="https://api.themoviedb.org/3/search/tv?api_key=43e0d3b323afff75bed93507a243605d&language=en-US&page=1&">
<form class="checkForms border showCheck" method="GET" action="https://api.themoviedb.org/3/search/tv?api_key=43e0d3b323afff75bed93507a243605d&language=en-US&page=1&">
<input name="query" id="2input" placeholder="Silicon Valley" >
<input type="submit" id="2check" value="Check" class="btn-primary">
<h3 id="showTarget2">
Expand Down