Homework #4

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

Setup

Setup

Backend uses embedded sqlite3 database

To Run Project

Backend

cd backend

npm install

npm run db:init (Only during the first run)

npm start

Frontend

cd frontend

npm install

npm run test (To run tests)

npm run serve

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:


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

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

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.

Front-end part of this task is already implemented in file frontend/src/components/LikeButton.vue

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.

Front-end part of this task is already implemented in file frontend/src/components/LikeButton.vue

Task#4 - 10 points

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.

  • 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

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:

  • 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