Giter Site home page Giter Site logo

make-parties-spring-backend's Introduction

Make Parties Spring Backend

This is a conversion of a past MakeSchool tutorial I completed to Spring Boot.

Screenshots








Built with

  • Java 17
  • Spring Boot 3.1
  • H2 Console
  • Lombok

Thoughts

  • Doing the mappings between entities is easy but there can be a few gotchas.
  • With Event and Rsvp, there exists a cyclic dependency and you get a stack overflow if you try to get Event - either use an annotation or a dto. See Stack Overflow for more.
  • Having to use DTOs with mappings (ManyToOne etc) is glossed over and obscured in a lot of implementations.
  • Using DTOs requires extra work -> easier to create a bug.
  • @JsonBackReference can't be used on a collection.
  • Could add a third table for the list of rsvps -> @JoinTable
  • Using Builder on an entity with a mapping warns - "@Builder will ignore the initializing expression entirely. If you want the initializing expression to serve as default, add @Builder.Default. If it is not supposed to be settable during building, make the field final." -> Because I set rsvps to an empty list, I needed to use @Builder.Default annotation on rsvps.
  • Added takesPlaceOn to Event Entity (stretch challenge in original MakeSchool tutorial).
  • Added timestamps as well but I did not use them in the frontend.
  • Added validation after I had the frontend working with the backend.
  • The tutorial did not feature any validation.
  • I kept the validation fairly minimal - a few required properties and date validation for takesPlaceOn.
  • In the entities, I used {entity}Id instead of just id. This can be annoying and debatable if this is a good practice or not.
  • Tests were written in this order: repository layer, service layer, controller layer.
  • I am not sure if it is truly necessary to test methods that just use JPARepository methods - seems redundant - this project didn't use any custom queries.
  • However, the repository tests are easy to write.
  • Had trouble with using Optional and thenReturn together in the EventService Tests - the commented out code seems like it should work but maybe I missed something - could be the return type of the function - ie Optional vs Event
  • You need to use assertAll() to handle void methods ie delete.
  • Not using response entities does create problems when testing error states in the controller layer because requests will fail without giving the appropriate status code. You have to write more checks to test routes versus stopping after isBadRequest() etc.

Continued Development

  • Use ResponseEntity for all routes?
  • Better exception handling / Custom exceptions
  • The validation for event put requests needs improvement - need to check takesPlaceOn is a valid date
  • fetchEventById in the event service implementation could probably be refactored and done in a better way

Useful Resources

  • YouTube - OneToMany | ManyToOne Relationship In Hibernate | SpringBoot | JPA | Java
  • Stack Overflow - code architecture of service interface and service implementation
  • Stack Overflow - timestamps
  • YouTube - Build REST API with Spring Boot and JPA [2021] - 25 Create timestamps by JPA
  • YouTube - Spring Boot For Beginners - One-To-Many in Spring Data
  • Baeldung - circular dependencies
  • Stack Overflow - fasterxml jackson stack overflow
  • Github - pokemon review springboot
  • Stack Overflow - one to many column not showing
  • Stack Overflow - stack overflow for hibernate one to one mapping
  • Stack Overflow - bidirectional relationships and infinite recursion
  • YouTube - 40 Enable CORS in Spring Boot
  • Stack Overflow - cors is not rejecting messages when i expect
  • Stack Overflow - return json for response entity
  • YouTube - Spring Boot tutorials | Spring boot full course - How to use ResponseEntity in REST API?
  • Stack Overflow - implement status 200 when delete is sent
  • Stack Overflow - jpa jointable annotation
  • Baeldung - java string valid date
  • How to Do in Java - date validation
  • Baeldung - lombok builder default value
  • Stack Overflow - suppress lombok warnings
  • YouTube - Spring Boot Unit Testing Tutorial (W/ Mockito)
  • Stack Overflow - mockito error with method that returns optional
  • Baeldung - java init list one line
  • YouTube - Write Unit Test Case For Controller Layer using Junit & Mockito | @WebMvcTest |MockMvc

make-parties-spring-backend's People

Contributors

jdegand avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.