Skip to content

The RedBag-Core is the main backend of the RedBag project. Responsible for managing user interactions, authentication, database operations, and API integrations, ensuring seamless communication between the system components.

License

Notifications You must be signed in to change notification settings

MateusOK/Redbag-Core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

91 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

banner

πŸ• RedBag Core

πŸ“Œ Project Overview

The RedBag-Core is the main backend of the RedBag project, developed at Fatec Registro. It is responsible for managing user interactions, authentication, database operations, and API integrations, ensuring seamless communication between the system components.

Built with Java Spring Boot, this API provides a robust and scalable solution, acting as the central hub that connects the frontend application with the RedBag-Predictor, a microservice responsible for cataract diagnosis in dogs.

πŸ‘‰ Access the RedBag-Predictor for more details.


πŸš€ Getting Started

Prerequisites

Before running this project, ensure you have the following installed:

Cloning the Repository

Clone this project to your local machine:

git clone https://github.com/MateusOK/Redbag-Core

Building the Project

Navigate to the project directory and build the JAR file:

mvn clean package

Environment Variables

Modify the application.yaml file to match your Cloudinary credentials, Predictor, and database URL:

datasource:
  url: ${SPRING_DATASOURCE_URL}
  driverClassName: 
  username: ${SPRING_DATASOURCE_USERNAME}
  password: ${SPRING_DATASOURCE_PASSWORD}

cloudinary:
  cloud-name: ${CLOUDINARY_CLOUD_NAME}
  api-key: ${CLOUDINARY_API_KEY}
  api-secret: ${CLOUDINARY_API_SECRET}

app:
  prediction-url: ${REDBAG_PREDICTOR_URL}

Running the API with Docker

Building the Docker Image

docker build -t redbag-core .

Running the Container

docker run -p 8080:8080 \
  -e SPRING_DATASOURCE_URL=your_database_url \
  -e SPRING_DATASOURCE_USERNAME=your_db_user \
  -e SPRING_DATASOURCE_PASSWORD=your_db_password \
  -e CLOUDINARY_CLOUD_NAME=your_cloudinary_name \
  -e CLOUDINARY_API_KEY=your_cloudinary_key \
  -e CLOUDINARY_API_SECRET=your_cloudinary_secret \
  -e PYTHON_API_URL=your_redbag_predictor_url \
  redbag-core

If you prefer using an .env file, create it and use the following command:

docker run --env-file .env -p 8080:8080 redbag-core

Verifying the API

Once the container is running, check if the API is accessible by visiting:

http://localhost:8080/swagger-ui/index.html#/

πŸ“ API Endpoints

To access Swagger documentation and view all available endpoints, start the application and visit:

Swagger UI

πŸ”‘ Authentication & User Management

Method Route Description
POST /api/auth/register Register a new user
POST /api/auth/login Authenticate and generate a token
PUT /api/users Update user data

Example Responses

POST /api/auth/register

Request:

{
  "name": "John Doe",
  "username": "JohnDoe",
  "email": "[email protected]",
  "password": "password"
}

Response:

{
  "id": 1,
  "name": "John Doe",
  "username": "JohnDoe",
  "email": "[email protected]"
}
POST /api/auth/login

Request:

{
  "usernameOrEmail": "JohnDoe",
  "password": "password"
}

Response:

{
  "token": "eyJhbGciOiJIUzI1NiIsInR..."
}

🐢 Animal Management

Method Route Description
POST /api/animals/{userId} Create a new animal
GET /api/animals/{userId} Retrieve all animals for user
PUT /api/animals/{userId}/{animalId} Update animal data
DELETE /api/animals/{userId}/{animalId} Delete an animal

Example Responses

POST /api/animals/{userId}

Request:

{
  "name": "Dog",
  "color": "#FFFFFF"
}

Response:

{
  "userId": 1,
  "name": "Dog",
  "color": "#FFFFFF"
}

🧠 Integration with RedBag-Predictor

Method Route Description
POST /predict Returns a preliminary diagnosis result
POST /predict/{animalId} Saves the result to the database

Example Requests & Responses

POST /predict

Request:

curl -X POST "localhost:8080/predict" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -F "image=@/path/to/image.jpg"

Response:

{
  "prediction": "unhealthy",
  "confidence": 0.89
}
POST /predict/{animalId}

Request:

curl -X POST "localhost:8080/predict/{animalId}" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -F "image=@/path/to/image.jpg"

Response:

{
  "prediction": "healthy",
  "confidence": 0.78
}

🀝 Collaborators

Special thanks to all contributors to this project:


This project is licensed under the MIT License.

About

The RedBag-Core is the main backend of the RedBag project. Responsible for managing user interactions, authentication, database operations, and API integrations, ensuring seamless communication between the system components.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published