This is an api for a blog app - An AltSchool Assessment
- User should be able to register
- User should be able to login with Passport using JWT and expires after one hour
- Logged in and not logged in users should be able to get a list of published blogs created
- Logged in and not logged in users should be able to to get a published blog
- Logged in users should be able to create a blog.
- When a blog is created, it is in draft state
- The owner of the blog should be able to update the state of the blog to published
- The owner of a blog should be able to edit the blog in draft or published state
- The owner of the blog should be able to delete the blog in draft or published state
- The owner of the blog should be able to get a list of their blogs.
- The endpoint should be paginated
- It should be filterable by state
- Blogs created should have title, description, tags, author, timestamp, state, read_count, reading_time and body.
- The list of blogs endpoint that can be accessed by both logged in and not logged in users should be paginated, default it to 20 blogs per page.
- It should also be searchable by author, title and tags.
- It should also be orderable by read_count, reading_time and timestamp
- When a single blog is requested, the api should return the user information(the author) with the blog. The read_count of the blog too should be updated by 1
- An algorithm for calculating the reading_time of the blog.
- Write tests for all endpoints
- Install NodeJS, mongodb
- pull this repo
- update env with yourFile.env
field | data_type | constraints |
---|---|---|
id | string | required |
firstname | string | required |
lastname | string | required |
string | required | |
password | string | required |
field | data_type | constraints |
---|---|---|
title | string | required |
description | string | required |
body | string | required |
state | string | required, default:'draft', enum: ['draft', 'published'] |
tags | array | optional |
read_Count | Number | optional |
reading_time | Number | |
author | string | required |
- Route: /auth/register
- Method: POST
- Body:
{
"email": "test@mail.com",
"password": "test123",
"firstname": "jon",
"lastname": "doe",
"role": "admin editor user"
}
- Responses
Success
{
message: `New user with email address test@mail.com created`,
user: {
"email": "test@mail.com",
"password": *hashedPassword*,
"first_name": "jon",
"last_name": "doe",
"roles": ["admin", "editor", "user"],
"articles": []
}
}
- Route: /auth/login
- Method: POST
- Body:
{
"password": "test123",
"email": "test@mail.com",
}
- Responses
Success
{
accessToken: 'sjlkafjkldsfjsddslbdcuibacawcaw.weragfvwca3qd'
}
- Route: /articles
- Method: POST
- Header
- Authorization: Bearer {token}
- Body:
{
article: {
title: "Nigeria: A land of opportunities",
author: "Jon Doe"
description: "The story of the giant of Africa",
tags: "Story, History",
body: "Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."
}
- Responses
Success
{
created_at: Sun Nov 06 2022 08:35:00 GMT+0100,
status: true,
result: {
title: "Nigeria: A land of opportunities",
description: "The story of the giant of Africa",
tags: ['Story', 'History'],
body: "Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...",
state: "draft",
read_Count:0,
reading_time:1,
author: "Jon Doe"
}
- Route: /articles
- Method: GET
- Header
- Authorization: Bearer {token}
- Query params:
- page (default: 1)
- limit (default: 20)
- author
- tags
- title
- Responses
Success
{
results: [{
title: "Nigeria: A land of opportunities",
description: "The story of the giant of Africa",
tags: ['Story', 'History'],
body: "Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...",
state: "draft",
read_Count:0,
reading_time:1,
author: "Jon Doe"
}]
}
- Route: /articles/:articleID
- Method: GET
- Header
- Authorization: Bearer {token}
- Responses
Success
{
status: true,
result: {
title: "Nigeria: A land of opportunities",
description: "The story of the giant of Africa",
tags: ['Story', 'History'],
body: "Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...",
state: "draft",
read_Count:0,
reading_time:1,
author: "Jon Doe"
}
}
- Route: /articles/articleID
- Method: PUT
- Header
- Authorization: Bearer {token}
- Body:
{
title: "Nigeria: The giant of Africa",
}
- Responses
Success
{
created_at: Sun Nov 06 2022 08:35:00 GMT+0100,
status: true,
result: {title: "Nigeria: The giant of Africa",
description: "The story of the giant of Africa",
tags: ['Story', 'History'],
body: "Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...",
state: "draft",
read_Count:0,
reading_time:1,
author: "Jon Doe"}
}
- Route: /articles/articleID
- Method: PATCH
- Header
- Authorization: Bearer {token}
- Body:
{
state: "published",
}
- Responses
Success
{
created_at: Sun Nov 06 2022 08:35:00 GMT+0100,
status: true,
article: {
{title: "Nigeria: The giant of Africa",
description: "The story of the giant of Africa",
tags: ['Story', 'History'],
body: "Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...",
state: "published",
read_Count:0,
reading_time:1,
author: "Jon Doe"}
}
}
- Route: /articles
- Method: DELETE
- Header
- Authorization: Bearer {token}
- Body:
{
_id: "635fabb65b42d30512068ca3",
}
- Responses
Success
{
result: [],
}
...
- Ayotunde Pedro