Skip to content

paultergust/news_provider

Repository files navigation

NEWS API PROJECT

A simple project to simulate a news provider API. Made with Django, DRF and PostgreSQL.

Table of contents

Requirements

Virtual environment

Create new directory

mkdir news_provider

Change directory

cd news_provider/

Create virtual environment

python3 -m venv env

Activate virtual environment

# Windows:
env\Scripts\activate.bat

# On Unix or MacOS, run:
source env/bin/activate

Development Mode Setup

Installation

Clone repository

git clone [email protected]:paultergust/news_provider.git

Change directory

cd news_provider

Install all dependencies

pip install -r requirements.txt

Make sure you have PostgreSQL runnint on port 5432. Then setup a database with credentials found in news_provider/settings.py:

# news_provider/settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': news_provider_api,
        'USER': news_provider_api,
        'PASSWORD': news_provider_api,
        'HOST': localhost,
        'PORT': 5432,
    }
}

Run django migrations

python manage.py makemigrations

Run django server with specific settings file

python manage.py runserver --settings=news_provider/dev_settings

Production Mode Setup

You'll need to have installed Docker, docker-compose and have a 'dockerd' instance running.

Clone repository

git clone [email protected]:paultergust/news_provider.git

Change directory

cd news_provider

After all set, just run:

make prod

OBS: If you get an error on this step, make sure you have port 5432 open. Maybe stop your local PostgreSQL service

sudo systemctl stop postgresql

Endpoints

  • Login API: /api/login/
  • Sign-up API: /api/sign-up/
  • List articles: /api/articles/?category=:slug
  • Administrator restricted APIs:
    • CRUD /api/admin/authors/
    • CRUD /api/admin/articles/

Models

Article:

{
  "id": "39df53da-542a-3518-9c19-3568e21644fe",
  "author": {
    "id": "2d460e48-a4fa-370b-a2d0-79f2f601988c",
    "name": "Author Name",
    "picture": "https://picture.url"
  },
  "category": "Category",
  "title": "Article title",
  "summary": "This is a summary of the article"
}

Author:

  {
    "id": "2d460e48-a4fa-370b-a2d0-79f2f601988c",
    "name": "Author Name",
    "picture": "https://picture.url"
  }

User:

  {
    "username": "Username",
    "password": "write-only hashed password",
    "is_admin": false,
  }

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published