Skip to content
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
74 changes: 0 additions & 74 deletions api/controllers/EmployeeController.js

This file was deleted.

149 changes: 149 additions & 0 deletions api/controllers/MovieController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/**
* EmployeeController
*
* @description :: Server-side logic for managing employees
* @help :: See http://sailsjs.org/#!/documentation/concepts/Controllers
*/

var Client = require('node-rest-client').Client;
var client = new Client();
var endpoint = "http://localhost:1337/movies"

module.exports = {

/**
* `MovieController.create()`
*/
create: function (req, res)
{

if(req.method != "POST")
{
return res.view('create');
}

var args =
{
data: req.body,
headers: { "Content-Type": "application/json" }
};

client.post(endpoint, args, function (data, response)
{
//return res.view('create', {success: { message: "Record added successfully"}});
if(response.statusCode != "201")
{
return res.view('create', {error:{message: response.statusMessage + ": " + data.reason}});
}

return res.view('create', {success:{message: "Record created successfully"}});

})
},






/**
* `MovieController.read()`
*/
read: function (req, res)
{

client.get(endpoint, function (data, response)
{
return res.view('read', {movies: data});
}).on('error', function (err) {
return res.view('read', {error: { message: "There was an error getting the records"}});
});

},





/**
* `MovieController.update()`
*/
update: function (req, res) {

var values = req.allParams();
var modifiedEndpoint = "http://localhost:1337/movies/" + values.id;

//this calls the data you need to update
if(req.method != "POST"){
client.get(endpoint, function (data, response) {
return res.view('update', {movies: data});
}).on('error', function (err) {
return res.view('update', {error: { message: "There was an error getting the records"}});
});

}else{
var args = {
data: req.body,
headers: { "Content-Type": "application/json" }
};
//this actually updates
client.put(modifiedEndpoint, args, function (data, response) {
//return res.view('create', {success: { message: "Record edited successfully"}});
if(response.statusCode != "200"){
return res.view('update', {error:{message: response.statusMessage + ": " + data.reason}});
}
return res.redirect('back');
return res.view('update', {success:{message: "Record edited successfully"}});

})
}


},










/**
* `MovieController.delete()`
*/
delete: function (req, res) {


var values = req.allParams();
var modifiedEndpoint = "http://localhost:1337/movies/" + values.id;

//this calls the data you need to delete and populates the table
if(req.method != "POST"){
client.get(endpoint, function (data, response) {
return res.view('delete', {movies: data});
}).on('error', function (err) {
return res.view('delete', {error: { message: "There was an error getting the records"}});
});

}else{
var args = {
data: req.body,
headers: { "Content-Type": "application/json" }
};
//this actually deletes
client.delete(modifiedEndpoint, args, function (data, response) {
//return res.view('create', {success: { message: "Record delete successfully"}});
if(response.statusCode != "200"){
return res.view('delete', {error:{message: response.statusMessage + ": " + data.reason}});
}
return res.redirect('back');
return res.view('delete', {success:{message: "Record deleted successfully"}});

})
}
}
};


8 changes: 4 additions & 4 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ module.exports.routes = {
* *
***************************************************************************/

'/create':'EmployeeController.create',
'/' :'EmployeeController.read',
'/update':'EmployeeController.update',
'/delete':'EmployeeController.delete'
'/create':'MovieController.create',
'/' :'MovieController.read',
'/update':'MovieController.update',
'/delete':'MovieController.delete'

/***************************************************************************
* *
Expand Down
52 changes: 18 additions & 34 deletions views/create.ejs
Original file line number Diff line number Diff line change
@@ -1,69 +1,53 @@
<ol class="breadcrumb">
<li><a href="/">Home</a></li>
<li class="active">Add Employee</a></li>
<li><a href="/">Add a Movie</a></li>
<li class="active">Add A Movie</a></li>
</ol>

<br/>
<%- partial ('partials/statusmessage.ejs') %>

<h2>Add Employee</h2>
<h2>Add Movie</h2>
<form action="/create" method="POST" class="form-horizontal">
<div class="form-group">
<label for="firstName" class="col-sm-2 control-label">First Name</label>
<label for="title" class="col-sm-2 control-label">Movie Title</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="firstName" name="firstName" placeholder="First Name">
<input type="text" class="form-control" id="title" name="title" placeholder="Movie Title">
</div>
</div>
<div class="form-group">
<label for="lastName" class="col-sm-2 control-label">First Name</label>
<label for="rating" class="col-sm-2 control-label">MPAA Rating</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="lastName" name="lastName" placeholder="Last Name">
<input type="text" class="form-control" id="rating" name="rating" placeholder="MPAA Rating">
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email Address</label>
<label for="year" class="col-sm-2 control-label">Release Year</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" placeholder="[email protected]">
<input type="text" class="form-control" id="year" name="year" placeholder="Release Year">
</div>
</div>
<div class="form-group">
<label for="homePhone" class="col-sm-2 control-label">Home Phone</label>
<label for="genre" class="col-sm-2 control-label">Genre</label>
<div class="col-sm-10">
<input type="phone" class="form-control" id="homePhone" name="homePhone" placeholder="###-###-####">
<input type="text" class="form-control" id="genre" name="genre" placeholder="Genre">
</div>
</div>
<div class="form-group">
<label for="cellPhone" class="col-sm-2 control-label">Cell Phone</label>
<label for="director" class="col-sm-2 control-label">Director</label>
<div class="col-sm-10">
<input type="phone" class="form-control" id="cellPhone" name="cellPhone" placeholder="###-###-####">
<input type="text" class="form-control" id="director" name="director" placeholder="Director">
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-2 control-label">Password</label>
<label for="imbdRating" class="col-sm-2 control-label">IMBD Rating</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="password" name="password" aria-describedby="helpBlock">
<span id="helpBlock" class="help-block">Password at least 8 characters, 1 upppercase, 1 lowercase, and one number</span>
<input type="text" class="form-control" id="imbdRating" name="imbdRating" aria-describedby="helpBlock">
<span id="helpBlock" class="help-block">Score must be entered as a rational number between 0-10. (#.#)</span>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="radio">
<label>
<input type="radio" name="active" id="active1" value="1" checked>
Active
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="active" id="active2" value="0">
Inactive
</label>
</div>
<button type="submit" class="btn btn-default">Add Movie</button>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Add Employee</button>
</div>
</div>
</form>
</form>
52 changes: 52 additions & 0 deletions views/delete.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<ol class="breadcrumb">
<li><a href="/">Delete A Movie</a></li>
<li class="active">Delete A Movie</a></li>
</ol>

<br/>
<%- partial ('partials/statusmessage.ejs') %>
<h2>Movie Database</h2>
<table class="table table-striped table-bordered">
<tr>
<th>ID</th>
<th>Movie Title</th>
<th>MPAA Rating</th>
<th>Release Year</th>
<th>Genre</th>
<th>Director</th>
<th>IMBD Rating (score/10)</th>
</tr>
<% if(typeof movies != "undefined" && movies.length > 0){ %>
<% movies.forEach(function(movie){ %>
<tr>
<td><%= movie.id %></td>
<td><%= movie.title %></td>
<td><%= movie.rating %></td>
<td><%= movie.year %></td>
<td><%= movie.genre %></td>
<td><%= movie.director %></td>
<td><%= movie.imbdRating %></td>
</tr>
<% }) %>
<% }else{ %>
<tr>
<td colspan="7">0 records found</td>
</tr>
<% } %>

</table>
<br>
<h2>Delete Movie</h2>
<form action="/delete" method="POST" class="form-horizontal">
<div class="form-group">
<label for="id" class="col-sm-2 control-label">Movie ID</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="id" name="id" placeholder="Movie ID">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Delete Movie</button>
</div>
</div>
</form>
4 changes: 2 additions & 2 deletions views/layout.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Employee Admin</title>
<title>Movie IMBD Database</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<style>
Expand All @@ -25,7 +25,7 @@
}
</style>
</head>
<body>
<body style="background-color: 784100">

<!-- Fixed navbar -->
<%- partial ('partials/navigation.ejs') %>
Expand Down
Loading