Skip to content

Instantly share code, notes, and snippets.

@ensargunesdogdu
Last active October 11, 2024 11:00
Show Gist options
  • Save ensargunesdogdu/f2dfb48b8a1f85670aaa977a00bf2fff to your computer and use it in GitHub Desktop.
Save ensargunesdogdu/f2dfb48b8a1f85670aaa977a00bf2fff to your computer and use it in GitHub Desktop.

Albert Java Coding Challenge

The goal of this challenge is to give you an opportunity to demonstrate your skills and how you would approach a real-life project.

General aspects

We expect you to create an GitHub repository that contains the your code and answers. Please always commit and push over your fork, and when you are done, create a pull request to this repository to deliver the results. We ask you to make one commit per challenge part and use the comment to identify it. Example: commit description “A” should have all the changes to answer the challenge part A.

Ensure you always include your code and also the written answers/explanations in the ANSWERS.md file within the same commit if they belong to the same challenge part.

The application technology

You should start with start.spring.io and add the necessary dependencies according to your needs. [Use H2 DB] for simplicity.

Challenge Introduction

Imagine you are building a basic appointment booking system where users can create their own availability slots, and other users can book those slots. To enhance the system, consider aspects such as data validation, performance, and scalability.

The aim of this challenge is to unify the data and expose it through a standard interface like a RESTful web service. Please ensure that your code follows clean code principles, design patterns, and best practices.

A - The Entities

Create the necessary entities with the following considerations:

1. Relationships: Define the relationships between entities clearly. For example, a user can have multiple roles, such as creating slots and booking them. Slots can be designed to allow multiple users to participate in them, establishing a “many-to-many” relationship between users and slots.

2. State Management: Implement state management for slots and appointments (e.g., “available” “booked,” and “completed”). Ensure that state transitions are well-defined and managed.

3. UML Class Diagram: Create a UML class model diagram that represents the entitiesand their relationships. Include this diagram in your commit and provide a brief explanation in the ANSWERS.md file.

B - Manage The Data

Implement the necessary classes using JPA entities and Spring repositories to persist data, with the following enhancements:

1. Custom Repository Methods: Implement custom repository methods to handle complex queries, such as finding available slots within a specific timeframe or retrieving appointments for a user.

2. Soft Deletes: Instead of deleting records from the database, implement soft deletes where records' status are marked as inactive or deleted.

C - Expose Data with a RESTful API

Create the following RESTful API endpoints:

1. Create Available Slots: This endpoint should allow users to create multiple booking slots.

2. Get Available Slots: This endpoint should return all available booking slots.

3. Book an Appointment: This endpoint should support booking multiple slots in a single request with detailed validation and error handling.

4. Update Available Slot: Create an endpoint that allows users to update an existing slot. Updates should only be allowed if the slot’s status permits it. For instance, if the slot is already "booked" or in a “completed” state, return an appropriate error message.

5. Cancel Appointment: Create an endpoint that allows users to cancel an existing appointment. Before performing this operation, add validation to check whether the appointment can be canceled (appointments within 24 hours cannot be canceled).

All endpoints must expose the results in JSON format, handle errors gracefully, and provide clear error/log messages for any validation failures.

D - Notification System

Create a notification system using Kafka to send reminders for appointments.

1.	Kafka Producer: Update the main application to publish an event to a Kafka topic  when an appointment is created. The event should include the appointment time and user details.

2.	Kafka Consumer: Create a Kafka consumer that listens to the appointment-reminders topic and schedules a notification to be sent 15 minutes before the appointment.

3.	Scheduling Logic: Implement scheduling in the consumer to trigger notifications 15 minutes before the appointment time.

4.	Kafka Topic and Message Format: Define the Kafka topic and ensure messages are in a simple format (e.g., JSON) with the necessary appointment details.

E - Improvements

Is there anything that you consider that can be improved in your solution? Please explain

Deliverables

Please share your github repository link with us as a response to challenge email.

FAQ

Should I deliver clean code and apply design patterns and good practices?

Definitely yes! We will evaluate those aspects.

Do I need to add tests?

Tests are always important! In the case of this challenge they are not mandatory, but always test what you consider important.

Do I need to use some specific libraries?

No, build the application with the tools you prefer, there are no limits.

When should I deliver it?

The sooner the better

Answers Format (Please use format below to explain your answers)

Please type your answers or explanations below.

A - The Entities

1. Relationships

2. State Management

3. UML Class Diagram

B - Manage The Data

1. Custom Repository Methods

2. Soft Deletes

C - Expose data with a RESTful API

1. Create Available Slots

2. Get Available Slots

3. Book an Appointment

4. Update Available Slot

5. Cancel Appointment

D - Notification System

1. Kafka Producer:

2. Kafka Consumer:

3. Scheduling Logic:

4. Kafka Topic and Message Format:

E - Improvements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment