Skip to content

LukasNolting/coderr-backend

Repository files navigation

Coderr Backend

The Coderr backend is a robust REST API built with Django and Django REST Framework (DRF). It supports functionalities such as user authentication, password reset, profile management, and review systems for business users.

Features

  • User Authentication:
    • Login and registration with JWT-based authentication.
    • Password reset via email with secure token validation.
  • Profile Management:
    • View and edit user profiles (business and customer).
    • Separate endpoints for business and customer profiles.
  • Review System:
    • Create, view, update, and delete reviews for business profiles.
  • Offer Management:
    • Manage business offers (create, view, update).


Installation

Prerequisites

  • Python 3.10+
  • pip
  • WSL 20.04 (for Windows users)
  • PostgreSQL

Steps

  1. Clone the repository:
    git clone git@github.com:LukasNolting/coderr-backend.git
    cd coderr-backend

  2. Create a virtual environment:
    python -m venv env
    source env/bin/activate # Linux/Mac
    env\Scripts\activate # Windows

  3. Install dependencies:
    pip install -r requirements.txt

  4. Set up PostgreSQL database:

    • Launch WSL or your terminal and start PostgreSQL:
      sudo service postgresql start
    • Access the PostgreSQL CLI:
      sudo -u postgres psql
    • Create a new database:
      CREATE DATABASE coderr;
    • Create a new user:
      CREATE USER coderr_user WITH PASSWORD 'your_password';
    • Grant privileges:
      GRANT ALL PRIVILEGES ON DATABASE coderr TO coderr_user;
    • Exit the PostgreSQL CLI:
      \q

  5. Configure .env file:

    • Copy dot_env_template to .env.
    • Update the database section:
      DATABASE_NAME='coderr'
      DATABASE_USER='coderr_user'
      DATABASE_PASSWORD='your_password'
      DATABASE_HOST='localhost'
      DATABASE_PORT=5432


  6. Apply migrations:
    python manage.py makemigrations
    python manage.py migrate

  7. Gunicorn Setup

In addition to installing the required dependencies from requirements.txt, you need to install Gunicorn separately for deployment:

7.1. Install Gunicorn via pip:
pip install gunicorn

7.2. Test running the server with Gunicorn:
gunicorn --bind 0.0.0.0:8000 coderr_backend.wsgi:application

7.3. Configure Gunicorn as a system service for production (optional):

  • Create a Gunicorn service file, e.g., /etc/systemd/system/coderr_gunicorn.service, with the following content:
   [Unit]
   Description=Gunicorn instance for Coderr Backend
   After=network.target

   [Service]
   User=your_user
   Group=your_group
   WorkingDirectory=/path/to/coderr-backend
   ExecStart=/path/to/env/bin/gunicorn --workers 3 --bind unix:/path/to/coderr-backend/coderr.sock coderr_backend.wsgi:application

   [Install]
   WantedBy=multi-user.target
   

7.4. Start and enable the Gunicorn service:
sudo systemctl start coderr_gunicorn
sudo systemctl enable coderr_gunicorn

This ensures Gunicorn is set up properly for production environments. """

  1. Start the development server:
    python manage.py runserver


Guest Access

Two guest access accounts have been pre-configured for testing purposes:

const GUEST_LOGINS = {
  customer: {
    username: "andrey",
    password: "asdasd",
  },
  business: {
    username: "kevin",
    password: "asdasd",
  },
};

You can use these accounts to log in and test the application with pre-defined roles: Customer and Business. """

API Endpoints

Authentication

  • POST /login/: Authenticate users and return a token.
  • POST /registration/: Register new users.

Profile Management

  • GET /profile/<pk>/: Retrieve or update a user profile.
  • GET /profiles/business/: List all business profiles.
  • GET /profiles/customer/: List all customer profiles.

Reviews

  • GET /reviews/: List reviews with optional filters.
  • POST /reviews/: Create a new review (requires authentication).
  • GET /reviews/<id>/: Retrieve, update, or delete a specific review.

Environment Variables

Create a .env file or use the template dot_env_template with the following settings:

REDIRECT_LOGIN='http://127.0.0.1:54051/login.html'
REDIRECT_LANDING='http://127.0.0.1:54051'
BACKEND_URL='localhost:8000'
PROD_FRONTEND_URL=''

SECRET_KEY=''
ALLOWED_HOSTS=["127.0.0.1", "localhost"]
CSRF_TRUSTED_ORIGINS=["http://127.0.0.1","http://localhost:4200","http://localhost:8000"]
CORS_ALLOWED_ORIGINS=["http://127.0.0.1","http://localhost:4200","http://localhost:8000"]

DATABASE_NAME='coderr'
DATABASE_USER='postgres'
DATABASE_PASSWORD=''
DATABASE_HOST=''
DATABASE_PORT=5432

EMAIL_HOST=''
EMAIL_PORT=587
EMAIL_HOST_USER=''
EMAIL_HOST_PASSWORD=''
DEFAULT_FROM_EMAIL=''
DOMAIN_NAME='localhost'


Deployment

  1. Set DEBUG=False in .env.
  2. Collect static files:
    python manage.py collectstatic
  3. Configure a WSGI server (e.g., Gunicorn or uWSGI) to serve the application.
  4. Use a reverse proxy (e.g., Nginx) for improved performance.


Contribution

  1. Fork the repository.
  2. Create a new feature branch:
    git checkout -b feature-name
  3. Commit your changes:
    git commit -m "Add feature description"
  4. Push to the branch:
    git push origin feature-name
  5. Open a pull request.


License

This project is licensed under the MIT License.
"""

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors