So, there are two things I'd like to add here to improve this event creation process,
if you want to call it like this.
And the first thing is that I want to validate the submitted data here when I create an event,
for example, before I call createEvent where the data gets stored in the database.
It should be validated first.
In a second step thereafter, I want to make sure that all these event routes are only
accessible for authenticated users.
So users who have such a token, if you remember that, this JSON Web Token, we will need it
soon.
But first I'll start with validation.
For that, I'll highlight this code and I'll ask Copilot to add validation to ensure title,
description, address and date are all not empty.
Also not just a bunch of blanks and valid values.
Let's see what we get by sending this to the AI.
That looks pretty good.
We check if title, description and so on are empty or just a bunch of blank strings, just
a bunch of blanks.
For the date, we also try to convert this to a date object or parse it as a date and
check whether that worked and send back an error response if we got invalid input data.
That's looking good.
We also trim the data before sending it to the database to remove access whitespace,
which also makes sense, I'd say.
So let's accept this.
And with that change made, let's try sending a POST request to slash events without any
event data again.
And this time we get back invalid input data as we should.
The fix now is to send a body with JSON data attached to it and there we now should have
a title like a test event, a description like testing, and if I sent this, I should
still get an error because that's not all the data we need because we also need an address.
And let's try sending a bunch of blanks here.
That should not work.
Send a date and here I'll send something like 2025 somewhere in July, let's say, and
then something like that.
Let's send this invalid input data because the address is invalid.
So let's put in a valid address, test street 5, test city 5.
And that looks better.
And that data was now stored.
Now you might still be able to catch some niche cases where data is stored that maybe
shouldn't be stored, that's not really appropriate as a title, for example.
You could enforce a maximum length for the title, you could definitely tweak the code,
but this demo, of course, is not so much about the app.
Instead it is about building the app with help of AI and therefore I'm happy with this
solution here.
And hence the next step for me is to make sure that we also perform validation here
when we edit an event and that then we also enforce that only authenticated users can
visit these event routes or at least the routes where we create or change events.