Skip to content

About

REST API for a booking/reservation system, the integrator project of the Ada School backend course. Java 17 and Spring Boot with Spring Security, BCrypt and JWT authentication, Dockerized and auto-deployed to Render.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

14 Commits

Folders and files

Repository files navigation

Booking System API

REST API for a booking/reservation system, built as the integrator project for the Ada School backend course. Each course module adds a new layer on top of this base project.

Live deployment (Render): https://booking-system-api-tn5k.onrender.com — auto-deploys on every push to main.

Free-tier instance: it spins down after inactivity, so the first request after a quiet period can take ~50s to wake up.

Tech Stack

  • Java 17
  • Spring Boot 4.1.0
  • Spring Web (MVC)
  • Spring Security
  • JJWT (JSON Web Tokens)
  • Maven

Prerequisites

  • JDK 17+
  • Maven 3.9+ (or use the included mvnw / mvnw.cmd wrapper)

Getting Started

Clone the repository and run the application:

git clone https://github.com/AnderssonProgramming/booking-system-api.git
cd booking-system-api

# using the Maven wrapper
./mvnw spring-boot:run

# or with a local Maven install
mvn spring-boot:run

The application starts on http://localhost:8080.

Security

The API is secured with Spring Security and JWT. All endpoints require a valid Authorization: Bearer <token> header except /health and /api/auth/**.

  • Passwords are hashed with BCrypt before being stored.
  • Tokens are signed with HS256 and expire after jwt.expiration milliseconds (default 24h).
  • The signing key comes from the JWT_SECRET env var (a Base64 string, 32+ bytes). If it's not set, a random key is generated at startup — fine for local development, but it means tokens won't survive an application restart, and every instance in a multi-instance deployment needs the same JWT_SECRET.

API Endpoints

Method Endpoint Auth required Description
GET /health No Health check — confirms the API is up
POST /api/auth/register No Create a user and return a JWT
POST /api/auth/login No Authenticate and return a JWT
GET /api/users Yes List all users
GET /api/users/{id} Yes Get a user by id
POST /api/users Yes Create a user
PUT /api/users/{id} Yes Update a user
DELETE /api/users/{id} Yes Delete a user

Health check:

curl http://localhost:8080/health

Response:

<h1>The API is working ok!</h1>

Register and get a token:

curl -X POST http://localhost:8080/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{"name":"Andersson Sanchez","email":"andersson@example.com","phone":"3001234567","password":"Secret123"}'

Response:

{"token":"eyJhbGciOiJIUzUxMiJ9...","email":"andersson@example.com","type":"Bearer"}

Log in with existing credentials:

curl -X POST http://localhost:8080/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"andersson@example.com","password":"Secret123"}'

User CRUD example (requires the Authorization header):

curl http://localhost:8080/api/users \
  -H "Authorization: Bearer <token>"

Response:

[{"id":1,"name":"Andersson Sanchez","email":"andersson@example.com","phone":"3001234567"}]

Note: users are stored in-memory in a HashMap, so the data resets every time the application restarts.

Project Structure

src/main/java/com/andersson/bookingsystemapi/
├── BookingSystemApiApplication.java   # Spring Boot entry point
├── controller/
│   ├── health/
│   │   └── HealthController.java      # GET /health
│   ├── user/
│   │   └── UserController.java        # /api/users CRUD endpoints
│   └── auth/
│       ├── AuthenticationController.java  # /api/auth/register, /api/auth/login
│       └── dto/
│           ├── RegisterRequest.java
│           ├── LoginRequest.java
│           └── AuthenticationResponse.java
├── security/
│   ├── SecurityConfiguration.java     # HttpSecurity rules, filter chain
│   ├── PasswordEncoderConfig.java     # BCryptPasswordEncoder bean
│   ├── JwtService.java                # Token generation/validation (JJWT)
│   ├── JwtAuthenticationFilter.java   # Reads the Bearer token on every request
│   └── CustomUserDetailsService.java  # Loads a User as Spring Security UserDetails
├── service/
│   ├── UserService.java               # User service interface
│   └── impl/
│       └── UserServiceImpl.java       # HashMap-based implementation (@Service)
├── model/
│   └── User.java                      # User model
└── exception/
    └── UserNotFoundException.java     # 404 when a user id doesn't exist

Building

./mvnw clean package

The packaged jar is generated at target/booking-system-api-0.0.1-SNAPSHOT.jar and can be run with:

java -jar target/booking-system-api-0.0.1-SNAPSHOT.jar

Testing

Unit tests for the service layer use JUnit 5 and Mockito:

./mvnw test
  • UserServiceImplTest — the in-memory CRUD service, with PasswordEncoder mocked.
  • JwtServiceTest — token generation/validation, expiry, and the random-key fallback.
  • CustomUserDetailsServiceTest — mapping a User to Spring Security's UserDetails.

JaCoCo runs on every test and writes an HTML report to target/site/jacoco/index.html; each of the services above is covered at 100% (lines) / 83%+ (branches), above the 70% target.

Deployment (Render)

The API deploys as a Docker container. render.yaml is a Render Blueprint that describes the service, so Render can pick up the whole configuration in one step:

  1. Push this repo to GitHub (already done if you're reading this from there).
  2. On Render, go to New + → Blueprint, and connect this GitHub repository. Authorize Render's GitHub App if this is the first time.
  3. Render reads render.yaml and proposes one Web Service (booking-system-api, Docker runtime, main branch, /health as the health check path). Click Apply.
  4. Render builds the Dockerfile and deploys. JWT_SECRET is generated automatically by the blueprint (generateValue: true) and stays stable across deploys, unlike the random-per-restart local default.
  5. Auto-deploy is on by default: every push to main triggers a new build and rollout, so the Render URL always tracks the latest commit.

If you'd rather create the service by hand instead of using the Blueprint: New + → Web Service → select this repo → Runtime: Docker → Branch: main → Health Check Path: /health → add the same JWT_SECRET / JWT_EXPIRATION env vars → Create Web Service.

Test the deployed instance the same way as local:

curl https://booking-system-api-tn5k.onrender.com/health

Note: the free Render plan spins the instance down after inactivity, so the first request after a quiet period can take a few extra seconds while it wakes back up.

About

REST API for a booking/reservation system, the integrator project of the Ada School backend course. Java 17 and Spring Boot with Spring Security, BCrypt and JWT authentication, Dockerized and auto-deployed to Render.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages