Skip to content

EmilyBalestrin/Challenge-3-Java-Spring-Boot-AWS

Repository files navigation

πŸš€ Challenge 3: Event and Ticket Microservices

This project is a challenge that implements two independent yet interconnected microservices for event management and ticket creation, making it ideal for use cases such as concerts, shows, and other types of events.


πŸ›  Technologies Used

  • Java 17: Main language of the project.
  • Spring Boot: Framework for developing the microservices.
  • MongoDB: NoSQL database used for data storage in the Ticket microservice.
  • RabbitMQ: Message broker used for email delivery.
  • OpenFeign: HTTP client for communication between microservices and external APIs.
  • ViaCep API: External service for fetching address information using a postal code (CEP).
  • JUnit: Framework for unit testing.
  • Postman: Used to test endpoints during development.
  • Docker: Used to containerize the application.
  • AWS: Hosts the application in the cloud.

🏁 Overview

🎫 MS Event Manager (Port: 8080)

Responsible for managing events, with integration to the ViaCep external API.

Functionality:

  • When creating or updating an event, it is possible to provide a valid postal code (CEP).
  • The microservice connects to the ViaCep API to automatically fetch address details such as street, neighborhood, city, and state.

🎟 MS Ticket Manager (Port: 8081)

Responsible for managing tickets, with features for communicating with other services.

Functionality:

  • When creating a ticket, the service:
    • Queries the MS Event Manager by event ID to retrieve information such as event name, date, time, and address.
    • Registers the ticket with the provided and retrieved information.
    • Sends a message to RabbitMQ to trigger a confirmation email.

Diagram:

Below is the project diagram for a better understanding of the structure.

challenge3 drawio (3)


πŸ“Š Endpoints Structure

MS Event Manager (Port: 8080)

All endpoints of this microservice have the prefix /api/events.

Method Endpoint Description
POST /create-event Create a new event
PUT /update-event/{id} Update an existing event
GET /get-event/{id} Get an event by ID
GET /get-all-events Get all events
GET /get-all-events/sorted Get all events in alphabetical order
DELETE /delete-event/{id} Delete an event by ID

MS Ticket Manager (Port: 8081)

All endpoints of this microservice have the prefix /api/tickets.

Method Endpoint Description
POST /create-ticket Create a new ticket
PUT /update-ticket/{ticketId} Update an existing ticket
GET /get-ticket/{id} Fetch a ticket by ID
GET /get-ticket-by-cpf/{cpf} Fetch ticket(s) by CPF
GET /get-canceled-tickets Fetch canceled tickets
GET /check-tickets-by-event/{eventId} Check if there are tickets for a specific event
DELETE /cancel-ticket/{id} Cancel a ticket by ID
DELETE /cancel-ticket/{cpf}/{ticketId} Cancel a ticket by CPF and ticket ID

🌐 Accessing the Application in the Cloud

This application is hosted on AWS, making it accessible via the following base URLs:

  • MS Event Manager: 18.188.197.28:8081/api/events
  • MS Ticket Manager: 18.188.197.28:8081/api/tickets

Use tools like Postman or Insomnia to interact with the endpoints listed above.


πŸ“ Some examples of API Calls

- 🎫 Event Endpoints

1. Creating an Event

Endpoint: 18.188.197.28:8081/api/events/create-event

Request Body:

{
  "eventName": "Test Event API",
  "dateTime": "2025-01-07T13:30:00",
  "cep": "99700-034"
}

Response Body:

{
    "eventId": "677d772fb8cab87077299013",
    "eventName": "Test Event API",
    "dateTime": "2025-01-07T13:30:00",
    "cep": "99700-034",
    "street": "Rua Carazinho",
    "neighborhood": "Centro",
    "city": "Erechim",
    "state": "RS"
}

2. Get an Event by ID

Endpoint: 18.188.197.28:8081/api/events/get-event/677d772fb8cab87077299013

Request Body: No request body required.

Response Body:

{
   "eventId": "677d772fb8cab87077299013",
    "eventName": "Test Event API",
    "dateTime": "2025-01-07T13:30:00",
    "cep": "99700-034",
    "street": "Rua Carazinho",
    "neighborhood": "Centro",
    "city": "Erechim",
    "state": "RS"
}

3. Canceling an Event

Endpoint: 18.188.197.28:8080/api/events/delete-event/677d772fb8cab87077299013

Request Body: No request body required.

Response Body:

Event successfully deleted.

- 🎟 Ticket Endpoints

1. Creating an Ticket

Endpoint: 18.188.197.28:8081/api/tickets/create-ticket

Request Body:

{
  "customerName": "John Deere",
  "cpf": "12345678911",
  "customerMail": "emailexample@gmail.com",
  "eventId": "677d772fb8cab87077299013",  It's necessary to create an event to have an eventId
  "eventName": "",
  "brlAmount": 500.0,
  "usdAmount": 100.00
  }

Response Body:

{
    "ticketId": "677d77bc74b7392a62e04ec3",
    "customerName": "John Deere",
    "cpf": "12345678911",
    "customerMail": "emailexample@gmail.com",
    "event": {
        "eventId": "677d772fb8cab87077299013",
        "eventName": "Test Event API",
        "dateTime": "2025-01-07T13:30:00",
        "street": "Rua Carazinho",
        "neighborhood": "Centro",
        "city": "Erechim",
        "state": "RS"
    },
    "brlTotalAmount": "R$ 500.00",
    "usdTotalAmount": "$ 100.00",
    "status": "PENDING"
}

2. Get a Ticket by ID

Endpoint: 18.188.197.28:8081/api/tickets/get-ticket/677d77bc74b7392a62e04ec3

Request Body: No request body required.

Response Body:

{
    "ticketId": "677d77bc74b7392a62e04ec3",
    "customerName": "John Deere",
    "cpf": "12345678911",
    "customerMail": "emailexample@gmail.com",
    "event": {
        "eventId": "677d772fb8cab87077299013",
        "eventName": "Test Event API",
        "dateTime": "2025-01-07T13:30:00",
        "street": "Rua Carazinho",
        "neighborhood": "Centro",
        "city": "Erechim",
        "state": "RS"
    },
    "brlTotalAmount": "R$ 500.00",
    "usdTotalAmount": "$ 100.00",
    "status": "COMPLETED"
}

3. Canceling a Ticket by ID and CPF

Endpoint: 18.188.197.28:8081/api/tickets/cancel-ticket/12345678911/677d77bc74b7392a62e04ec3

Request Body: No request body required.

Response Body:

Ticket with ID 677d77bc74b7392a62e04ec3 for CPF 12345678911 was successfully canceled.

πŸ’» Running Locally (Optional)

If you wish to run the application locally for development or testing purposes, follow these steps:

πŸ”§ Requirements

  • Maven installed.
  • Docker installed.
  • Docker Compose installed.

Step 1: Clone the Repository

Clone the project repository to your machine:

git clone https://github.com/EmilyBalestrin/Challenge-3-Java-Spring-Boot-AWS.git
cd Challenge-3-Java-Spring-Boot

Step 2: Build the Microservices

In the ms-event-manager directory, run:

cd ms-event-manager
mvn clean package -DskipTests

In the ms-ticket-manager directory, run:

cd ../ms-ticket-manager
mvn clean package -DskipTests

Step 3: Start the Services with Docker Compose

After building the microservices, run the following command to start the application:

cd ..
docker-compose up --build

Step 4: Test Locally

Once the containers are running, use Postman or a similar tool to test the local endpoints:

  • MS Event Manager: http://localhost:8080/api/events
  • MS Ticket Manager: http://localhost:8081/api/tickets

✨ Things to Improve

Integration Tests

  • Implement integration tests to validate the communication between microservices and ensure data consistency.

Swagger

  • Add Swagger documentation to clearly expose the endpoints and their respective inputs/outputs.

Validations and Exceptions

  • Implement new field validations to ensure the integrity of the received data.

  • Add custom exceptions to handle specific errors in a more comprehensible way.

Features

  • Create the GET /get-all-tickets endpoint to list all available tickets in the ms-ticket-manager microservice.
  • Add endpoints to filter tickets by event name and date; for events, include a filter by CEP.

πŸ† Challenges/Experiences

  • Project Relevance: This project, proposed in Challenge 3, was extremely important to exercise the knowledge acquired during the Spring Boot + AWS training program, as it covered topics and concepts from the very beginning of the course.

  • Microservices Connection: I faced difficulties regarding the connection between microservices because my knowledge of OpenFeign was limited and had gaps. However, throughout the challenge, I was able to address and fill those gaps.

  • Docker Implementation: The biggest challenges for me were mainly the implementation of Docker and its files for containerizing the project and deploying it to an AWS instance.

  • Asynchronous Messaging with RabbitMQ: Implementing asynchronous messaging with RabbitMQ was also a challenge, as I had never worked with this tool before. It required understanding its configuration, integration, and ensuring proper message delivery throughout the system.

Despite the challenges faced, I enjoyed working on the project. It significantly enhanced my understanding of topics where I previously struggled, and seeing it running in the cloud was both rewarding and exciting.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published