{"id":24773963,"url":"https://github.com/marioszocs/spring-boot-hotel-reservation-api","last_synced_at":"2025-10-11T22:30:51.572Z","repository":{"id":158978955,"uuid":"577860519","full_name":"marioszocs/spring-boot-hotel-reservation-api","owner":"marioszocs","description":"A detailed Standalone RESTful web service example application with the use of Spring Boot framework","archived":false,"fork":false,"pushed_at":"2025-02-11T15:43:09.000Z","size":143,"stargazers_count":13,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-04T23:51:16.334Z","etag":null,"topics":["h2-database","hibernate-jpa","integration-testing","java21","jpa","junit5","lombok","microservices","mockito","mysql-database","restful-api","restful-webservices","spring-boot-3","spring-framework","standalone","swagger-ui"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marioszocs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-13T17:34:00.000Z","updated_at":"2025-03-02T12:53:09.000Z","dependencies_parsed_at":"2025-02-10T20:40:51.005Z","dependency_job_id":null,"html_url":"https://github.com/marioszocs/spring-boot-hotel-reservation-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/marioszocs/spring-boot-hotel-reservation-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marioszocs%2Fspring-boot-hotel-reservation-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marioszocs%2Fspring-boot-hotel-reservation-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marioszocs%2Fspring-boot-hotel-reservation-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marioszocs%2Fspring-boot-hotel-reservation-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marioszocs","download_url":"https://codeload.github.com/marioszocs/spring-boot-hotel-reservation-api/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marioszocs%2Fspring-boot-hotel-reservation-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279009071,"owners_count":26084549,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["h2-database","hibernate-jpa","integration-testing","java21","jpa","junit5","lombok","microservices","mockito","mysql-database","restful-api","restful-webservices","spring-boot-3","spring-framework","standalone","swagger-ui"],"created_at":"2025-01-29T05:20:17.605Z","updated_at":"2025-10-11T22:30:51.560Z","avatar_url":"https://github.com/marioszocs.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Hotel Reservation API\n\nThis project provides a **RESTful API** for hotel reservations. It enables users to create hotels, make reservations, search for availability, and manage existing data. The project is implemented using **Spring Boot**, with a focus on clean architecture and proper validations.\n\n---\n\n## Features\n- **Hotel Management**:\n  - Create, update, and delete hotels.\n  - Search for hotels by availability or retrieve all existing hotels.\n  - Each hotel has attributes such as name, type (e.g., DELUXE, LUXURY, SUITE), availability dates, and status.\n\n- **Reservation Management**:\n  - Make reservations for a specific hotel, including check-in and check-out dates, number of guests, and status.\n  - View or delete existing reservations.\n  - Ensures logical validations, such as no overlapping reservations for the same hotel.\n\n- **Validations**:\n  - Prevent overlapping reservations for the same hotel.\n  - Ensure valid date ranges and proper input formats (e.g., `YYYY-MM-DD`).\n  - Disallow deletion of hotels with active reservations.\n\n---\n\n## Explore REST APIs\n\n### Hotel APIs\n\n![image](https://github.com/user-attachments/assets/cb224507-8968-441a-a1d5-600c1271c401)\n\n\n\n| Method | Endpoint | Description |\n| ------ | -------- | ----------- |\n| POST   | `/api/v1/hotel` | Create a new hotel. |\n| PATCH  | `/api/v1/hotel` | Update an existing hotel. |\n| GET    | `/api/v1/hotels` | Retrieve all hotels. |\n| GET    | `/api/v1/hotels/availabilitySearch?dateFrom={from}\u0026dateTo={to}` | Get available hotels for a date range. |\n| GET    | `/api/v1/hotel/{id}` | Retrieve a specific hotel by ID. |\n| DELETE | `/api/v1/hotel/{id}` | Delete a hotel by ID. |\n\n#### Example Request: Create a New Hotel\n**Request Body:**\n```json\n{\n  \"name\": \"Luxury Inn\",\n  \"type\": \"LUXURY\",\n  \"description\": \"A luxurious hotel in the city center.\",\n  \"availableFrom\": \"2025-01-01\",\n  \"availableTo\": \"2025-12-31\",\n  \"status\": true\n}\n```\n**Response:**\n```json\n{\n  \"id\": 1,\n  \"name\": \"Luxury Inn\",\n  \"type\": \"LUXURY\",\n  \"description\": \"A luxurious hotel in the city center.\",\n  \"availableFrom\": \"2025-01-01\",\n  \"availableTo\": \"2025-12-31\",\n  \"status\": true\n}\n```\n\n---\n\n### Reservation APIs\n\n![image](https://github.com/user-attachments/assets/d51a7e5d-481c-46ed-8bda-a31314e212ff)\n\n\n\n| Method | Endpoint | Description |\n| ------ | -------- | ----------- |\n| POST   | `/api/v1/reservation` | Create a reservation for a hotel. |\n| GET    | `/api/v1/reservations` | Retrieve all reservations. |\n| GET    | `/api/v1/reservation/{id}` | Retrieve a reservation by ID. |\n| DELETE | `/api/v1/reservation/{id}` | Delete a reservation by ID. |\n\n#### Example Request: Create a Reservation\n**Request Body:**\n```json\n{\n  \"hotelId\": 1,\n  \"checkIn\": \"2025-03-15\",\n  \"checkOut\": \"2025-03-20\",\n  \"guests\": 2,\n  \"status\": true\n}\n```\n**Response:**\n```json\n{\n  \"id\": 101,\n  \"hotelId\": 1,\n  \"checkIn\": \"2025-03-15\",\n  \"checkOut\": \"2025-03-20\",\n  \"guests\": 2,\n  \"status\": true\n}\n```\n\n\n\n---\n\n## Database Structure\nThe API uses a **MySQL database** with the following tables:\n\n### `hotel`\n| Column          | Type       | Description                         |\n| --------------- | ---------- | ----------------------------------- |\n| `id`            | Integer    | Primary key.                        |\n| `name`          | String     | Hotel name.                         |\n| `type`          | Enum       | `DELUXE`, `LUXURY`, or `SUITE`.     |\n| `description`   | String     | Description of the hotel.           |\n| `availableFrom` | Date       | Start date of availability.         |\n| `availableTo`   | Date       | End date of availability.           |\n| `status`        | Boolean    | Availability status.                |\n\n### `reservation`\n| Column       | Type    | Description                          |\n| ------------ | ------- | ------------------------------------ |\n| `id`         | Integer | Primary key.                         |\n| `hotelId`    | Integer | Foreign key referencing `hotel`.     |\n| `checkIn`    | Date    | Check-in date.                       |\n| `checkOut`   | Date    | Check-out date.                      |\n| `guests`     | Integer | Number of guests.                    |\n| `status`     | Boolean | Reservation status.                  |\n\n### Example SQL Script to Set Up the Schema\n```sql\nCREATE TABLE hotel (\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    name VARCHAR(255) NOT NULL,\n    type ENUM('DELUXE', 'LUXURY', 'SUITE') NOT NULL,\n    description TEXT,\n    availableFrom DATE NOT NULL,\n    availableTo DATE NOT NULL,\n    status BOOLEAN NOT NULL\n);\n\nCREATE TABLE reservation (\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    hotelId INT NOT NULL,\n    checkIn DATE NOT NULL,\n    checkOut DATE NOT NULL,\n    guests INT NOT NULL,\n    status BOOLEAN NOT NULL,\n    FOREIGN KEY (hotelId) REFERENCES hotel(id)\n);\n\nINSERT INTO hotel (name, type, description, availableFrom, availableTo, status) VALUES\n('Luxury Inn', 'LUXURY', 'A luxurious hotel in the city center.', '2025-01-01', '2025-12-31', true),\n('City Center Suites', 'DELUXE', 'Conveniently located in the heart of the city.', '2025-01-01', '2025-12-31', true);\n```\n\n---\n\n## Tech Stack\n- **Backend**: Java 21, Spring Boot 3, Hibernate, JPA\n- **Database**: MySQL (runtime), H2 (testing)\n- **API Documentation**: Swagger UI\n- **Testing**: JUnit 5, Mockito\n- **Utilities**: Lombok, Maven\n\n---\n\n## Project Structure\n```\nmarioszocs-spring-boot-hotel-reservation-api/\n├── README.md\n├── mvnw\n├── mvnw.cmd\n├── pom.xml\n├── src/\n│   ├── main/\n│   │   ├── java/\n│   │   │   └── dev/marioszocs/hotelreservationapi/\n│   │   │       ├── HotelReservationApiApplication.java\n│   │   │       ├── ServletInitializer.java\n│   │   │       ├── bootstrap/\n│   │   │       │   └── HotelsAndReservationsLoader.java\n│   │   │       ├── config/\n│   │   │       │   └── OpenApiConfig.java\n│   │   │       ├── constants/\n│   │   │       │   ├── AppConstants.java\n│   │   │       │   └── ErrorMessages.java\n│   │   │       ├── controller/\n│   │   │       │   ├── HotelController.java\n│   │   │       │   └── ReservationController.java\n│   │   │       ├── entity/\n│   │   │       │   ├── Hotel.java\n│   │   │       │   ├── Reservation.java\n│   │   │       │   └── ValidTypesOfHotelsEnum.java\n│   │   │       ├── repository/\n│   │   │       │   ├── HotelRepository.java\n│   │   │       │   └── ReservationRepository.java\n│   │   │       ├── service/\n│   │   │       │   ├── HotelService.java\n│   │   │       │   └── ReservationService.java\n│   │   │       ├── serviceImp/\n│   │   │       │   ├── HotelServiceImp.java\n│   │   │       │   └── ReservationServiceImp.java\n│   │   │       ├── utils/\n│   │   │       │   └── AppUtils.java\n│   │   │       └── validator/\n│   │   │           ├── HotelValidator.java\n│   │   │           └── ReservationValidator.java\n│   │   └── resources/\n│   │       ├── application-h2.properties\n│   │       ├── application-mysql.properties\n│   │       └── application.properties\n├── .mvn/\n│   └── wrapper/\n│       └── maven-wrapper.properties\n```\n\n---\n\n## Testing\n- Includes **unit tests** (with Mockito) and **integration tests** (using H2 in-memory database).\n- Coverage:\n  - **93%** of classes.\n  - **94%** of methods.\n  - **85%** of lines.\n- Test scenarios:\n  - API endpoint responses.\n  - Validation of inputs and error handling.\n  - Business logic for reservations and hotel availability.\n\n---\n\n## Installation\n\n### Prerequisites\n- Java 21\n- Maven\n- MySQL (if not using the H2 database)\n\n### Steps\n1. Clone the repository:\n   ```bash\n   git clone https://github.com/your-username/hotel-reservation-api.git\n   cd hotel-reservation-api\n   ```\n2. Configure the database in `src/main/resources/application.properties`:\n   ```properties\n   spring.datasource.url=jdbc:mysql://localhost:3306/hotel_reservation_db\n   spring.datasource.username=your-username\n   spring.datasource.password=your-password\n   ```\n3. Build the project:\n   ```bash\n   mvn clean install\n   ```\n4. Run the application:\n   ```bash\n   mvn spring-boot:run\n   ```\n\n---\n\n## Contribution\nContributions are welcome! Feel free to fork the repository and submit a pull request.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarioszocs%2Fspring-boot-hotel-reservation-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarioszocs%2Fspring-boot-hotel-reservation-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarioszocs%2Fspring-boot-hotel-reservation-api/lists"}