I create this project to practice a little the code and include some concepts that I study. So was a sample idea, create a sample Investiment API that to return the all investiment the portfolio the customers.
I used the Visual Studio with language C# with .NET 6, but I will create a other article with coding in VSCode, now at the moment the environment this is.
So some rules the our API business investiment consunting, should have endpoints bellow:
- List all investiments
- Get investiments Fixed Income
- Get invetiments Variable Rent
- Get invetiments Funds
- Investing Fixed Income is a POST
- Investing Funds Property is a POST
- GET Rescue invetiments
Another rules the user cannot rescue the investiment in less than a month for all and The user cannot investing bonds that. The user cannot investing that does not fit your profile, and for the calculation rules:
If the date due date the investiment is than more that six month, so descount twent percent (20%) the yours yield
If the date due date the investiment is than more that twelve month, so descount ten percent (10%) the yours yield
If the date due date the investiment is equal due date all, so descount five percent (5%) the yours yield.
All ready, let´s the code.
Creating the project
First of all select the directory in your machine and create a solution blank with the name api-fanfareInvest or the name want do you want, image bellow.
After you have created, inside the solution blank, click right button -> new project and select ASP.NET Core API. In this case, we don't create a minimal API, ´follow the image.
This a structure basic the our Simple API. Now you can create the pasts: ConfigDependency, Controllers, Data, Model, Response and Service. I will explain later.
Creating the Models
For our API we need to create some Model class We need this class: (DirectTreasury, FixedIncome, Fund, VariableIncome and InvestimentPortfolio). The last class we will get all investments in the portfolio
The objective here is a create model class for get some investimet, for example I want to get all investiment direct treasury, or get fixed income, get variable income etc. I will mock data this investiment using Json Mock. But at moment, just let´s to create the classes model.
Let´s to create a class DirectTreasury in paste Model.
Let's repeat the process by creating the other classes
FixedIncome
Fund
InvestmentPortfolio
VariableIncome
Creating the Json Mocks
We are using these tools JSON Mocky this link https://designer.mocky.io/design. JSON Mocky is a nice tool because you can create JSON mocks to be consumed in APIs for testing. Bascally the tools generate a response Mock with a URL.
I created the JSON, so I used this website to validate my JSON https://jsoneditoronline.org. The first response we are to create is a Direct Treasury, as shown in the image below.
Creating JSON the response Direct Treasury
Copy the json and paste it in the field HTTP Response Body the website JSON Mocky, and after click in button Generate in my HTTP Response.
I have already prepared the response of the objects, just copy and save in a notepad. The procedure I did was the same, I created a JSON for each class, generated and formatted it in the online JSON Editor and pasted it in the body response of the JSON Mocky site.
Direct Tresuary Response: https://run.mocky.io/v3/52ad684e-30a4-4a45-9c88-3b18169c6137
Fixed Income Response: https://run.mocky.io/v3/ba42dc71-9176-46d0-8ede-a21faeb5b3ba
Fund Response: https://run.mocky.io/v3/7ac36199-db5c-4d21-bc8a-74fe91fa43b1
Variable Response: https://run.mocky.io/v3/4fcc8f18-8ab7-4a36-abc1-f466566e9785
In the next part of this article, I will continue to create the class Repository, Services, Response, and some configuration of the project.
Top comments (5)
Parabéns Jéssica,
Seu post e seu trabalho são uma inspiração.
continue assim.
abraço!
muito obrigada Rubens
It was a good training...tnx
I am writing the second part of this article.
I hope help you
Thank you very much🙏