A Java Spring Boot application with GraphQL API for event booking, replicated from the TypeScript/Node.js version.
- GraphQL API with Spring GraphQL
- PostgreSQL Database with Spring Data JDBC
- JWT Authentication and authorization
- Event Management (create, read events)
- Venue Management (create, read venues)
- Artist Management (create, read artists)
- Booking System (create bookings with tickets)
- User Management (registration, login)
- Comprehensive Tests (unit and integration tests)
- Java 17
- Spring Boot 4.0.0-SNAPSHOT
- Spring GraphQL
- Spring Data JDBC
- PostgreSQL
- JWT (JSON Web Tokens)
- Maven
- Docker
- Java 17+
- Maven 3.6+
- Docker and Docker Compose
- PostgreSQL (or use Docker)
docker-compose up -d postgresmvn clean install
mvn spring-boot:run- GraphQL Playground: http://localhost:8080/graphiql
- GraphQL Endpoint: http://localhost:8080/graphql
query {
events {
id
name
description
eventDate
category
imageUrl
venueId
venue {
id
name
address
location
capacity
}
artists {
id
name
bio
imageUrl
}
}
}query GetEvent($id: ID!) {
event(id: $id) {
id
name
description
eventDate
category
imageUrl
venue {
id
name
address
location
capacity
weather {
temp
feels_like
temp_min
temp_max
humidity
description
}
}
artists {
id
name
bio
imageUrl
}
}
}query {
venues {
id
name
address
location
capacity
events {
id
name
eventDate
category
}
weather {
temp
feels_like
temp_min
temp_max
humidity
description
}
}
}query GetVenue($id: ID!) {
venue(id: $id) {
id
name
address
location
capacity
events {
id
name
description
eventDate
category
imageUrl
}
weather {
temp
feels_like
temp_min
temp_max
humidity
description
}
}
}query GetBookings($eventId: Float!) {
bookings(eventId: $eventId) {
id
bookingDate
eventId
userId
price
tickets {
id
seatNo
bookingId
}
}
}mutation CreateUser($userInput: UserInput!) {
createUser(userInput: $userInput) {
id
name
email
role
}
}Variables:
{
"userInput": {
"name": "John Doe",
"email": "john@example.com",
"password": "password123",
"role": "ROLE_USER"
}
}mutation CreateVenue($venueInput: VenueInput!) {
createVenue(venueInput: $venueInput) {
id
name
address
location
capacity
}
}Variables:
{
"venueInput": {
"name": "Madison Square Garden",
"address": "4 Pennsylvania Plaza",
"location": "New York, NY",
"capacity": 20789
}
}mutation CreateEvent($eventInput: EventInput!) {
createEvent(eventInput: $eventInput) {
id
name
description
eventDate
category
imageUrl
venueId
}
}Variables:
{
"eventInput": {
"name": "Spring Music Festival",
"description": "A fantastic music festival featuring top artists",
"eventDate": "2024-06-15T19:00:00",
"category": "Concert",
"imageUrl": "https://example.com/festival.jpg",
"venueId": 1,
"artistIds": [1, 2, 3]
}
}mutation CreateBooking($bookingInput: BookingInput!) {
createBooking(bookingInput: $bookingInput) {
id
bookingDate
eventId
userId
price
tickets {
id
seatNo
bookingId
}
}
}Variables:
{
"bookingInput": {
"eventId": 1,
"seats": [1, 2, 3, 4]
}
}Here's a complete example of creating a venue, event, and booking:
mutation {
createVenue(venueInput: {
name: "Concert Hall"
address: "123 Music Street"
location: "New York, NY"
capacity: 5000
}) {
id
name
capacity
}
}mutation {
createEvent(eventInput: {
name: "Rock Concert 2024"
description: "Amazing rock concert with top artists"
eventDate: "2024-07-15T20:00:00"
category: "Concert"
imageUrl: "https://example.com/rock-concert.jpg"
venueId: 1
artistIds: [1, 2]
}) {
id
name
eventDate
venueId
}
}mutation {
createUser(userInput: {
name: "Alice Smith"
email: "alice@example.com"
password: "securepassword"
role: "ROLE_USER"
}) {
id
name
email
}
}mutation {
createBooking(bookingInput: {
eventId: 1
seats: [10, 11, 12]
}) {
id
bookingDate
price
tickets {
seatNo
}
}
}query {
events {
id
name
description
eventDate
category
venue {
id
name
location
capacity
weather {
temp
description
}
}
artists {
id
name
bio
}
}
}The application creates the following tables:
users- User accountsvenues- Event venuesartists- Event artistsevents- Eventsevent_artists- Many-to-many relationship between events and artistsbookings- User bookingstickets- Individual tickets for bookings
# Run all tests
mvn test
# Run specific test class
mvn test -Dtest=EventControllerTest
# Run integration tests
mvn test -Dtest=EventBookingIntegrationTestThe project includes:
- Unit tests for controllers
- Integration tests with H2 in-memory database
- GraphQL query/mutation tests
Key configuration in application.properties:
# Database
spring.datasource.url=jdbc:postgresql://localhost:5432/event_booking
spring.datasource.username=postgres
spring.datasource.password=password
# GraphQL
spring.graphql.graphiql.enabled=true
spring.graphql.path=/graphql
# JWT
jwt.secret=mySecretKey
jwt.expiration=86400000src/
├── main/
│ ├── java/com/codewiz/eventbooking/
│ │ ├── controller/ # GraphQL controllers
│ │ ├── entity/ # Domain entities
│ │ ├── repository/ # Data repositories
│ │ ├── dto/ # Data transfer objects
│ │ └── security/ # Security configuration
│ └── resources/
│ ├── graphql/ # GraphQL schema
│ ├── schema.sql # Database schema
│ └── data.sql # Sample data
└── test/
├── java/ # Test classes
└── resources/ # Test configuration
- Create entity classes in
entity/package - Create repository interfaces in
repository/package - Add GraphQL schema definitions in
schema.graphqls - Create controllers in
controller/package - Add tests in
test/package
The application uses schema.sql and data.sql for database initialization. For production, consider using Flyway or Liquibase for proper migration management.
- JWT-based authentication
- Password encryption with BCrypt
- Role-based authorization (ROLE_USER, ROLE_ADMIN)
- CORS configuration for GraphQL endpoints
- GraphQL Playground for API exploration
- H2 Console available in test profile
- Spring Boot Actuator endpoints (if enabled)
- Database Connection: Ensure PostgreSQL is running and accessible
- Port Conflicts: Check if port 8080 is available
- JWT Issues: Verify JWT secret configuration
- GraphQL Errors: Check schema definitions and resolver implementations
Check application logs for detailed error information:
tail -f logs/application.log- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License.