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

Feedback #1

Open
wants to merge 66 commits into
base: feedback
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
72f2e9f
Setting up GitHub Classroom Feedback
github-classroom[bot] Nov 22, 2022
128d71d
initial commit.
dcheris Nov 22, 2022
a32d52c
server foundation.
dcheris Nov 22, 2022
c062b88
setting routes/middleware.
dcheris Nov 22, 2022
99df937
correcting routing
dcheris Nov 22, 2022
a7c00c4
adding bootstrap css.
dcheris Nov 25, 2022
d718cea
adding bcrypt to see if I can implement it as a password security man…
dcheris Nov 25, 2022
e6cfd1b
adding a create page.
dcheris Nov 25, 2022
4362520
adding a database js file.
dcheris Nov 25, 2022
cf36dba
correcting routing files.
dcheris Nov 25, 2022
1fa1a96
completing basic routing.
dcheris Nov 25, 2022
eb2de04
completeing basic routing.
dcheris Nov 25, 2022
7781cba
completing basic routing.
dcheris Nov 25, 2022
c74a8fc
completing basic routing.
dcheris Nov 25, 2022
cf37d33
completing basic routing.
dcheris Nov 25, 2022
0f8c19a
correcting routing.
dcheris Nov 25, 2022
c88af3e
adding jade files for routes.
dcheris Nov 25, 2022
125e8dc
adding database functions.
dcheris Nov 25, 2022
43024e5
adding database
dcheris Nov 25, 2022
7f232f2
Added handlebars.
dcheris Nov 26, 2022
e9eb167
still working on CRUD.
dcheris Nov 26, 2022
8b64d7c
made a new branch to successfully route from scratch.
dcheris Nov 27, 2022
81216c6
getting forms to display data, and some css.
dcheris Nov 27, 2022
ae9dd7d
create, delete, and retrieve work in application but not in display.
dcheris Nov 28, 2022
5be1ff1
pushing new code to remote repo.
dcheris Dec 2, 2022
5b3c21e
trying to get the pages to display data.
dcheris Dec 4, 2022
14a7fe8
starting over on new branch.
dcheris Dec 4, 2022
0712b2e
Fixed routing and got anime to display.
dcheris Dec 4, 2022
8d15395
working on update functionality.
dcheris Dec 5, 2022
68cb884
added a description box, fixed css not rendering, update function is …
dcheris Dec 5, 2022
077dba4
fixing update and delete.
dcheris Dec 5, 2022
89dbbd7
fixing update for sql
dcheris Dec 5, 2022
5d12287
adding notes.
dcheris Dec 6, 2022
c096ac3
merging start-over branch into main.
dcheris Dec 6, 2022
9ffd52e
still working on the update function.
dcheris Dec 6, 2022
6a7ca08
adding ignore file.
dcheris Dec 13, 2022
5eb50ad
adding procfile.
dcheris Dec 13, 2022
cc603f6
fixed update function.
dcheris Dec 15, 2022
bf92bd7
adding views for authentication.
dcheris Dec 15, 2022
995e89c
adding mongoose foundation.
dcheris Dec 16, 2022
b2a5698
adding Heroku link to readme.
dcheris Dec 17, 2022
1fd0c9e
fixing deployment.
dcheris Dec 17, 2022
aeae34d
changing a config file.
dcheris Dec 17, 2022
166eab3
modifying ignore files.
dcheris Dec 17, 2022
3660def
correcting for deployment.
dcheris Dec 17, 2022
c700525
recommitting.
dcheris Dec 17, 2022
9245ebc
gitignore.
dcheris Dec 17, 2022
d68fa5a
config files.
dcheris Dec 17, 2022
de21298
config.
dcheris Dec 17, 2022
2f4c22c
package file.
dcheris Dec 17, 2022
d2721e3
fixing procfile.
dcheris Dec 17, 2022
07c4027
procfile.
dcheris Dec 17, 2022
438e445
config.
dcheris Dec 17, 2022
d0b190b
delete.
dcheris Dec 17, 2022
aa7f91e
config.
dcheris Dec 17, 2022
d9e0f90
config
dcheris Dec 17, 2022
5ffed83
connecting to mongoose.
dcheris Dec 18, 2022
ace6293
implementing passport.
dcheris Dec 18, 2022
8372137
working on authentication.
dcheris Dec 19, 2022
759d604
fixing for heroku.
dcheris Dec 19, 2022
f1dd8fc
adding procfile again.
dcheris Dec 19, 2022
52f7109
heroku
dcheris Dec 19, 2022
59de8ad
re-adding home page.
dcheris Dec 19, 2022
bae870a
re-adding env.
dcheris Dec 19, 2022
8a662bc
env
dcheris Dec 19, 2022
18d5f54
env2
dcheris Dec 19, 2022
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
Prev Previous commit
Next Next commit
Fixed routing and got anime to display.
  • Loading branch information
dcheris committed Dec 4, 2022
commit 0712b2eb78859c114a484ff53470c78945c5b267
Binary file modified animedb.db
Binary file not shown.
89 changes: 39 additions & 50 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,61 @@
var createError = require('http-errors');
const express = require('express');
const app = express();
const dbOperations = require('./database.js');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
const port = 3000

var indexRouter = require('./routes/index');
var createRouter = require('./routes/create');
var addRouter = require('./routes/add');
var displayRouter = require('./routes/display');
var updateRouter = require('./routes/update');

var app = express();
/**To serve static files such as images, CSS files, and JavaScript files, create a folders
* and include the below statement. The below statement assumes that I have a folder named assets
**/
app.use(express.static('assets'))

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');
app.set("view engine", "hbs");

app.use(logger('dev'));
// parse application/json
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

// For parsing application/x-www-form-urlencoded
app.use(express.urlencoded({ extended: true }))

// ROUTE TO HOME PAGE
app.get('/', function (req, res) {
dbOperations.getAnime(res)

res.render('index',{
title: "ANIME DATABASE"
})
dbOperations.getAnime(res);
})

app.use('/', indexRouter);
app.use('/display', displayRouter);
app.use('/create', createRouter);
app.use('/add', addRouter);
app.use('/update', updateRouter);

app.post('/add', function (req,res) {
res.render('index', {title: 'ANIME DATABASE'})

const {animeID,animeName,releaseYear,genre,rating} = req.body;
// ROUTE TO UPDATE PAGE
app.get('/update', function (req, res) {

dbOperations.createItem(animeID,animeName,releaseYear,genre,rating);
dbOperations.getAnime(res);
})

app.post('/delete', function (req,res) {
res.render('index', {title: 'ANIME DATABASE'})
// ROUTE TO CREATE ANIME LIST ITEM
app.post('/create', function (req, res) {

const {deleterecord} = req.body;
// GETTING BODY PARAMETERS
const {anime_name,release_year,genre,rating}= req.body;

// EXECUTE createItems METHOD
dbOperations.createItem(anime_name,release_year,genre,rating, res);

})

// ROUTE TO DELETE ANIME ITEM
app.post('/delete', function (req, res) {
// GETTING BODY PARAMETERS
const {deleterecord}= req.body;
dbOperations.deleteItem(deleterecord);
})

// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});
})

// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// ROUTE TO UPDATE ANIME LIST ITEM
app.post('/update', function (req, res) {

// render the error page
res.status(err.status || 500);
res.render('error');
});
// GETTING BODY PARAMETERS
const {anime_name,release_year,genre,rating}= req.body;
dbOperations.updateItem(anime_name,release_year,genre,rating);

module.exports = app;
})

module.exports = app;
69 changes: 69 additions & 0 deletions database.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,72 @@ let db = new sqlite3.Database('./animedb.db', sqlite3.OPEN_READWRITE, (err) => {
}
});

// CREATE ANIME ITEM
let createItem = (anime_name,release_year,genre,rating,res) =>{
var createAnimeItem = `INSERT INTO anime_items(anime_name,release_year,genre,rating) VALUES (?,?,?,?)` // PARAMETERIZED QUERY
var params = [anime_name,release_year,genre,rating];

db.run(createAnimeItem,params,function(err){

if(err){
return console.log(err.message);
}
getAnime(res);
})

}


// DISPLAY ALL ANIME
let getAnime = (res) => {
var getAllAnimeItems = 'SELECT animeID,anime_name,release_year,genre,rating FROM anime_items';
db.all(getAllAnimeItems, function(err, rows){
if (err) {

throw err;
}
console.log(rows);
res.render('index', {rows})

})

}

// UPDATE ANIME ITEM

let updateItem = (recordToUpdate,res) =>{
var updateAnimeItem = 'UPDATE anime_items SET anime_name = ? WHERE animeID = ?';
var params = [recordToUpdate];

db.run(updateAnimeItem, function(err){
if (err){
return console.log(err.message);
}


console.log("Anime Updated");
console.log(`Rows updated ${this.changes}`);
});

getAnime(res);

}
// DELETE ANIME ITEM
let deleteItem = (recordToDelete,res) =>{

var deleteAnimeItem = 'DELETE FROM anime_items WHERE animeID = ?';

var params = [recordToDelete];
db.run(deleteAnimeItem,params,function(err){

if(err){
return console.log(err.message);
}
console.log("Anime Item Deleted");
console.log('Rows deleted ${this.changes}');
});
}


module.exports = {createItem,updateItem,getAnime,deleteItem}

4 changes: 2 additions & 2 deletions model/anime.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var anime = {

animeID: "",
animeName: "",
releaseYear: "",
anime_name: "",
release_year: "",
genre: "",
rating: ""

Expand Down
4 changes: 2 additions & 2 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'ANIME DATABASE' });
res.render('index', ('Anime Database'));
});

module.exports = router;
module.exports = router;
50 changes: 48 additions & 2 deletions views/index.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<nav class="navbar navbar-expand-xl navbar-dark" style="background-color: #0C0D08;">
<a class="navbar-brand" href="/">{{title}}</a>
<a class="navbar-brand" href="/">Anime Database</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
Expand All @@ -21,4 +21,50 @@
</nav>


<h2>Welcome to the {{title}} where you can help us enter,update and delete anime!</h2>

<body>
<div id="container">
<h1>Enter Anime Item</h1>
<form action="/create" method="POST">
<input type="text" name="anime_name" class="form-control" placeholder="Enter Anime Name (ex. Naruto)" size="40"><br>
<input type="number" min="1900" max="2099" step="1" name="release_year" class="form-control" placeholder="Enter Anime Release Date (ex. 2022)" size="40"><br>
<input type="text" name="genre" class="form-control" placeholder="Enter Anime Genre (ex. Slice-of-life)" size="40"><br>
<input type="number" step="0.01"class="form-control" name="rating" placeholder="Enter a rating" size="40"><br>
<input type="submit" class="btn btn-primary" value="submit">
</form>

<!-- Display Anime Items -->
<h2>ANIME LIST</h2>
<table style="margin: 20px;">
<tr>
<th>ANIME ID</th>
<th>TITLE</th>
<th>RELEASE YEAR</th>
<th>GENRE</th>
<th>RATING</th>
</tr>
{{#each rows}}
<tr>
<td>{{this.animeID}}</td>
<td>{{this.anime_name}}</td>
<td>{{this.release_year}}</td>
<td>{{this.genre}}</td>
<td>{{this.rating}}</td>
<td>
<div class="button-container">
<form action="/update_item" method="POST">
<button name="updaterecord" id="update" type="submit" class="btn btn-success" value="{{this.animeID}}">UPDATE</button>
</form>
<form action="/delete_item" method="POST">
<button name="deleterecord" id="deletenow" type="submit" class="btn btn-danger" value="{{this.animeID}}">DELETE</button>
</form>
</div>
</td>

</tr>
{{/each}}
</table>
</div>
</body>

</html>