The stored procedure will just get
the content that has passed from
the web app to
Azure SQL. Again,
just like JSON.
I'm literally passing only the
JSON I receive as a payload.
And, so I will open Azure SQL.
I will open the payload with the open
JSON I shown before and put the respective
property, title, and completed into the
column. I could also have chosen to
completely save JSON as JSON if I
really wanted to keep the maximum flexibility,
but I can also save JSON as we
saw before in Azure SQL. In this case.
I prefer to have asked a schema
and so I converted the JSON into a
table. But as you can see,
my code is super simple,
here. For example,
my to do, my query controller,
which is where all the communication with
the base happened.
As only one statement called query that
given that the input and the output is
always JSON is super easy to manage,
My Todo controller,
The post verb is super simple.
I just do query,
which means called the story procedure that
is called post
to do, pass the payload,
which is exactly what I received from
the user,
and that's it.
Then EnrichResult only takes care
of adding a URL object to the JSON.
Just to show you "how can I
have SQL and .NET can collaborate together
to create a complex JSON?"
If I wanted to do,
I could have done this also in Azure SQL.
But that didn't seem to be very
clever to me,
because, of course,
JSON manipulation will be faster in
.NET, since it is a compiled language.
So I do on Azure SQL all the data
manipulation,
the JSON manipulation that is related to
the data I need to return.
But all the other .json manipulation I
prefer to do it in .NET,
since, of course,
it's a
faster way to make sure that everything it's
super performed.
Now, having said that,
I have my
API ready -
so I have implemented the Delete,
the Post,
the Patch, and
uh, and, uh
the Get method,
so I can.
Now - let's say I want to deploy everything,
and I want to start to publish my solution.
Before doing that,
of course,
I need to be able to also create my
database.
So here I have created a script that
creates all my database,
and this again is something you can
actually find in the GitHub
repo. And I'm using here a tool -
I could have used something else, in
this case,
I wanted to use a tool called DbUp
that will apply the script for me.
And this will create a .NET application
that will read my script and apply
to my database as long as the descriptor
has not been applied yet,
It will help me to incrementally deploy
my database.
There are other options to do the database
deployment I could have used,
for example,
something called a BACPAC that will
actually deploy database using
the same principle,
but another tool.
But in this case,
I really wanted to do everything in
.NET
And then I also want to run some tests,
of course.
So, here I even have some tests.
Because, again,
you have a test definition here that
you can go and read,
I implemented those to the test
here using a new root,
for example,
so that let me show, this test is very
simple.
One of the requirements is that
all the results are returned to
as an array when,
for example,
I want to return everything.
So I just want to make sure that if
I get everything,
I will get an array.
Perfect! So this is just a very simple -
A very simple,
test -
and I can run this from the VS Code,
but I also want to make sure that as
part of my deployment,
I deploy my database,
due to migration if needed, and
then run the test.
If the tests are successful,
I then want to move to deploy
website and publish it
database
and the website and publish it.
That's exactly what I do here with the
GitHub. So in GitHub
I'm using what are known as GitHub
action in order to deploy everything.
So this is,
my actual code to do API
first action.
The first job of my action is Deploy Database,
which means I just run the Deploy
Project,
which I just discussed,
it is how I decided right now to deploy my
database,
using a .NET application that uses
DbUp to deploy my script.
After that,
I want to run some tests in order to
make sure that my database is exactly the
state I expect it to be.
And then if everything works well,
I want to start to publish my
API and I want to publish in a slot
called "dev" into my application called
Dm-tbd-02.
That's it!
I can now deploy
this in GitHub.