<aside> 💡 I made this class so much harder and longer than it needed to be trying to skip all the learning resources and begin the PA, looking up things as I go. This is what I would normally do for PA classes but it won’t work for this one unless you’ve worked with Spring Boot before because you’re learning all new material.
The Udemy Learning Path linked in Zybooks Section 1.2 will take you through each rubric requirement pretty much in order. For the video sections where it says “0 of 366 items” just click “view entire course” then ctrl-f and type in the section title to find the appropriate videos. I also tried to link them below. If there are multiple grouped I only linked the first. I tried to switch most of the links over but some may still be wgualumni Udemy links. Remove “alumni” from the url if you run into issues so that it’s wgu.udemy.[otherstuff].
</aside>
REQUIREMENT F Additional Info:
<aside> 💡 1. Add your button in the right spot in your mainscreen html file. You want to pass your productID through this button and treat it like a form. Then we're going to use a controller to process the function of the button so post map a url here.
Resources:
https://spring.io/guides/gs/handling-form-submission/
https://www.feathery.io/blog/html-hidden-inputs....
https://www.w3schools.com/tags/att_button_formmethod.asp
Create html docs for your buy confirmation message and for the error message.
In ProductService initialize a decrement method then define the method's function in ProductServiceImpl. Pass the product through the method so it can check if the product exists and if there are any in inventory. If so, return "true" as a result. If not, false.
Create a controller for this process. Add two methods with productID, theID, theModel as parameters - annotate one with GetMapping and the other PostMapping. For GetMapping you need to decrement the product. For PostMapping you want to save the product in the repository if the purchase was successful and set the result as your confirmation message. If the purchase was unsuccessful leave product as is in repo and set result as error. Then return your result outside of your if/else if. Use the pre-existing product decrement and save functions. There's a bit more to this but not sure how to explain without fully giving you the code so you may have to ChatGPT.
That's it. So what ends up happening when the button is pressed is the html maps to the controller. When the controller gets the mapping request it tries to decrement the product using ProductService(Impl). ProductService(Impl) checks if that's possible and tells the controller yes or no. Then the controller's post mapping kicks in and if it was a yes it saves the product's new inventory value and sends a confirmation - if not, it sends an error.
Hope that helps!
</aside>