Storage Machine is a small but realistic and rather complete back-end of a Web-application. It does not include the front-end part so you will use Postman or similar to interact with it.
The goal is to see an example of a complete system made using F# and get acquainted with the Onion architecture. You will do this by example functionalities and (architectural and FP) patterns already implemented in the back-end and extend it with new ones, by applying the same patterns.
- As always, F# language reference.
- Storage Machine uses Giraffe -- a library for creating Web-applications using F# as a thin layer on top of ASP.NET Core in FP style, unlike heavily OO-based ASP.NET Core model.
- For JSON serialization the Thoth.Json library is used because it provides FP-oriented combinator style of JSON (de)serialization.
Fill in missing parts to complete the functionality of retrieving an overview of products in stock.
Requirements and hints:
- The
Stockcomponent already contains two other complete and working functionalities. Study the corresponding use-case functionsbinOverviewandstockOverviewin the Application layer. - Study how other layers support these two working use-cases.
- Discover how to trigger these use-cases from outside and use Postman to see the results.
- Fill in all "holes" marked with "Exercise 0" required to complete implementation of
productsInStockin the Application layer. - Compare the response in Postman with simulated (hard-coded) data in the Data Access layer.
Extend the
Stockcomponent with functionality to store a new bin containing zero or one products.
Requirements and hints:
- Adding a bin should be possible using a
POSTrequest. - After adding a bin, it should be visible in the bin and/or stock overview already implemented in by the same
Stockcomponent. - Extend the data access interface in the Application layer.
- Define the use-case function in the Application layer.
- Is there anything missing in the Model layer or is it complete for this functionality?
- Extend the data access implementation object in the Data Access layer part of the
Stockcomponent. - Make a
Decoderfor bins. - Module
PostExamplein the Service layer contains an example of decoding (simple) JSON values from the body of aPOSTrequest and returing various responses. - Existing functionality in the
Stockcomponent contains examples of serializing JSON responses. - Make an
HttpHandlerfor the handling thePOSTrequest and combine it with existing handlers of theStockcomponent.
Implement "product repacking" functionality in the
Repackingcomponent.
Requirements and hints:
- Bins can be nested in other bins, this is already modeled in the Model layer of the
Repackingcomponent. - Products stored in bins ("bin trees") need to get protective packaging. Each individual product needs to be wrapped in a package, but the overall shape of the bin tree must remain the same. Storage Maching can magically mechanically do this, if you implement this repacking in F#.
- The
Repackingcomponent contains working functionality for viewing bin trees and counting products in a bin tree. Experiment with these. - After repacking, the number of products in a bin tree should remain the same. Use this as a sanity check for your repacking implementation.
- Adjust the model to express the packaging requirement.
- Implement repacking as a bin tree transformation function.
- Add the repacking step to an existing use-case function in the Application layer of the
Repackingcomponent.
Improve the model of product repacking.
- Current model in module
BinTreeallows a bin tree to be a single product. Strictly speaking, this does not make sense. Define the type for bin trees such that this is not possible anymore. - Adjust the model further to make applying packaging to products more than once impossible.