Homework #4
Homework #4
Points: 20
Points: 20
Grading breakdown:
Task 1 - 5 points
Task 2 - 3 points
Task 3 - 2 points
Task 4 - 10 points
Bonus Task - 5 points
Deadline: 13 December 2019 23:59:59
Deadline: 13 December 2019 23:59:59
Setup
Setup
Setup
Setup
Backend uses embedded sqlite3 database
Backend uses embedded sqlite3 database
To Run Project
To Run Project
Backend
Backend
cd backend
npm install
npm run db:init (Only during the first run)
npm start
Frontend
Frontend
cd frontend
npm install
npm run test (To run tests)
npm run serve
Tasks
Tasks
If you have a closer look at the code of both front-end and back-end applications you will see, that all the functionalities (100%) on front-end are already implemented and backend is just missing some endpoints, your tasks for this homework will be to implement these endpoints and one test for the front-end:
If you have a closer look at the code of both front-end and back-end applications you will see, that all the functionalities (100%) on front-end are already implemented and backend is just missing some endpoints, your tasks for this homework will be to implement these endpoints and one test for the front-end:
NOTE: All the SQL queries that need to be executed by the backend add are ALREADY implemented since, SQL is not in the scope of the course, you can use convenient methods prepared for you in backend/models/PostModel.js
NOTE: All the SQL queries that need to be executed by the backend add are ALREADY implemented since, SQL is not in the scope of the course, you can use convenient methods prepared for you in backend/models/PostModel.js
Task#1 - 5 points
Task#1 - 5 points
Implement POST endpoint localhost:3000/posts/ in file backend/routes/posts.js, where you will send data to create a new post.
Implement POST endpoint localhost:3000/posts/ in file backend/routes/posts.js, where you will send data to create a new post.
Front-end part of this task is already implemented in file frontend/src/components/AddPost.vue
Front-end part of this task is already implemented in file frontend/src/components/AddPost.vue
Task#2 - 3 points
Task#2 - 3 points
Implement PUT endpoint localhost:3000/posts/:postId/likes in file backend/routes/posts.js, where you will send data to like a particular post.
Implement PUT endpoint localhost:3000/posts/:postId/likes in file backend/routes/posts.js, where you will send data to like a particular post.
Front-end part of this task is already implemented in file frontend/src/components/LikeButton.vue
Front-end part of this task is already implemented in file frontend/src/components/LikeButton.vue
Task#3 - 2 points
Task#3 - 2 points
Implement DELETE endpoint localhost:3000/posts/:postId/likes in file backend/routes/posts.js, where you will send data to unlike a particular post.
Implement DELETE endpoint localhost:3000/posts/:postId/likes in file backend/routes/posts.js, where you will send data to unlike a particular post.
Front-end part of this task is already implemented in file frontend/src/components/LikeButton.vue
Front-end part of this task is already implemented in file frontend/src/components/LikeButton.vue
Task#4 - 10 points
Task#4 - 10 points
Complete the test in file frontend/tests/unit/PostsTest.spec.js.
Complete the test in file frontend/tests/unit/PostsTest.spec.js.
All the necessary setup, such as mocking routes, store and axios module is already done.
All the necessary setup, such as mocking routes, store and axios module is already done.
- Test that exactly as many posts are rendered as contained in testData variable
- Test that if post has media property, image or video tags are rendered depending on media.type property, or if media property is absent nothing is rendered.
- Test that post create time is displayed in correct format: Saturday, December 5, 2020 1:53 PM
Bonus Task - 5points
Bonus Task - 5points
Currently it is hardcoded on backend side that no matter which user logs in, always user with id 1 will be current user, change that and generate JWT token on login from currently logged in user object and to frontend.
Currently it is hardcoded on backend side that no matter which user logs in, always user with id 1 will be current user, change that and generate JWT token on login from currently logged in user object and to frontend.
NOTE:
NOTE:
- See backend/routes/users.js to change login logic
- See backend/middlewares/authorize.js to validate passed tokens and set correct user as current user
- See backend/library/jwt.js for convenient methods for creating and verifying access tokens
Frontend handling of access token is already implemented
Frontend handling of access token is already implemented