Skip to content

leandroguarino/orders_management_api_spring_boot_postgres

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Back-office REST API - Java Spring Boot

This is a REST API built with Java Spring Boot for managing a back-office application with Orders, Customers, Products, Categories, and Users.

Prerequisites

  • Java 17 or higher
  • Maven 3.6 or higher
  • PostgreSQL 12 or higher

Database Setup

  1. Install PostgreSQL if you haven't already
  2. Create a database named backoffice_db:
# Login to PostgreSQL
psql -U postgres

# Create database
CREATE DATABASE backoffice_db;

# Exit
\q
  1. Update database credentials in src/main/resources/application.properties if needed:
    • Default username: postgres
    • Default password: postgres
    • Default database: backoffice_db

How to Run the API

Option 1: Using Maven Wrapper (Recommended)

# On Linux/Mac
./mvnw spring-boot:run

# On Windows
mvnw.cmd spring-boot:run

Option 2: Using Maven directly

# Clean and install dependencies
mvn clean install

# Run the application
mvn spring-boot:run

Option 3: Build and run JAR file

# Build the JAR file
mvn clean package

# Run the JAR
java -jar target/backoffice-api-1.0.0.jar

API Endpoints

The API will be available at: http://localhost:8080

Authentication

  • POST /api/auth/login - Login with email and password

Users

  • GET /api/users - Get all users
  • GET /api/users/{id} - Get user by ID
  • POST /api/users - Create new user
  • PUT /api/users/{id} - Update user
  • DELETE /api/users/{id} - Delete user

Categories

  • GET /api/categories - Get all categories
  • GET /api/categories/{id} - Get category by ID
  • POST /api/categories - Create new category
  • PUT /api/categories/{id} - Update category
  • DELETE /api/categories/{id} - Delete category

Products

  • GET /api/products - Get all products
  • GET /api/products/{id} - Get product by ID
  • POST /api/products - Create new product
  • PUT /api/products/{id} - Update product
  • DELETE /api/products/{id} - Delete product

Customers

  • GET /api/customers - Get all customers
  • GET /api/customers/{id} - Get customer by ID
  • POST /api/customers - Create new customer
  • PUT /api/customers/{id} - Update customer
  • DELETE /api/customers/{id} - Delete customer

Orders

  • GET /api/orders - Get all orders
  • GET /api/orders/{id} - Get order by ID
  • POST /api/orders - Create new order
  • PUT /api/orders/{id} - Update order
  • DELETE /api/orders/{id} - Delete order

Default Admin User

After the first run, a default admin user will be created:

  • Email: admin@backoffice.com
  • Password: admin123

Database Migration

The application uses Flyway for database migrations. The initial migration script is located at: src/main/resources/db/migration/V1__create_initial_tables.sql

Migrations will run automatically when the application starts.

Technologies Used

  • Java 17
  • Spring Boot 3.2.0
  • Spring Data JPA
  • Spring Security
  • PostgreSQL
  • Flyway (Database Migration)
  • JWT (Authentication)
  • Lombok
  • Maven

Project Structure

src/main/java/com/backoffice/api/
├── config/          # Configuration classes (Security, CORS)
├── controller/      # REST Controllers
├── domain/          # Entity classes (JPA)
├── dto/             # Data Transfer Objects
├── repository/      # JPA Repositories
├── security/        # Security components (JWT)
└── service/         # Business logic services

Troubleshooting

Port already in use

If port 8080 is already in use, change it in application.properties:

server.port=8081

Database connection error

  • Make sure PostgreSQL is running
  • Verify database credentials in application.properties
  • Ensure the database backoffice_db exists

Maven build errors

# Clean Maven cache and rebuild
mvn clean install -U

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages