Repo to store back end infrastructure for Message in a Bottle

Overview


Message in a Bottle Backend API

RESTful API for Message in a Bottle frontend application consumption.

contributors_badge forks_badge stars_badge issues_badge

About The ProjectTools UsedLocal Set UpInstallationHow To UseDatabase SchemaContributingAcknowledgements

About The Project

Message in a Bottle is an application where users can discover stories about the communities around them. This app was designed as a way to interact with cities, neighborhoods, and the people that inhabit them. The Message in a Bottle backend is built with a Django framework that stores story and user data through PostgreSQL. We expose this data to our frontend team to build out the user interface.

Learning Goals

  • Building a RESTful API with a Python Django backend
  • Collaborating with a Front-End dev team
  • Geolocation calls and tracking
  • Applying best practices learned during Turing to a new language and framework
    • e.g. TDD, OOP, REST, MVC(Rails) <--> MTV(Django)
  • Making use of the git rebase workflow

Tools Used

Development Testing Packages
Python 3.9.7 Pytest-Django Django
Django Pytest-Cov Django CORS Headers
CircleCI Postman Django Heroku
PostgreSQL VCRPY Django REST Framework
Git/Github Gunicorn
Heroku Psycopg2
Pycodestyle
Python-Decouple
Python-DotENV
Requests

Local Set Up

  1. To clone and run this application, you'll need Python 3.9.7 and Django 3.2.8. Using the official Python docs, follow instructions to install python3 for your local OS.

  2. You can check for a successful installation using this command:

$ python3 -V
> Python 3.9.7

Installation

  1. Fork this repo
  2. Clone your new repo:
git clone https://github.com/MIBFB-COLLAB/message_in_a_bottle_backend.git
  1. Create and Invoke your virtual environment:
python3 -m virtualenv venv
source venv/bin/activate
  1. Install dependencies:
(venv) python -m pip install -r requirements.txt
  1. Set up the database:
$ psql

CREATE DATABASE <project name>;
CREATE USER <user name> WITH PASSWORD <password>;
ALTER ROLE <user name> SET client_encoding TO 'utf8';
ALTER ROLE <user name> SET default_transaction_isolation TO 'read committed';
ALTER ROLE <user name> SET timezone TO 'UTC';
GRANT ALL PRIVILEGES ON DATABASE <project name> TO <user name>;
\q
  1. Add PostgreSQL database info to settings.py file:
DATABASES = {
  'default': {
      'ENGINE': 'django.db.backends.postgresql_psycopg2',
      'NAME': '
   
    '
   ,
      'USER': '
   
    '
   ,
      'PASSWORD': '
   
    '
   ,
      'HOST': '
   
    '
   ,
      'PORT': '
   
    '
   ,
  }
}
  1. Migrate database:
(venv) python manage.py makemigrations
(venv) python manage.py migrate
  1. Update CORS allowed origins in settings.py. Domains currently allowed are:
CORS_ALLOWED_ORIGINS = [
  'http://localhost:3000',
  'https://message-in-a-bottle-fe-app.herokuapp.com',
  'https://app-message-in-a-bottle.herokuapp.com',
]
  1. Run the test suite with:
(venv) export DJANGO_SETTINGS_MODULE=message_in_a_bottle.settings
(venv) pytest --cov
  1. Run your local Python server with:
(venv) python manage.py runserver

How To Use

To experience the front-end UI, please visit the application here. You can also hit our endpoints through an API client, such as Postman or HTTPie.

Endpoint Documentation

Domain: https://message-in-a-bottle-api.herokuapp.com

Stories Index Endpoint
The GET stories endpoint retrieves stories near you. You must supply valid longitude and latitude coordinates.

Query Params Required? Example Notes
latitude Yes /api/v1/stories?latitude=12.345&longitude=4.5968 requires longitude
longitude Yes /api/v1/stories?latitude=12.345&longitude=4.5968 requires latitude

Request: GET /api/v1/stories?latitude=12.3456&longitude=4.5968

Response:

{
  "data": {
    "input_location": "phoenix,az",
    "stories":[
      {
      "id": 1,
      "type": "story",
      "attributes": {
        "title": "my cool story",
        "latitude": 13.201,
        "longitude": 9.2673,
        "distance_in_miles": 1.2,
        "created_at": "2021-10-27T03:45:34.165600Z",
        "updated_at": "2021-10-27T03:45:36.855162Z"
        }
      },
      {
      "id": 2,
      "type": "story",
      "attributes": {
        "title": "story",
        "latitude": 13.563,
        "longitude": 10.2673,
        "distance_in_miles": 3,
        "created_at": "2021-10-27T04:45:34.165600Z",
        "updated_at": "2021-10-27T04:45:36.855162Z"
        }
      }
    ]
  }
}

Story Show Endpoint
Request: GET /api/v1/stories/:id?latitude=12.3456&longitude=-4.5968

Response:

{
  "data": {
    "id": 1,
    "type": "story",
    "attributes": {
      "title": "my cool story",
      "message": "This one time I saw a bird",
      "name": "Anonymous",
      "created_at": "2021-10-08T23:28:51.897746Z",
      "updated_at": "2021-10-08T23:28:51.897746Z",
      "latitude": 30.071945143440377,,
      "longitude": 31.225164325479227,
      "distance_in_miles": 1.2,
      "location": "Cairo Governorate, EG"
      }
   }
}

Directions Endpoint
Request: GET /api/v1/stories/:id/directions?latitude=1230&longitude=1209.3

Response:

{
  "data": [
    {
      "id": null,
      "type": "directions",
      "attributes": {
        "narrative": "Turn left on Bob St.",
        "distance": ".8 miles"
      }
    },
    {
      "id": null,
      "type": "directions",
      "attributes": {
        "narrative": "Turn right on Starry Road",
        "distance": ".2 miles"
      }
    }
  ]
}

Create Story Endpoint
Request: POST /api/v1/stories

Request Body:

{
  "title": "A new title",
  "message": "I'm coming up",
  "latitude": 27.717311514603534,
  "longitude": 85.32098499247293
}

Response:

{
  "data": {
    "id": 2,
    "type": "story",
    "attributes": {
      "title": "A new title",
      "message": "I'm coming up",
      "name": "Anonymous",
      "created_at": "2021-10-08T23:28:51.897746Z",
      "updated_at": "2021-10-08T23:28:51.897746Z",
      "latitude": 27.717311514603534,
      "longitude": 85.32098499247293,
      "location": "Kathmandu, NP"
    }
  }
}

Update Story Endpoint
Request: PATCH /api/v1/stories/:id

Request Body:

{
  "title": "My Fixed Title",
  "message": "Hello World.",
  "name": "Sally"
}

Response:

{
  "data": {
    "id": 1,
    "type": "story",
    "attributes": {
      "title": "My Fixed Title",
      "message": "Hello World.",
      "name": "Sally",
      "created_at": "2021-10-08T23:28:51.897746Z",
      "updated_at": "2021-10-18T23:28:51.897746Z",
      "latitude": 40.3830,
      "longitude": 105.5190,
      "location": "Estes Park, CO"
    }
  }
}

Delete Story Endpoint
Request: DELETE /api/v1/stories/:id

Error Handling
Here are some examples of error messages you could receive if you send an invalid request:

Bad Request URI: GET /api/v1/stories/:id or /api/v1/stories/:id?latitude=&longitude=

Response:

{
    "errors": {
        "messages": [
            "Latitude or longitude can't be blank."
        ],
        "code": 1
    }
}

Bad Request URI: GET /api/v1/stories/:id?latitude=1000&longitude=1000

Response:

{
    "errors": {
        "messages": [
            "Invalid latitude or longitude."
        ],
        "code": 1
    }
}

Bad Request URI: GET /api/v1/stories/:id?latitude=0&longitude=0

Response:

{
    "errors": {
        "messages": [
            "Impossible route."
        ],
        "code": 2
    }
}

POST /api/v1/stories Bad Request Body:

{
    "title":"Here's Johnny!",
    "message": "allworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboyallworkandnoplaymakesjackadullboy",
    "name":"Jack Torrance",
    "latitude":40.3830,
    "longitude":105.5190
}

Response:

{
    "errors": {
        "message": [
            "Ensure this field has no more than 1000 characters."
        ],
        "location": [
            "This field may not be blank."
        ]
    }
}

Database Schema

Screen Shot 2021-10-27 at 17 33 14

Contributing

👤 Marla Schulz

👤 Taylor Varoglu

👤 Matt Kragen

👤 Mae Duphorne

👤 Fara Akhatova

👤 Justin Anthony

Acknowledgements

Python Function to manage users via SCIM

Python Function to manage users via SCIM This script helps you to manage your v2 users. You can add and delete users or groups, add users to groups an

4 Oct 11, 2022
A simple python project that can find Tangkeke in a given image.

A simple python project that can find Tangkeke in a given image. Make the real Tangkeke image as a kernel to convolute the target image. The area wher

张志衡 1 Dec 08, 2021
A Python 3 client for the beanstalkd work queue

Greenstalk Greenstalk is a small and unopinionated Python client library for communicating with the beanstalkd work queue. The API provided mostly map

Justin Mayhew 67 Dec 08, 2022
Um jogo para treinar COO em python

WAR DUCK Este joguinho bem simples tem como objetivo treinar um pouquinho de POO com python. Não é nada muito complexo mas da pra se divertir Como rod

Gabriel Jospin 3 Sep 19, 2021
A beacon generator using Cobalt Strike and a variety of tools.

Beaconator is an aggressor script for Cobalt Strike used to generate either staged or stageless shellcode and packing the generated shellcode using your tool of choice.

Capt. Meelo 441 Dec 17, 2022
YunoHost is an operating system aiming to simplify as much as possible the administration of a server.

YunoHost is an operating system aiming to simplify as much as possible the administration of a server. This repository corresponds to the core code, written mostly in Python and Bash.

YunoHost 1.5k Jan 09, 2023
Banking management project using Tkinter GUI in python.

Bank-Management Banking management project using Tkinter GUI in python. Packages required Tkinter - Tkinter is the standard GUI library for Python. sq

Anjali Kumawat 7 Jul 03, 2022
Code for the manim-generated scenes used in 3blue1brown videos

This project contains the code used to generate the explanatory math videos found on 3Blue1Brown. This almost entirely consists of scenes generated us

Grant Sanderson 4.1k Jan 02, 2023
Academic planner application designed for students and counselors.

Academic planner application designed for students and counselors.

Ali bagheri 2 Dec 31, 2021
36 key ergo split keyboard, designed around the Seeeduino Xiao platform

Slice36 Minimalist Split Keyboard 36 key ergo split keyboard, designed around the Seeeduino Xiao platform. Inspired by the Corne, Ferris, Ben Vallack'

54 Dec 21, 2022
Functional interface for concurrent futures, including asynchronous I/O.

Futured provides a consistent interface for concurrent functional programming in Python. It wraps any callable to return a concurrent.futures.Future,

A. Coady 11 Nov 27, 2022
In this project, we'll be creating a virtual personal assistant for ourselves using our favorite programming language

In this project, we'll be creating a virtual personal assistant for ourselves using our favorite programming language, Python. We can perform several offline as well as online operations using the bo

Ashutosh Krishna 188 Jan 03, 2023
Python library to decode the EU Covid-19 vaccine certificate

DCC Utils Python library to decode the EU Covid-19 vaccine certificate, as specified by the EU. Setup pip install dcc-utils Make sure zbar is installe

Developers Italia 13 Mar 11, 2022
Simple module with some functions such as generate password (get_random_string)

Simple module with some functions such as generate password (get_random_string), fix unicode strings, size converter, dynamic console, read/write speed checker, etc.

Dmitry 2 Dec 03, 2022
Python code for YouTube videos.

#This is a open source project. Python 3 These files are mainly intended to accompany my series of YouTube tutorial videos here, https://www.youtube.c

Joe James 1.3k Dec 26, 2022
Alfred 4 Workflow to search through your maintained/watched/starred GitHub repositories.

Alfred 4 Workflow to search through your maintained/watched/starred GitHub repositories. Setup This workflow requires a number of Python modules. Thes

Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs 1 Oct 14, 2022
Repo Home WPDrawBot - (Repo, Home, WP) A powerful programmatic 2D drawing application for MacOS X which generates graphics from Python scripts. (graphics, dev, mac)

DrawBot DrawBot is a powerful, free application for macOS that invites you to write Python scripts to generate two-dimensional graphics. The built-in

Frederik Berlaen 342 Dec 27, 2022
Localization and multifractal properties of the long-range Kitaev chain in the presence of an Aubry-André-Harper modulation

This repository contains the code for the paper Localization and multifractal properties of the long-range Kitaev chain in the presence of an Aubry-André-Harper modulation.

Joana Fraxanet 2 Apr 17, 2022
Org agenda in the console

This Python script reads an org agenda file (i.e. a regular org file with some active dates) and displays an interactive and colored year calendar with detailed information for each day when the mous

Nicolas P. Rougier 113 Jan 03, 2023
Port of the OpenCascade library to JavaScript / WebAssembly using Emscripten

OpenCascade.js A port of the OpenCascade CAD library to JavaScript and WebAssembly via Emscripten. Explore the docs » Examples · Issues · Discuss Proj

Sebastian Alff 347 Jan 08, 2023