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.
- Backend: Node.js, Express.js
- Database: PostgreSQL
- ORM: Knex.js
- Authentication: JWT (JSON Web Token)
- Password Hashing: bcryptjs
- Environment Variables: dotenv
- Security: helmet, cors
- 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.
- 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.
- 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.
-
POST
/api/register
Register a new user. -
POST
/api/login
Authenticate user and return JWT.
-
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).
-
POST
/api/shelters/:id/needs
Add needs to a shelter (requires authentication). -
GET
/api/needs
Get a list of all predefined needs.
-
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).
-
POST
/api/votes
Upvote a shelter (requires authentication). -
GET
/api/votes
Get the number of votes for a specific shelter.
-
Clone the repository:
git clone https://github.com/MatheusCampagnolo/sheltermap-backend.git
-
Install dependencies:
npm install
-
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
-
Run migrations:
npx knex migrate:latest
-
Seed the database:
npx knex seed:run
-
Start the development server:
npm run dev
- 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.
Contributions are welcome! Feel free to submit issues and pull requests for new features, bug fixes, and improvements.
This project is licensed under the MIT License.