Now that we have confirmed that the service is capturing and parsing the clothing order data correctly, we can add our business logic to the main function.
Let's first being by declaring some new uses
use std::fs;use std::fs::File;use std::io::prelude::*;use serde_json::json;
We will also be using a constant to define where our aggregated data records will be stored.
Once again, this could be configured as a command line argument using the clap crate.
We next need to create some supportive functions outside of the main function:
fncreate_local_storage() {match fs::create_dir_all(WORKSPACE_LOCAL_STORAGE) {Ok(_) => {},Err(err) => {panic!("Warning: Could not create the local directory path {} : {:?}", WORKSPACE_LOCAL_STORAGE, err); }, }}
With all the use declarations and supportive functions in place, we can now start modifying the main function.
We first call the function to create the local storage directory when the service starts. This code can be added after the parameters section within the main function.
To add our business logic, (inside the callback function after the println we were using to confirm the service is working correctly) we add the following lines of code:
The final state of your order_clothing.rs file should look like the following: