A RESTful API built with Spring Boot and PostgreSQL to manage tour packages.
- Create new tour packages
- Retrieve all tour packages
- Get tour package by ID
- Input validation and error handling
- PostgreSQL database integration
- Java 17
- Spring Boot 3.2.0
- Spring Data JPA
- PostgreSQL
- Maven
- Java 17 or higher
- Maven 3.6+
- PostgreSQL 12+
git clone https://github.com/1234-ad/simple-tour-package-api.git
cd simple-tour-package-api- Install PostgreSQL and create a database:
CREATE DATABASE tour_package_db;- Update database credentials in
src/main/resources/application.properties:
spring.datasource.url=jdbc:postgresql://localhost:5432/tour_package_db
spring.datasource.username=your_username
spring.datasource.password=your_password# Build the project
mvn clean install
# Run the application
mvn spring-boot:runThe API will be available at http://localhost:8080
- URL:
POST /api/tours - Content-Type:
application/json - Request Body:
{
"image": "https://images.unsplash.com/photo-1598275277521-1885382d523a",
"discountInPercentage": "17%",
"title": "Himalayan Trek Adventure",
"description": "14-day trek through the Himalayas",
"duration": "14Days/13Nights",
"actualPrice": "$1200",
"discountedPrice": "$1000"
}- URL:
GET /api/tours - Response: Array of tour packages
- URL:
GET /api/tours/{id} - Response: Single tour package object
curl -X POST http://localhost:8080/api/tours \
-H "Content-Type: application/json" \
-d '{
"image": "https://images.unsplash.com/photo-1598275277521-1885382d523a",
"discountInPercentage": "17%",
"title": "Himalayan Trek Adventure",
"description": "14-day trek through the Himalayas",
"duration": "14Days/13Nights",
"actualPrice": "$1200",
"discountedPrice": "$1000"
}'curl -X GET http://localhost:8080/api/tourscurl -X GET http://localhost:8080/api/tours/1The API includes comprehensive error handling:
- 400 Bad Request: Invalid input data
- 404 Not Found: Tour package not found
- 500 Internal Server Error: Server errors
All required fields are validated:
image: Must not be blankdiscountInPercentage: Must not be blanktitle: Must not be blankdescription: Must not be blankduration: Must not be blankactualPrice: Must not be blankdiscountedPrice: Must not be blank
src/
├── main/
│ ├── java/com/mapmytour/api/
│ │ ├── TourPackageApiApplication.java
│ │ ├── controller/
│ │ │ └── TourPackageController.java
│ │ ├── entity/
│ │ │ └── TourPackage.java
│ │ ├── exception/
│ │ │ └── GlobalExceptionHandler.java
│ │ ├── repository/
│ │ │ └── TourPackageRepository.java
│ │ └── service/
│ │ └── TourPackageService.java
│ └── resources/
│ └── application.properties
└── test/
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License.