-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Michael's Instagram Challenge #917
Open
mcsuGH
wants to merge
19
commits into
makersacademy:main
Choose a base branch
from
mcsuGH:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+15,188
−72
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1e856aa
initial README
mcsuGH b0cd7f3
initial project setup files and routes
mcsuGH 0f453a6
wrote and passed first test to show title on homepage, added some oth…
mcsuGH 84de197
added user tests and passed them, including needing unique email to s…
mcsuGH 4bddf0e
added integration tests and passed them for logging in and registering
mcsuGH e707ea2
fixed an issue where req.body was not sending anything, will need to …
mcsuGH dddd0b3
wrote and passed unit tests for posts, will currently only take image…
mcsuGH 77deae5
passed integration test for posting a picture
mcsuGH 9073b50
added and passed test to show a page containing post info
mcsuGH 128fef6
added and passed test to delete a post
mcsuGH f1e8816
wrote test to add like
mcsuGH 1a42c02
passed test to like post
mcsuGH b238cf4
updated README
mcsuGH 93fc39c
wrote tests for comments
mcsuGH 1d8a4a0
unit tests passed for comments
mcsuGH 32d51bc
wrote integration test for posting comment
mcsuGH f213774
passed integration test for posting comments
mcsuGH 18797fb
all tests passing, added very small amount of css, updated README
mcsuGH 73c5811
fixed images in readme
mcsuGH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
"env": { | ||
"browser": true, | ||
"commonjs": true, | ||
"es2021": true | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": "latest" | ||
}, | ||
"rules": { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
# next.js build output | ||
.next | ||
|
||
# cypress.io | ||
cypress/screenshots | ||
cypress/videos |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,68 @@ | ||
Instagram Challenge | ||
=================== | ||
|
||
## Instructions | ||
|
||
* Feel free to use Google, your notes, books, etc., but work on your own | ||
* If you refer to the solution of another coach or student, please put a link to that in your README | ||
* If you have a partial solution, **still check in a partial solution** | ||
* You must submit a pull request to this repo with your code by 9am Monday morning | ||
# Instagram Challenge | ||
``` | ||
.-------------------. | ||
/--"--.------.------/| | ||
|Kodak|__Ll__| [==] || | ||
| | .--. | """" || | ||
| |( () )| || | ||
| | `--' | |/ | ||
`-----'------'------' | ||
``` | ||
|
||
## Task | ||
I have been tasked to create a web app that will work similar to Instagram - users will be able to sign up and be able to post pictures which can be liked and commented on. | ||
|
||
Build Instagram: Simple huh! | ||
|
||
Your challenge is to build Instagram using Rails. You'll need **users** who can post **pictures**, write **comments** on pictures and **like** a picture. Style it like Instagram's website (or more awesome). | ||
|
||
Bonus if you can add filters! | ||
## Instructions | ||
Clone this repository to your desired location using `git clone https://github.com/mcsuGH/instagram-challenge.git`.\ | ||
\ | ||
Make sure you have the most recent update of Node and then you can run `npm install` whilst in the main directory in your terminal to install dependencies.\ | ||
\ | ||
You can run tests by using the command `npm run start:test` to load up the test server then using `npm test` to run the test files. Note that tests are dependent on being run like this - for example some integration tests use the fact that previous unit tests made posts in order for the integration tests to work, or that some integration tests depend on previous integration tests.\ | ||
\ | ||
You will need to have mongoDB to be able to run this web app in it's intended manner, you can run the commands `brew tap mongodb/brew` and then `brew install [email protected]` in order to install mongoDB.\ | ||
\ | ||
In order to access for the website to function, you will need to run the server on localhost by using `npm start` and then going on `localhost:2800` to access the website. From there, you will be able to make an account and those account details will then be stored on your local database.\ | ||
\ | ||
You will be able to post pictures so make sure to clear the database every so often so that it does not take up too much space - to do this, open `mongo` in the terminal, use the command `use instagram` (or `use instagram_test` if you wish to access the test database, although that gets cleared every time tests are ran) to access the instagram database, then you can use `db.users.drop()` and `db.posts.drop()` to clear the database. Note: currently storing images inside the database is not working (currently storing urls of images) but you can still clear the database if you wish.\ | ||
\ | ||
Here are some images to show what it looks like: | ||
![Screenshot](https://i.imgur.com/h9QYDfg.png) | ||
![Screenshot](https://i.imgur.com/8AsVFYR.png) | ||
|
||
## How to start | ||
## User Stories | ||
``` | ||
As a User, | ||
So that nobody else can use my account, | ||
I would like to be able to log out | ||
|
||
1. Produce some stories, break them down into tasks, and estimate | ||
2. Fork this repo, clone, etc | ||
3. Initialize a new rails project | ||
As a User, | ||
So that I can share pictures to other people, | ||
I would like to be able to post pictures | ||
|
||
Remember to proceed in small steps! Getting confused? Make the steps even smaller. | ||
As a User, | ||
So that I can interact with people I like, | ||
I would like to be able to comment on pictures | ||
|
||
## Code Quality | ||
As a User, | ||
So that I can give other people my approval, | ||
I would like to be able to like their pictures | ||
|
||
For linting, you can use the `.rubocop.yml` in this repository (or your own!). | ||
You'll need these gems: | ||
Bonus: | ||
As a User, | ||
So that I can make my pictures look even better, | ||
I would like to be able to add filters to them | ||
``` | ||
|
||
```ruby | ||
group :development, :test do | ||
gem 'rubocop', '1.20', require: false | ||
gem 'rubocop-rails' | ||
end | ||
## References | ||
``` | ||
https://www.asciiart.eu/electronics/cameras | ||
https://geeksforgeeks.org/upload-and-retrieve-image-on-mongodb-using-mongoose/ | ||
``` | ||
used the above for the ASCII art, made by Joan Starks\ | ||
used the above to upload and retrieve images in mongoDB - abandoned for now, would make my req.body empty for some reason making my posts empty. | ||
|
||
You can also lint Javascript, CSS, and ERB — feel free to research this. These | ||
will help you to train yourself to produce cleaner code — and will often alert | ||
you to mistakes or mishaps! | ||
## Functionality yet to be added | ||
- add more CSS - currently only added a bar at the top and a background for the post images, displaying the images in rows of 3. | ||
- make it so each user can only like a post once (would just need to create a new collection for likes inside database with foreign keys for the post and the user who liked the post) | ||
- add filter function | ||
- add the ability to upload images onto the database rather than using a external image host | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
var createError = require('http-errors'); | ||
var express = require('express'); | ||
var path = require('path'); | ||
var cookieParser = require('cookie-parser'); | ||
var logger = require('morgan'); | ||
const session = require("express-session"); | ||
const methodOverride = require("method-override"); | ||
var hbs = require('hbs'); | ||
const moment = require('moment'); | ||
const multer=require('multer'); | ||
var bodyParser = require('body-parser'); | ||
|
||
const homeRouter = require("./routes/home"); | ||
const postsRouter = require("./routes/posts"); | ||
const sessionsRouter = require("./routes/sessions"); | ||
const usersRouter = require("./routes/users"); | ||
|
||
var app = express(); | ||
|
||
// view engine setup | ||
app.set('views', path.join(__dirname, 'views')); | ||
app.set('view engine', 'hbs'); | ||
|
||
app.use(logger('dev')); | ||
app.use(express.json()); | ||
app.use(express.urlencoded({ extended: false })); | ||
app.use(cookieParser()); | ||
app.use(express.static(path.join(__dirname, 'public'))); | ||
app.use(methodOverride("_method")); | ||
app.use(bodyParser.urlencoded({ extended: false })) | ||
app.use(bodyParser.json()) | ||
|
||
app.use( | ||
session({ | ||
key: "user_sid", | ||
secret: "super_secret", | ||
resave: false, | ||
saveUninitialized: false, | ||
cookie: { | ||
expires: 600000, | ||
}, | ||
}) | ||
); | ||
|
||
// Helper functions | ||
hbs.registerHelper('formatDate', function(dateString) { | ||
return new hbs.SafeString( | ||
'at ' + moment(dateString).format("HH:mm") +' on ' + moment(dateString).format("MMM D") + ' ' + moment(dateString).format("YYYY") | ||
); | ||
}); | ||
|
||
hbs.registerHelper('ifEqual', function(userId, postId) { | ||
if (userId === postId) { | ||
return true | ||
} | ||
return false | ||
}) | ||
|
||
// clear the cookies after user logs out | ||
app.use((req, res, next) => { | ||
if (req.cookies.user_sid && !req.session.user) { | ||
res.clearCookie("user_sid"); | ||
} | ||
next(); | ||
}); | ||
|
||
// middleware function to check for logged-in users | ||
const sessionChecker = (req, res, next) => { | ||
if (!req.session.user && !req.cookies.user_sid) { | ||
res.redirect("/sessions/new"); | ||
} else { | ||
next(); | ||
} | ||
}; | ||
|
||
// route setup | ||
app.use("/", homeRouter); | ||
app.use("/posts", sessionChecker, postsRouter); | ||
app.use("/sessions", sessionsRouter); | ||
app.use("/users", usersRouter); | ||
|
||
// 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 : {}; | ||
|
||
// render the error page | ||
res.status(err.status || 500); | ||
res.render('error'); | ||
}); | ||
|
||
module.exports = app; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great readme instructions, very easy to follow