From the course: Extending, Securing, and Dockerizing Spring Boot Microservices

Reviewing the Original Spring Boot microservice

From the course: Extending, Securing, and Dockerizing Spring Boot Microservices

Start my 1-month free trial

Reviewing the Original Spring Boot microservice

- [Instructor] Our launchpad is the completed capstone project built for my course, creating your first spring boot microservice. Which introduces spring boot, spring data repositories, spring data rest, and spring MVC rest controllers. You should flip over to that course if you are unfamiliar with any of these frameworks. The microservice provides backend support for an imaginary California tour company, called Explore California. And here's the website for it. Explore California is a tour operator that publishes several guided tours. Those with common themes are grouped into tour packages. So for example, there's a tour package based on backpacking, California calm, Hotsprings, et cetera. And then for each tour package, we have different tours such as the Big Sur Retreat, Channel Island excursion, et cetera. And for each tour, there are attributes such as the description, the duration of the tour, the cost, the difficulty rating and the locale. The exercise files for the course are available in my code repository. Each branch corresponds to a chapter video. You can view the repo in a browser or clone it to your desktop. And of course you can always download the entire archive as I have, from the exercise files link on the course page. Let's open the project with IntelliJ IDEA or you can use your IDE of choice, that's Maven aware. So I'm going to open the project in the desktop, exercise files, chapter one, zero one zero one, and there is the project exploreCali, Java project, and let's open it, and give it a moment to resolve dependencies. And I'm going to enable auto import with Maven on my IDE. Okay, so it seems like IntelliJ IDEA is happy. So in our project folder, let's go through and look at our domain model, in the domain folder under the com.example.ec package, we have the TourPackage entity. For a TourPackage, we have the ID, which is the code for the package and the name of the tour package. Then for a Tour entity, we have the generated ID, a title of the tour, description, blurb, the price, the duration, bullets about the tour, quick descriptions keywords, a reference back to the tour package that it's in, and two enums, one for the difficulty of the tour and one for the region of the tour. And lastly, we have a TourRating. A tour rating is the ability for a customer to rate a tour that they've been on. And that has an ID that it's an embedded PK, I'm going to drill down into that, It's a TourRatingPK, which has a reference back to the tour and the customer identifier. Going back to tour rating, and so the other attributes that TourRating, other than that PK primary key is the Score and a comment that the customer could leave. Let's look at our spring data repositories, TourPackageRepository is a credit repository and the ResourceRel is slash packages. And we are using Spring Data REST, so that API is exposed to HTTP. The same is true for TourRepository, is a Spring Data repository that exposes the methods of a Tour. And then TourRatingRepository, we do not export this to REST. This repository is only invoked by the TourRatingController. For RatingController has APIs in it, the API is, is tours slash tourID and then rating. And it injects the tourRatingRepository and the tourRepository. So for this RestController, we map API is to create a tour, to get ratings for a tour, get the average score for a tour, update a tour rating, with the put HTTP verb, update with patch HTTP verb, and then we can delete a tour rating. This demo application uses an in-memory H2 database, and it is initialized with a preexisting tours and tour package at startup in exploreCali application. So here's our main exploreCali Java class, that implements command line runner and within the run method, is where we create our tour packages at startup. And then in this importTours() we will actually import a Json file called exploreCalifornia.json in the resources folder. So the application will iterate through these Json objects and at runtime all of these tours and tour packages will be able to be invoked as HTTP APIs.

Contents