Skip to content

ShelterMap Backend is the API for the ShelterMap project, built with Node.js and Express. It manages user authentication, shelter data, and updates needs. It uses PostgreSQL for storage, JWT for authentication, and bcryptjs for password encryption.

License

Notifications You must be signed in to change notification settings

MatheusCampagnolo/ShelterMap-backend

Repository files navigation

ShelterMap Backend

Overview

ShelterMap Backend is the API service for the ShelterMap project, designed to manage shelters and connect them with individuals offering help. It handles user authentication, shelter data management, updates to shelter needs, category assignments, and user feedback. The backend supports shelter representatives in registering and managing their shelters, while providing the public with access to shelter information and upvoting capabilities.

Technologies Used

Database Schema

Tables

  • Users: Stores user data for authentication and authorization.
  • Shelters: Stores shelter information, including location and associated user.
  • Needs: Stores predefined needs that shelters can select from.
  • Categories: Stores different categories that can be associated with shelters.
  • Shelter Categories: Associates shelters with specific categories.
  • Votes: Tracks upvotes for shelters.

Migrations

  • Create Users Table: Defines the schema for storing user information.
  • Create Shelters Table: Defines the schema for storing shelter information.
  • Create Needs Table: Defines the schema for storing predefined needs.
  • Create Categories Table: Defines the schema for storing categories.
  • Create Shelter Categories Table: Defines the schema for associating shelters with categories.
  • Create Votes Table: Defines the schema for storing user votes on shelters.

Seeds

  • 01_add_users: Seeds initial user data.
  • 02_add_shelters: Seeds initial shelter data.
  • 03_add_needs: Seeds predefined needs.
  • 04_add_categories: Seeds initial categories.

API Routes

User Authentication

  • POST /api/register
    Register a new user.

  • POST /api/login
    Authenticate user and return JWT.

Shelter Management

  • POST /api/shelters
    Add a new shelter (requires authentication).

  • GET /api/shelters
    Get a list of all shelters.

  • GET /api/shelters/:id
    Get detailed information about a specific shelter.

  • PUT /api/shelters/:id
    Update shelter details (requires authentication).

  • DELETE /api/shelters/:id
    Delete a shelter (requires authentication).

Needs Management

  • POST /api/shelters/:id/needs
    Add needs to a shelter (requires authentication).

  • GET /api/needs
    Get a list of all predefined needs.

Category Management

  • POST /api/categories
    Add a new category.

  • GET /api/categories
    Get a list of all categories.

  • POST /api/shelters/:id/categories
    Associate a shelter with categories (requires authentication).

  • DELETE /api/shelters/:id/categories/:categoryId
    Remove a category from a shelter (requires authentication).

Feedback & Upvote System

  • POST /api/votes
    Upvote a shelter (requires authentication).

  • GET /api/votes
    Get the number of votes for a specific shelter.

Installation & Setup

  1. Clone the repository:

    git clone https://github.com/MatheusCampagnolo/sheltermap-backend.git
  2. Install dependencies:

    npm install
  3. Set up environment variables by creating a .env file:

    DB_HOST=localhost
    DB_USER=postgres
    DB_PASSWORD=your_password
    DB_NAME=sheltermaps
    JWT_SECRET=your_secret_key
  4. Run migrations:

    npx knex migrate:latest
  5. Seed the database:

    npx knex seed:run
  6. Start the development server:

    npm run dev

Testing

  • Testing Routes: Use tools like Postman or Insomnia to test API routes and ensure they are functioning correctly.
  • Unit Testing: Consider adding unit tests using a testing framework like Jest to ensure code reliability.

Contributing

Contributions are welcome! Feel free to submit issues and pull requests for new features, bug fixes, and improvements.

License

This project is licensed under the MIT License.

About

ShelterMap Backend is the API for the ShelterMap project, built with Node.js and Express. It manages user authentication, shelter data, and updates needs. It uses PostgreSQL for storage, JWT for authentication, and bcryptjs for password encryption.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published