This is my solution to the Ada School's Spring Boot Java Challenge.
A bus company wants to start using technology and allow their users to book online tickets. Please help them build a REST API Level 2 (preferrable) that lets them control their trip bookings, supporting the following operations:
- Create a new booking with the following information: name, email, origin, destination, departure date and time and duration.
- Update an existing booking
- Find a booking using its ID.
- Delete an existing booking.
- Using coding best practices.
- SOLID principles.
- Clear usage of Dependency injection.
- Correct usage of Spring Boot annotations.
- Correct connection with a persistance layer.
- Java / Kotlin
- Spring Boot
- MongoDB
- Debatable if you should just use one collection object versus splitting the object into more documents
- You would first signup and create an account. After that, you would be able to purchase a ticket.
- One to many relationship? A person can buy multiple tickets.
- Make ticket an embedded document inside person document?
- Embedded documents create data duplication, which increases storage requirements. However, embedded documents make querying for data easier.
- This article gives an overview on how to use
DBRefs
and@DocumentReference
to replace embedded documents. - I decided to take an approach similar to the article.
- Added basic CORS config versus having to annotate methods or controllers.
- Debatable if adding
final
to parameters is really necessary. It doesn't really hurt, and it helps make you more deliberate about what you are doing in the code.
- Could add Thymeleaf for a frontend.
- Testing
- CommandLineRunner to seed database
Duration
is problematic inside entities. Need to investigate more. Might need to use@Transient
and store the duration in the database as a string.
- Bootify
- YouTube - MongoDB with Spring Boot Crash Course - Full Tutorial
- Blog - embedded documents with spring data and mongo
- Mongo - embedded documents
- Mongo - spring boot
- Baeldung - spring data mongodb tutorial
- Github - spring boot mongodb tutorial
- Digital Ocean - spring boot mongodb
- Github - mongodb spring boot nested collection
- Stack Overflow - how to update embedded objects in spring mongodb
- Java tech online - spring boot mongodb using mongotemplate examples
- Medium - building and consuming rest apis in spring microservices
- Mongo - spring boot
- YouTube - MongoDB – Model One-to-One, One-to-Many Relationships Embedded Documents | Spring Boot | Java Techie
- Medium - mongodb vs mongodb srv whats the difference
- Blog - querysrv errors when connecting to mongodb atlas
- Baeldung - spring profiles
- YouTube - Spring Boot MongoDB CRUD 2024 | REST API Operations Tutorial
- YouTube - MongoDB CRUD operation using Springboot
- Stack Overflow - how to create an id within the embedded document using mongodb and spring data
- Baeldung - spring bot mongodb auto generated field
- Stack Overflow - how to generate uuid using spring annotations
- Spring - mongodb reference
- Github - Problem with replacement of
@DBRef
to@DocumentReference
- Bootify - document reference in spring boot mongodb
- Stack Overflow - how to model java time duration in mysql database
- Stack Overflow - thymeleaf template does not work upon adding cors configuration