Skip to content

zamandevv/altblog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

[![Contributors][contributors-shield]][contributors-url] [![Forks][forks-shield]][forks-url] [![Stargazers][stars-shield]][stars-url] [![Issues][issues-shield]][issues-url] [![MIT License][license-shield]][license-url] [![Twitter][twitter-shield]][twitter-url] AltSchool Badge

Altblog

— a wonderful Blogging API built as an exam project by tobisupreme, a Backend Engineering student at AltSchool Africa.

back to top

Built With:

![Javascript][javascript] ![Node.js][node] ![Express.js][express] ![MongoDB][mongodb]

back to top


Requirements

Requirements for the examination project
  • Users should have a first_name, last_name, email, password,

  • A user should be able to sign up and sign in into the blog app

  • Use JWT as authentication strategy and expire the token after 1 hour

  • A blog can be in two states; draft and published

  • 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

  • Come up with any algorithm for calculating the reading_time of the blog.

  • Write tests for all endpoints

back to top



Development

Prerequisites

Clone this repo

git clone https://github.com/zamandevv/altblog.git

Install project dependencies

npm install

Update .env with example.env

Run a development server

npm run dev

For testing, run

npm run test

Models

User

field data_type constraints
username string required, unique
firstName string required
lastName string required
email string required, unique
password string required
articles ref - Article

Article

field data_type constraints
title string required, unique
description string optional
author ref - User
owner string
state string required, default: 'draft', enum: ['draft', 'published']
read_count Number default: 0
reading_time Number
tags array optional
body string required

back to top


Usage

Creating a user

  • Route: /api/signup
  • Method: POST

👇 Body

{
  "firstName": "John",
  "lastName": "Doe",
  "username": "mightyjoe",
  "email": "joe@mail.com",
  "password": "Password0!"
}

👇 Response

{
  "status": "success",
  "data": {
    "firstName": "John",
    "lastName": "Doe",
    "username": "mightyjoe",
    "email": "joe@mail.com",
    "articles": [],
    "_id": "6367c296ba7522bd8561e4f6"
  }
}

Logging in

  • Route: /api/login
  • Method: POST

👇 Body

{
  "username": "mightyjoe",
  "password": "Password0!"
}

👇 Response

{
  "token": <token>,
  "username": "mightyjoe",
  "name": "John"
}

back to top


Lessons Learned

While building this project, I learned about:

  • Test Driven Development
  • Testing the backend
  • Database Modelling
  • Database Management
  • Debugging
  • User Authentication
  • User Authorization
  • Documentation

back to top


License

Distributed under the MIT License. See <a href="https://github.com/zamandevv/alt

/blob/main/LICENSE.md">LICENSE for more information.

back to top


Contact

Project Link: altblog

back to top


Acknowledgements

This project was made possible by:

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors