Skip to content

Latest commit

Β 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎫 THE GATEKEEPER LOGIC - Event Ticketing Platform

Backend Event Ticketing System dengan Java Native + MySQL yang mencegah overselling

Java MySQL

Dibuat oleh: Davin Gabriel J
Submission: Backend Web Developer - The Gatekeeper Logic


🎯 Tentang Project

Platform backend untuk sistem tiket event online yang memfasilitasi:

  • Organizer untuk membuat dan mengelola event
  • Customer untuk memesan tiket event
  • Sistem untuk mencegah overselling dengan transaction locking

Problem yang Diselesaikan

Overselling Prevention: Sistem menggunakan Pessimistic Locking untuk memastikan tidak ada tiket yang terjual melebihi kapasitas, bahkan ketika terjadi concurrent requests dari multiple users.


✨ Fitur Utama

πŸ”’ Core Features

  • CRUD Users - Manajemen data pengguna (Customer & Organizer)
  • CRUD Events - Buat, update, dan kelola event
  • CRUD Bookings - Sistem pemesanan tiket
  • Pessimistic Locking - Mencegah race condition
  • Transaction Management - ACID compliance
  • Partial Update - Update field tertentu saja
  • Status Management - Tracking status booking & event

πŸ›‘οΈ Security Features

  • Database transaction dengan BEGIN/COMMIT/ROLLBACK
  • SELECT FOR UPDATE untuk row-level locking
  • Input validation di Service layer
  • Error handling yang comprehensive

πŸ—οΈ Arsitektur & Database

Struktur Project

src/
β”œβ”€β”€ Main.java                    # Entry point & HTTP Server
β”œβ”€β”€ controllers/
β”‚   β”œβ”€β”€ UserController.java      # User endpoints
β”‚   β”œβ”€β”€ EventController.java     # Event endpoints
β”‚   └── BookingController.java   # Booking endpoints
β”œβ”€β”€ services/
β”‚   β”œβ”€β”€ UserService.java         # Business logic - Users
β”‚   β”œβ”€β”€ EventService.java        # Business logic - Events
β”‚   └── BookingService.java      # Business logic - Bookings
β”œβ”€β”€ dao/
β”‚   β”œβ”€β”€ UserDAO.java             # Database access - Users
β”‚   β”œβ”€β”€ EventDAO.java            # Database access - Events
β”‚   └── BookingDAO.java          # Database access - Bookings
└── models/
    β”œβ”€β”€ User.java                # User entity
    β”œβ”€β”€ Event.java               # Event entity
    └── Booking.java             # Booking entity

Database Schema

Table: USERS

CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(50) UNIQUE NOT NULL,
    email VARCHAR(100) UNIQUE NOT NULL,
    password VARCHAR(255) NOT NULL,
    full_name VARCHAR(100) NOT NULL,
    phone VARCHAR(20),
    role ENUM('CUSTOMER', 'ORGANIZER') DEFAULT 'CUSTOMER',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Table: EVENTS

CREATE TABLE events (
    id INT AUTO_INCREMENT PRIMARY KEY,
    organizer_id INT NOT NULL,
    event_name VARCHAR(200) NOT NULL,
    description TEXT,
    event_date DATETIME NOT NULL,
    location VARCHAR(200) NOT NULL,
    total_capacity INT NOT NULL,
    available_tickets INT NOT NULL,
    ticket_price DECIMAL(10,2) NOT NULL,
    status ENUM('ACTIVE', 'CANCELLED', 'COMPLETED') DEFAULT 'ACTIVE',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    FOREIGN KEY (organizer_id) REFERENCES users(id)
);

Table: BOOKINGS

CREATE TABLE bookings (
    id INT AUTO_INCREMENT PRIMARY KEY,
    user_id INT NOT NULL,
    event_id INT NOT NULL,
    quantity INT NOT NULL,
    total_price DECIMAL(10,2) NOT NULL,
    status ENUM('PENDING', 'CONFIRMED', 'CANCELLED') DEFAULT 'PENDING',
    booking_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    FOREIGN KEY (user_id) REFERENCES users(id),
    FOREIGN KEY (event_id) REFERENCES events(id)
);

πŸš€ Cara Install

Prerequisites

  • Java JDK 11+
  • MySQL 8.0+
  • Git

Step 1: Clone Repository

git clone https://github.com/Davin164/BE_Submission_The-Gatekeeper-Logic.git
cd BE_Submission_The-Gatekeeper-Logic

Step 2: Setup Database

# Login ke MySQL
mysql -u root
mysql -u root -p (jika ada password)

# Jalankan database.sql
source database.sql

Step 3: Configure Environment

# Copy .env.example ke .env
cp .env.example .env

# Edit .env sesuai konfigurasi MySQL kamu
nano .env

Isi .env:

DB_HOST=localhost
DB_PORT=3306
DB_NAME=event_ticketing
DB_USER=root
DB_PASSWORD=your_password

Step 4: Compile & Run

# Compile
bash compile.sh

# Run server
bash run.sh

Server akan berjalan di: http://localhost:8080


πŸ“š API Documentation

Base URL

http://localhost:8080/api

πŸ‘€ USERS ENDPOINTS

1. Get All Users

GET /api/users

Response Success (200):

[
  {
    "id": 1,
    "username": "johndoe",
    "email": "john@example.com",
    "fullName": "John Doe",
    "phone": "081234567890",
    "role": "CUSTOMER",
    "createdAt": "2024-12-24T10:30:00"
  }
]

2. Get User by ID

GET /api/users/{id}

3. Create User

POST /api/users
Content-Type: application/json

Request Body:

{
  "username": "johndoe",
  "email": "john@example.com",
  "password": "password123",
  "fullName": "John Doe",
  "phone": "081234567890",
  "role": "CUSTOMER"
}

Response Success (201):

{
  "id": 1,
  "username": "johndoe",
  "email": "john@example.com",
  "fullName": "John Doe",
  "role": "CUSTOMER"
}

4. Update User

PUT /api/users/{id}
Content-Type: application/json

Request Body (Partial):

{
  "fullName": "John Doe Updated",
  "phone": "081234567999"
}

5. Delete User

DELETE /api/users/{id}

πŸŽͺ EVENTS ENDPOINTS

1. Get All Events

GET /api/events

Response Success (200):

[
  {
    "id": 1,
    "organizerId": 1,
    "eventName": "Music Festival 2025",
    "description": "Amazing music festival",
    "eventDate": "2025-06-15T18:00:00",
    "location": "Jakarta Convention Center",
    "totalCapacity": 5000,
    "availableTickets": 4500,
    "ticketPrice": 150000.00,
    "status": "ACTIVE",
    "createdAt": "2024-12-24T10:00:00"
  }
]

2. Get Event by ID

GET /api/events/{id}

3. Create Event

POST /api/events
Content-Type: application/json

Request Body:

{
  "organizerId": 1,
  "eventName": "Music Festival 2025",
  "description": "Amazing music festival",
  "eventDate": "2025-06-15 18:00:00",
  "location": "Jakarta Convention Center",
  "totalCapacity": 5000,
  "ticketPrice": 150000.00
}

Response Success (201):

{
  "id": 1,
  "eventName": "Music Festival 2025",
  "availableTickets": 5000,
  "status": "ACTIVE"
}

4. Update Event

PUT /api/events/{id}
Content-Type: application/json

Request Body (Partial):

{
  "ticketPrice": 120000.00,
  "status": "ACTIVE"
}

5. Delete Event

DELETE /api/events/{id}

🎟️ BOOKINGS ENDPOINTS

1. Get All Bookings

GET /api/bookings

2. Get Booking by ID

GET /api/bookings/{id}

3. Get User Bookings

GET /api/bookings/user/{userId}

4. Get Event Bookings

GET /api/bookings/event/{eventId}

5. Create Booking (WITH LOCKING) πŸ”’

POST /api/bookings
Content-Type: application/json

Request Body:

{
  "userId": 2,
  "eventId": 1,
  "quantity": 2
}

Response Success (201):

{
  "id": 1,
  "userId": 2,
  "eventId": 1,
  "quantity": 2,
  "totalPrice": 300000.00,
  "status": "PENDING",
  "bookingDate": "2024-12-24T14:30:00"
}

Response Error (400):

{
  "error": "Not enough tickets available"
}

6. Confirm Booking

PUT /api/bookings/{id}/confirm

7. Cancel Booking

PUT /api/bookings/{id}/cancel

8. Delete Booking

DELETE /api/bookings/{id}

πŸ§ͺ Testing

Testing dengan Thunder Client (VSCode)

  1. Install extension Thunder Client
  2. Import collection atau create new request
  3. Set method dan URL
  4. Untuk POST/PUT, tambahkan body JSON
  5. Klik Send

Testing Script

Gunakan script yang sudah disediakan:

# Test semua endpoints
bash test_api.sh

Manual Testing Examples

Test Overselling Prevention

# Terminal 1: Booking 100 tiket
curl -X POST http://localhost:8080/api/bookings \
  -H "Content-Type: application/json" \
  -d '{"userId": 2, "eventId": 1, "quantity": 100}'

# Terminal 2: Booking 100 tiket (simultaneous)
curl -X POST http://localhost:8080/api/bookings \
  -H "Content-Type: application/json" \
  -d '{"userId": 3, "eventId": 1, "quantity": 100}'

πŸ› οΈ Technology Stack

  • Language: Java (Native) JDK16
  • Database: MySQL 8.0+
  • Run API Test: Thunder Client (extension VSCode)

πŸ‘¨β€πŸ’» Author

Davin Gabriel J


πŸ™ Acknowledgments

  • Submission ini untuk kepentingan Tugas Backend Web Developer GDGoC 2026
  • Studi Kasus: "The Gatekeeper Logic"
  • Platform Tiket Event Online dengan Overselling Prevention
  • Bisa diintegrasikan dengan Spring boot (Framework Java)

Made with β˜• and πŸ’» in Indonesia Last Updated: 24 December 2025

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages