source: README.md

Last change on this file was 09e02d7, checked in by Nikola Sarafimov <sarafimov.nikola12345@…>, 3 days ago

Final room reservation system implementation

  • Property mode set to 100644
File size: 8.7 KB
Line 
1# Room Reservation System
2
3A full-stack database-oriented Room Reservation System developed for the Databases course project.
4
5The application allows users to search available rooms, create reservation requests, add optional equipment, approve or reject pending reservations, and view analytical reports generated from live PostgreSQL data.
6
7---
8
9## Project Overview
10
11The system manages shared rooms, equipment, users, reservations, and approval decisions.
12
13A reservation can include:
14
15- a room only,
16- equipment only,
17- both a room and equipment.
18
19The main goal of the project is to demonstrate correct relational database design, SQL implementation, database constraints, transactions, advanced SQL reports, and a working application connected to the faculty PostgreSQL database.
20
21---
22
23## Technologies Used
24
25### Backend
26
27- Java 21
28- Spring Boot
29- Spring JDBC / JdbcTemplate
30- HikariCP connection pooling
31- PostgreSQL
32- BCrypt password hashing
33- Maven
34- Docker
35
36### Frontend
37
38- React
39- Vite
40- JavaScript
41- CSS
42- Lucide React icons
43- Framer Motion
44- React Hot Toast
45- Docker / Nginx
46
47### Database
48
49- PostgreSQL
50- Faculty database accessed through SSH tunnel
51- Schema: `project`
52
53---
54
55## Main Features
56
57### User Access
58
59- User registration
60- User sign in with username or email
61- Password hashing using BCrypt
62- Role-based navigation:
63 - `regular`
64 - `approver`
65 - `admin`
66
67### Dashboard
68
69- Live system overview
70- Room count
71- Equipment count
72- User count
73- Pending reservation count
74- Approved reservation count
75- Current database connection status
76
77### Search Rooms
78
79- Search available rooms by:
80 - reservation date
81 - start time
82 - end time
83 - minimum capacity
84 - room type
85 - required equipment
86
87### Create Reservation
88
89- Create a pending reservation request
90- Select an available room
91- Create equipment-only reservations
92- Add optional equipment with quantity
93- Validate empty reservations
94- Store reservation data in the PostgreSQL database
95
96### Approvals
97
98- View pending reservations
99- Approve or reject requests
100- Uses PostgreSQL stored function logic
101- Updates reservation status and approval records
102
103### Reports
104
105- Advanced SQL reports based on live project data
106- Room utilization report
107- Equipment demand and stock risk report
108- Grouping, aggregation, ranking, and analytical SQL logic
109
110### Admin Panel
111
112- Read-only overview for administrator users
113- Users overview
114- Equipment overview
115- Pending reservations overview
116
117---
118
119## Database Connection
120
121The application connects to the faculty PostgreSQL database through an SSH tunnel.
122
123Before starting the backend, the tunnel must be running and forwarding the database to local port `9999`.
124
125Expected local tunnel port:
126
127```text
128localhost:9999
129```
130
131Backend local database URL:
132
133```text
134jdbc:postgresql://localhost:9999/db_202526z_va_prj_room_reservation
135```
136
137Docker database URL:
138
139```text
140jdbc:postgresql://host.docker.internal:9999/db_202526z_va_prj_room_reservation
141```
142
143---
144
145## Environment Variables
146
147Create a local `.env` file in the root folder.
148
149```env
150SPRING_DATASOURCE_URL=jdbc:postgresql://host.docker.internal:9999/db_202526z_va_prj_room_reservation
151SPRING_DATASOURCE_USERNAME=db_202526z_va_prj_room_reservation_owner
152SPRING_DATASOURCE_PASSWORD=YOUR_DATABASE_PASSWORD_HERE
153```
154
155---
156
157## Required Database Objects
158
159The application expects the following database objects to exist in schema `project`:
160
161### Main Tables
162
163```text
164project.buildings
165project.rooms
166project.equipment
167project.room_equipment
168project.users
169project.reservations
170project.reservation_equipment
171project.approvals
172project.user_credentials
173```
174
175### Views
176
177```text
178project.v_pending_reservation_details
179project.v_quarterly_room_utilization
180```
181
182### Stored Function
183
184```text
185project.fn_approve_or_reject_reservation
186```
187
188### Domain
189
190```text
191project.approval_decision_domain
192```
193
194---
195
196## Authentication Table
197
198The UI authentication flow uses an additional table for password hashes.
199
200The SQL script is located in:
201
202```text
203backend/src/main/resources/authentication-table.sql
204```
205
206SQL:
207
208```sql
209CREATE TABLE IF NOT EXISTS project.user_credentials (
210 user_id INTEGER NOT NULL,
211 password_hash VARCHAR(255) NOT NULL,
212 created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
213 updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
214
215 CONSTRAINT pk_user_credentials PRIMARY KEY (user_id),
216
217 CONSTRAINT fk_user_credentials_users FOREIGN KEY (user_id)
218 REFERENCES project.users(user_id)
219 ON DELETE CASCADE
220 ON UPDATE CASCADE
221);
222```
223
224This table stores hashed passwords only. Plain text passwords are not stored.
225
226---
227
228## Run the Application Locally
229
230### 1. Start the SSH Tunnel
231
232Start the faculty tunnel script and keep the tunnel window open.
233
234The tunnel should forward the database to:
235
236```text
237localhost:9999
238```
239
240---
241
242### 2. Start Backend Locally
243
244From the root folder:
245
246```bash
247cd backend
248mvn spring-boot:run
249```
250
251Backend URL:
252
253```text
254http://localhost:8080
255```
256
257Health endpoint:
258
259```text
260http://localhost:8080/api/health
261```
262
263Expected response example:
264
265```json
266{
267 "status": "UP",
268 "database": "PostgreSQL",
269 "schema": "project",
270 "roomCount": 5
271}
272```
273
274---
275
276### 3. Start Frontend Locally
277
278Open a new terminal:
279
280```bash
281cd frontend
282npm install
283npm run dev
284```
285
286Frontend development URL:
287
288```text
289http://localhost:5173
290```
291
292---
293
294## Run with Docker Compose
295
296Make sure the SSH tunnel is running first.
297
298Then run:
299
300```bash
301docker compose up -d --build
302```
303
304Frontend Docker URL:
305
306```text
307http://localhost:3000
308```
309
310Backend Docker URL:
311
312```text
313http://localhost:8080
314```
315
316Health endpoint:
317
318```text
319http://localhost:8080/api/health
320```
321
322Stop containers:
323
324```bash
325docker compose down
326```
327
328---
329
330## Backend API Endpoints
331
332### Health and Dashboard
333
334```text
335GET /api/health
336GET /api/dashboard
337```
338
339### Authentication
340
341```text
342POST /api/auth/register
343POST /api/auth/login
344POST /api/auth/activate
345```
346
347### Users
348
349```text
350GET /api/users
351GET /api/approvers
352```
353
354### Rooms
355
356```text
357GET /api/rooms
358POST /api/rooms/search
359```
360
361### Equipment
362
363```text
364GET /api/equipment
365```
366
367### Reservations
368
369```text
370POST /api/reservations
371GET /api/reservations/{id}
372GET /api/reservations/pending
373```
374
375### Approvals
376
377```text
378POST /api/approvals
379```
380
381### Reports
382
383```text
384GET /api/reports/room-utilization
385GET /api/reports/equipment-demand
386```
387
388---
389
390## Example API Requests
391
392### Register User
393
394```json
395POST /api/auth/register
396
397{
398 "fullName": "Nikola Test",
399 "username": "nikolatest",
400 "email": "nikola.test@example.com",
401 "password": "Password123!"
402}
403```
404
405### Login User
406
407```json
408POST /api/auth/login
409
410{
411 "identifier": "nikolatest",
412 "password": "Password123!"
413}
414```
415
416### Search Available Rooms
417
418```json
419POST /api/rooms/search
420
421{
422 "reservationDate": "2026-07-20",
423 "startTime": "09:00",
424 "endTime": "10:00",
425 "minimumCapacity": 1,
426 "roomType": "",
427 "requiredEquipmentName": ""
428}
429```
430
431### Create Reservation
432
433```json
434POST /api/reservations
435
436{
437 "userId": 1,
438 "reservationDate": "2026-07-20",
439 "startTime": "09:00",
440 "endTime": "10:00",
441 "roomId": 1,
442 "equipment": [
443 {
444 "equipmentId": 1,
445 "requestedQuantity": 1
446 }
447 ]
448}
449```
450
451### Approve Reservation
452
453```json
454POST /api/approvals
455
456{
457 "reservationId": 1,
458 "approverId": 2,
459 "decision": "approved",
460 "note": "Approved through React UI."
461}
462```
463
464---
465
466## Testing Through DBeaver
467
468After using the UI, the changes can be verified directly in DBeaver.
469
470### Check Registered Users
471
472```sql
473SELECT *
474FROM project.users
475ORDER BY user_id DESC;
476```
477
478### Check User Credentials
479
480```sql
481SELECT *
482FROM project.user_credentials
483ORDER BY user_id DESC;
484```
485
486### Check Created Reservations
487
488```sql
489SELECT *
490FROM project.reservations
491ORDER BY reservation_id DESC;
492```
493
494### Check Reservation Equipment
495
496```sql
497SELECT *
498FROM project.reservation_equipment
499ORDER BY reservation_id DESC;
500```
501
502### Check Approvals
503
504```sql
505SELECT *
506FROM project.approvals
507ORDER BY approval_id DESC;
508```
509
510### Check Pending Reservations View
511
512```sql
513SELECT *
514FROM project.v_pending_reservation_details;
515```
516
517### Check Room Utilization View
518
519```sql
520SELECT *
521FROM project.v_quarterly_room_utilization;
522```
523
524---
525
526## Role-Based Testing
527
528The application supports role-based navigation.
529
530To test different roles, update the role of a test user in DBeaver.
531
532### Set User as Regular
533
534```sql
535UPDATE project.users
536SET role = 'regular'
537WHERE username = 'nikolatest';
538```
539
540### Set User as Approver
541
542```sql
543UPDATE project.users
544SET role = 'approver'
545WHERE username = 'nikolatest';
546```
547
548### Set User as Admin
549
550```sql
551UPDATE project.users
552SET role = 'admin'
553WHERE username = 'nikolatest';
554```
555
556After changing the role, log out and log in again.
557
558---
559
560## Build Checks
561
562### Backend Build
563
564```bash
565cd backend
566mvn clean package -DskipTests
567```
568
569### Frontend Build
570
571```bash
572cd frontend
573npm install
574npm run build
575```
576
577### Docker Build
578
579```bash
580docker compose down
581docker compose up -d --build
582```
583
584---
585
586## Author
587
588- Nikola Sarafimov
Note: See TracBrowser for help on using the repository browser.