Skip to content

Commit

Permalink
add edits to structure
Browse files Browse the repository at this point in the history
  • Loading branch information
BikeMouse committed Sep 18, 2022
1 parent 9e920c3 commit 75bae64
Show file tree
Hide file tree
Showing 11 changed files with 260 additions and 8 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
node_modules
.env
.vscode
views
.vscode
26 changes: 26 additions & 0 deletions models/Comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const mongoose = require("mongoose");

const CommentSchema = new mongoose.Schema({
comment: {
type: String,
required: true,
},
likes: {
type: Number,
required: true,
},
user: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
},
createdAt: {
type: Date,
default: Date.now,
},
post: {
type: mongoose.Schema.Types.ObjectId,
ref: "Post",
},
});

module.exports = mongoose.model("Comment", CommentSchema);
12 changes: 6 additions & 6 deletions models/Post.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
const mongoose = require("mongoose");

const PostSchema = new mongoose.Schema({
title: {
user: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
},
recipename: {
type: String,
required: true,
},
Expand All @@ -13,18 +17,14 @@ const PostSchema = new mongoose.Schema({
type: String,
require: true,
},
caption: {
procedure: {
type: String,
required: true,
},
likes: {
type: Number,
required: true,
},
user: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
},
createdAt: {
type: Date,
default: Date.now,
Expand Down
15 changes: 15 additions & 0 deletions views/feed.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<%- include('partials/header') -%>
<div class="container">
<div class="row justify-content-center mt-5">
<ul class="row list-unstyled">
<% for(var i=0; i<posts.length; i++) {%>
<li class="col-6 justify-content-between mt-5">
<a href="/post/<%= posts[i]._id%>">
<img class="img-fluid" src="<%= posts[i].image%>">
</a>
</li>
<% } %>
</ul>
</div>
</div>
<%- include('partials/footer') -%>
11 changes: 11 additions & 0 deletions views/index.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%- include('partials/header') -%>

<main class="container">
<div class="row justify-content-around mt-5">
<a href="/login" class="col-3 btn btn-primary"> Login</a>
<a href="/signup" class="col-3 btn btn-primary"> Signup</a>
</div>
</main>


<%- include('partials/footer') -%>
40 changes: 40 additions & 0 deletions views/login.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<%- include('partials/header') -%>

<main class="container">
<div class="row justify-content-center">
<section class="col-6 mt-5">
<% if (locals.messages.errors) { %> <% messages.errors.forEach( el => { %>
<div class="alert alert-danger"><%= el.msg %></div>
<% }) %> <% } %> <% if (locals.messages.info) { %> <%
messages.info.forEach( el => { %>
<div class="alert alert-info"><%= el.msg %></div>
<% }) %> <% } %>
<form action="/login" method="POST">
<div class="mb-3">
<label for="exampleInputEmail1" class="form-label"
>Email address</label
>
<input
type="email"
class="form-control"
id="exampleInputEmail1"
aria-describedby="emailHelp"
name="email"
/>
</div>
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">Password</label>
<input
type="password"
class="form-control"
id="exampleInputPassword1"
name="password"
/>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</section>
</div>
</main>

<%- include('partials/footer') -%>
3 changes: 3 additions & 0 deletions views/partials/footer.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" crossorigin="anonymous"></script>
</body>
</html>
36 changes: 36 additions & 0 deletions views/partials/header.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Baking Mice Unite!</title>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/imgs/favicon-32x32.png"
/>
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6"
crossorigin="anonymous"
/>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"
integrity="sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w=="
crossorigin="anonymous"
/>
<link rel="stylesheet" href="/css/style.css" />
</head>
<body>
<header class="container">
<div class="text-center">
<h1 class=""><a href="/profile">Baking Mice Unite!</a></h1>
<span>Your Online Recipe Book!</span>
</div>
</header>
</body>
</html>
37 changes: 37 additions & 0 deletions views/post.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<%- include('partials/header') -%>
<div class="container">
<div class="row justify-content-center mt-5">
<div class="col-6">
<h2><%= post.title %></h2>
<img class="img-fluid" src="<%= post.image%>" />
<div class="row justify-content-between">
<form
class="col-1"
action="/post/likePost/<%= post.id %>?_method=PUT"
method="POST"
>
<button class="btn btn-primary fa fa-heart" type="submit"></button>
</form>
<h3 class="col-3">Likes: <%= post.likes %></h3>
<%if(post.user == user.id){ %>
<form
action="/post/deletePost/<%= post.id %>?_method=DELETE"
method="POST"
class="col-3"
>
<button class="btn btn-primary fa fa-trash" type="submit"></button>
</form>
<%}%>
</div>
</div>
<div class="col-3 mt-5">
<p><%= post.caption %></p>
</div>
<div class="col-6 mt-5">
<a class="btn btn-primary" href="/profile">Return to Profile</a>
<a class="btn btn-primary" href="/feed">Return to Feed</a>
</div>
</div>
</div>

<%- include('partials/footer') -%>
46 changes: 46 additions & 0 deletions views/profile.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<%- include('partials/header') -%>
<div class="container">
<div class="row mt-5">
<div class="col-6">
<div>
<p><strong>User Name</strong>: <%= user.userName %></p>
<p><strong>Email</strong>: <%= user.email %></p>
<a href="/logout" class="col-3 btn btn-primary">Logout</a>
</div>
<div class="mt-5">
<h2>Add a recipe</h2>
<form action="/post/createPost" enctype="multipart/form-data" method="POST">
<div class="mb-3">
<label for="title" class="form-label">Recipe name</label>
<input type="text" class="form-control" id="recipename" name="recipename">
</div>
<div class="mb-3">
<label for="procedure" class="form-label">Procedure</label>
<textarea class="form-control" id="procedure" name="procedure"></textarea>
</div>
<div class="mb-3">
<label for="imgUpload" class="form-label">Image</label>
<input type="file" class="form-control" id="imageUpload" name="file">
</div>
<button type="submit" class="btn btn-primary" value="Upload">Submit</button>
</form>
</div>
</div>
<div class="col-6">
<ul class="row list-unstyled">
<% for(var i=0; i<posts.length; i++) {%>
<li class="col-6 justify-content-between mt-5">
<a href="/post/<%= posts[i]._id%>">
<img class="img-fluid" src="<%= posts[i].image%>">
</a>
</li>
<% } %>
</ul>
<div class="row justify-content-center mt-5">
<a class="btn btn-primary" href="/feed">Return to Feed</a>
</div>
</div>
</div>
</div>
</div>
<%- include('partials/footer') -%>
39 changes: 39 additions & 0 deletions views/signup.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<%- include('partials/header') -%>
<main class="container">
<div class="row justify-content-center">
<section class="col-6 mt-5">
<% if (locals.messages.errors) { %>
<% messages.errors.forEach( el => { %>
<div class="alert alert-danger"><%= el.msg %></div>
<% }) %>
<% } %>
<% if (locals.messages.info) { %>
<% messages.info.forEach( el => { %>
<div class="alert alert-info"><%= el.msg %></div>
<% }) %>
<% } %>
<form action="/signup" method="POST">
<div class="mb-3">
<label for="userName" class="form-label">User Name</label>
<input type="text" class="form-control" id="userName" name="userName">
</div>
<div class="mb-3">
<label for="exampleInputEmail1" class="form-label">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" name="email">
<div id="emailHelp" class="form-text">We'll never share your email with anyone else.</div>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password">
</div>
<div class="mb-3">
<label for="confirmPassword" class="form-label">Confirm Password</label>
<input type="password" class="form-control" id="confirmPassword" name="confirmPassword">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</section>
</div>
</main>

<%- include('partials/footer') -%>

0 comments on commit 75bae64

Please sign in to comment.