If you're reading this post on NixMash.com might have noticed the Home Page Banner on your way here. Here's a screenshot for those who haven't. The photos are Creative Commons Licensed with the attribution displayed at the bottom of the page.
Each day a different random banner is displayed from the pool of active banners. Banners can be archived, or deactivated and removed from the pool. In this NixMash post I describe how banner images were displayed in Spring. Since rebuilding NixMash from the ground up in Bootique I moved most of the display selection logic to a MySQL Stored Procedure found in this Gist.
I had been changing the active status directly in MySQL Console since remoting in Linux is so seamless that it's like performing tasks on your own PC. But as a weekend project I decided to put a face on changing Banner Image Status and built a Management Component. We'll walk through the highlights of that Image Management piece here.
Here's the Banner Management feature. The Current Banner is displayed on the initial, active Banners page. The top right-hand button displays the archived Banners no longer in the random display pool.
We'll jump straight to the code highlights. The overall logic is this:
- The Web Module REST Controller passes the Banner Image ID and an Application Security Key to a Post Microservice endpoint
- The Post Microservice Resource validates the Security Key and if valid performs the action.
The Thumbnail HTML
Here's the Thumbnail HTML with Mustache doing its thing of inserting the siteImageId and other properties where needed.
The Local REST Controller
Here is the Web Module Controller Method, passing the request along to the REST processing stage for transmission to the Post Microservice Endpoint.
Web Module Service Layer
The Web Module Service Layer intermediary method passes the ID to the REST Request to the Post Microservice and returns a Boolean success/fail indicator.
Preparing the REST Request
Still in the Web Module we need to package the @POST Request to our Post Microservice. Interesting here that we're performing a @POST Request but aren't posting an Entity of any kind. Instead the action is in the Request @PathParams.
Post Microservice Processing
Here in the Post Microservice the process completes if the Application Security Api Key is valid. A FORBIDDEN Response Status is returned if the api key is not valid, which invokes a Processing Exception in the Web Module REST Packaging Method and sends back a success/fail from the Service Layer method to the Controller.