Skip to content

davidgfolch/spring-mongo-reactive

Repository files navigation

Getting Started

Description

Fully reactive Rental film REST API. Also see Kotlin version (in Kotlin branch).

Prerequisites

  • Enable annotation processors (in your IDE for lombok)

Architecture

  • Reactive Layers architecture (spring-framework reactor).
  • Java non-blocking functional programming: reactor+streams.
  • REST API's with Spring-WebFlux.
  • Persistence with reactive MongoDb.

Notes:

Business logic

I've changed the requirement "renting for x days".

In my implementation, when renting, you are always paying for 1 day.

When you return films you pay for surcharges if applies.

Details

Rent & Return films:

  • In both cases:

    • Non-existent userId throws UserNotFoundException.
    • duplicated filmId's are ignored, just processing one.
  • Rent films

    • Non-existent filmId's or not available stock, are ignored and not returned in result list.
    • With all available films found:
      • decreases stock
      • calculates rent for 1 day.
      • get saved in Customer.films (including date in each film).
  • Return films

    • Non-existent films in Customer.films are ignored and not returned in result list.
    • From all matching films in Customer.films, gets the older one (a filmId could be repeated with different rent date)
      • calculate surcharges (after x days).
      • remove from customer & save.
      • increase film stock.

Try it

  • Run App as a spring-boot app:
    • command line: gradlew :bootRun
    • intellij: right button on App.java & Run...

Every time app starts, customer and films are created automatically with harcoded ids for ease of use.

Also, generated json for each user+films is printed in log console, so we can copy/paste in RestApi POST bodies.

  • Use postman_collection.json (importing the json file in Postman client):
    • rentFilms: to rent
    • customerGet: to see customer rented films & bonusPoints
    • returnFilms: to return (after x days as path param)