iuridantas / Backend-Adocao-Animais

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

animal Adoption Backend API

This repository contains the backend API for a animal adoption platform. The API provides features for users to login, create new users, update their data, create animals for adoption, update their animal's data, update animal status, search for animals based on multiple parameters and import animals from third-party APIs.

Table of Contents

Getting Started

Prerequisites

Ensure that your machine is equipped with the necessary software by installing the following:

Installation

  1. Clone the repository:
git clone https://github.com/iuridantas/Backend-Adocao-Animais.git
  1. Navigate to the project directory:
cd Backend-Adocao-Animais
  1. Install dependencies:
yarn
  1. Fulfill the .env variables

Running with Docker Compose

To run the application using Docker Compose, make sure you have Docker and Docker Compose installed. If you don't, you can install them by following the instructions at Docker

  1. Build the images and start the containers:
docker-compose up --build

This command will build Docker images and start containers based on the docker-compose.yml file.

Prisma Database Operations

To perform Prisma-related database operations, follow these steps:

  1. Run Prisma migrations:
npx prisma migrate dev

This command applies any pending migrations.

  1. Push changes to the database:
npx prisma db push

Use this command to apply the changes to the database.

  1. Generate Prisma Client:
npx prisma generate

Run this command to generate the Prisma Client, which is used to interact with your database.

Running the Application

Run the following command to start the application:

yarn start:dev

The API will be accessible at http://localhost:3000.

API Routes

User Login

  • Endpoint: /auth/login
  • Method: POST
  • Description: User login
  • Request Body:
    {
      "email": "string",
      "password": "string"
    }
  • Responses:
    • 200: Successful login
    • 400: Bad request
    • 500: Internal server error

Create User

  • Endpoint: /user/create

  • Method: POST

  • Description: Create user

  • Request Body:

    {
      "name": "string",
      "email": "string",
      "cpf": "string",
      "password": "string"
    }
  • Responses:

    • 200: Successful creation
    • 400: Bad request
    • 500: Internal server error

Create Animal

  • Endpoint: /animal/create
  • Method: POST
  • Description: Create animal
  • Request Body:
{
  "name": "string",
  "description": "string",
  "image": "string",
  "userId": "string",
  "category": "string",
  "status": "available"
}
  • Responses:
    • 200: Successful creation
    • 400: Bad request
    • 500: Internal server error

Index animals into Database

  • Endpoint: /animal/allIncludingExternalData
  • Method: GET
  • Description: All animals into the database
  • Security: Bearer Token
  • Responses:
    • 200: Successful request
    • 401: Unauthorized
    • 500: Internal server error

Update animal Status

  • Endpoint: /animal/updateStatus/{id}
  • Method: PATCH
  • Description: Update animal status
  • Security: Bearer Token
  • Parameters:
    • animalId (string)
  • Responses:
    • 200: Successful update
    • 400: Bad request
    • 401: Unauthorized
    • 500: Internal server error

Get Animal Term

  • Endpoint: /animal/byTerm

  • Method: GET

  • Description: Get pets by term(name or description)

  • Parameters:

    • term (string)
  • Responses:

    • 200: Successful request
    • 400: Bad request
    • 500: Internal server error

Get Animal Category

  • Endpoint: /animal/byCategory
  • Method: GET
  • Description: Get pets by category(cat or dog)
  • Parameters:
    • category (string)
  • Responses:
    • 200: Successful request
    • 400: Bad request
    • 500: Internal server error

Get Animal Status

  • Endpoint: /animal/byStatus
  • Method: GET
  • Description: Get pets by status(available or adopted)
  • Parameters:
    • status (string)
  • Responses:
    • 200: Successful request
    • 400: Bad request
    • 500: Internal server error

Get Animal Creation Date

  • Endpoint: /animal/byCreationDate
  • Method: GET
  • Description: Get pets by creation date(yyyy/MM/dd or dd/MM/yyyy)
  • Parameters:
    • creation date (string)
  • Responses:
    • 200: Successful request
    • 400: Bad request
    • 500: Internal server error

Dependencies

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

About

License:MIT License


Languages

Language:TypeScript 98.3%Language:JavaScript 1.7%