This is spring boot conversion of my express solution to a past interview test from LCOGT.
I have created an angular frontend that works with this backend.
- Maven
- Java 17
- Spring Boot 3.1
- JPA
- H2 Console
- The interview challenge repo was long outdated before I started. I used the repo to practice my skills as there are few Java take home tests on Github.
- Package names are not allowed to use dashes -> 'The original package name 'com.example.LCOGT-spring-backend' is invalid and this project uses 'com.example.LCOGTspringbackend' instead.' It is probably best to not use capitals either.
- H2 console does not automatically create a table (based on your schema) for you anymore - add
spring.jpa.hibernate.ddl-auto=create-drop
in application.properties - JPA query methods save you a lot of time - many use cases are covered
- However, JPA query methods don't throw errors - they return nothing and have a 200 status code.
- @Digits annotation seems better than @Pattern with a regex
- Easy to swap databases in Spring Boot. Not much has to be changed - add a driver dependency and update the
application.properties
file. - Constructor injection is better than field injection(@Autowired) for unit testing.
- Added DBDataInitializer to add "Mars" to the database on start-up. I used a SQL migration to add "Mars" to the database in my Express application.
- Lombok / Tests added on 'lombok' branch
- Database Integration / Removal of H2 Console
- Query method exception
- Stack Overflow - double's precision
- H2 Docs - connecting using jdbc
- Stack Overflow - h2 console not being found
- Stack Overflow - h2 console not opening
- Baeldung - spring boot h2 database
- Stack Overflow - spring h2 console not showing my table
- YouTube - How To Access The H2 Database Console In Spring Boot Projects
- Stack Overflow - h2 database doesn't create table from schema
- Spring Docs - jpa query methods
- Stack Overflow - validate unique username in spring
- Stack Overflow - unique constraint
- Stack Overflow - swing jtextfield max 3 digits before decimal and max 2 digits after decimal
- Stack Overflow - invalid escape sequence valid one are b-t-n-f-r in java
- Stack Overflow - validation with double value in spring
- Blind Text Generator - used this to test description max length
- Stack Overflow - validation with double value in spring
- JTuts - validating double values spring
- Stack Overflow - validating size for big decimal for given length not precision
- Cheat Sheet Series - Bean Validation Cheat Sheet
- Stack Overflow - throw exceptions on search methods in spring data jpa
- Java Guides - optional orElseThrow method
- Spring Docs - boot features sql
- Github - mariadb
- Reflectoring - unit testing spring boot
- Blog - spring boot unit testing
- Baeldung - big decimal validation