This is a Spring Boot REST API for managing accommodations, users, hosts, countries, and temporary reservations. It supports user registration, login, and role-based access using Spring Security, as well as reporting endpoints powered by materialized views.
Authentication is handled via Spring Security using form login.
The following users are seeded on startup via the DataInitializer
:
Username | Password | Role |
---|---|---|
user |
user |
USER |
host |
host |
HOST |
- PostgreSQL (via Docker)
- Schema initialized using
schema.sql
with materialized views
To start the DB:
docker-compose up -d
- GET
/api/accommodations
- GET
/api/accommodations/{id}
- POST
/api/accommodations
{
"name": "Beach House",
"category": "HOUSE",
"hostId": 1,
"numRooms": 5
}
- PUT
/api/accommodations/{id}
{
"name": "Updated Beach House",
"category": "HOUSE",
"hostId": 1,
"numRooms": 6
}
-
DELETE
/api/accommodations/{id}
-
PUT
/api/accommodations/rent/{id}
-
GET
/api/accommodations/by-host
- Returns number of accommodations per host (materialized view, refreshed daily)
- GET
/api/hosts
- GET
/api/hosts/{id}
- POST
/api/hosts
{
"name": "Alice",
"surname": "Smith",
"countryId": 1
}
-
PUT
/api/hosts/{id}
-
DELETE
/api/hosts/{id}
-
GET
/api/hosts/by-country
- Returns number of hosts per country (materialized view, refreshed on host add/update/delete)
- GET
/api/countries
- GET
/api/countries/{id}
- POST
/api/countries
{
"name": "France",
"continent": "Europe"
}
- PUT
/api/countries/{id}
- DELETE
/api/countries/{id}
- POST
/api/auth/register
{
"username": "newuser",
"password": "securepass",
"role": "USER"
}
- POST
/api/auth/login
{
"username": "user",
"password": "user"
}
- POST
/api/auth/logout
Users can maintain a temporary list of accommodations before confirming reservations.
- GET
/api/reservations
- POST
/api/reservations
{
"accommodationId": 2
}
- DELETE
/api/reservations/{id}
- POST
/api/reservations/confirm
curl -X POST http://localhost:8080/api/auth/login \
-H "Content-Type: application/json" \
-d '{"username":"user", "password":"user"}'
curl -X POST http://localhost:8080/api/accommodations \
-H "Content-Type: application/json" \
-d '{"name":"Cozy Flat", "category":"APARTMENT", "hostId":1, "numRooms":3}'
curl http://localhost:8080/api/accommodations/by-host
curl http://localhost:8080/api/hosts/by-country
Use Swagger to explore and test the API:
- URL: http://localhost:8080/swagger-ui/index.html
- Requires login — use
user/user
orhost/host