So we have a few things to take care of now, first of all, we want to be able to update this reservation.
So if I change the first name or the last name or whatever, that it saves the changes.
Secondly, we need a means of deleting a reservation.
And thirdly, we need need a means of updating the processed status of our reservation to processed
equals one instead of the default of zero.
And none of that is difficult.
So let's get started.
We'll do our database routines first.
So I'm in postgrads Dutko and I already have one function that doesn't update, so I'm going to copy
that as a starting place.
So let me copy that.
Go to the very bottom of this file and paste it in here and change the name from update user to update
reservation.
And it won't take a model's user.
It'll take a model's reservation and we'll fix the comment.
And I would just need to change the query, so update reservations set first name equals to one last
name equals to two email equals equals to three.
And we'll put phone here equal to four and then update it up.
And I think that's everything we need to worry about.
Let's make sure first name, last name, email, phone, start date and end date.
We're not going to change room and we're not going to change.
Yeah, so that's everything.
I'm not going to worry about processed right now because we'll handle that separately.
So now we substitute our five placeholders with the five things we need.
This just needs to change the phone.
And everything else should be OK, so let's copy this.
And put it in our repository, which is right here.
And then copy the entire function and put it in our test repo, which is right here, and delete the
things we don't need, so we'll just return.
No, that will be sufficient for right now.
Get the receiver correct.
And paste it in there.
OK, so that's the first thing we're going to have to do.
What else are we going to have to do?
Well, we want to be able to delete a reservation, and that should be pretty simple.
Func M of postcrisis DB, repo receiver, delete reservation and we'll take an ID, which will be an
ENT and return potentially an error and I'll copy my contact stuff.
Pasted in here, write my query, delete from reservations where ID equals dollar, sign one, and this
is just a query.
Exactly.
So we can do that as follows.
IMDB query will be an exact context.
There is the exact context and will pass it.
The context will pass it, the query and we'll pass it our ID.
And what does context return?
It returns a result which we don't care about and an error that we do.
So a result.
I don't care about an error that I do.
If air is not equal to nil, return the air.
Otherwise, Richard, Neal, give it a comment.
Deletes one reservation by I.D., copy the whole thing and put it in our test repo.
Just have that return nil for now.
And give it a new receiver and then copy the entire function's signature and put it in our repository.
And there's one more databased routine we need to right here, and that's the one that changes the status
and all right, one function that handles both cases, func M Postgrads DB Repo Update.
Processed for reservation, and that will take an ID of Ent. and I'll also pass in the process status
processed just in case we ever want to toggle this instead of just setting it to processed.
And it will return an error, if any.
And the rest of this, I could just copy right from here and change it as necessary.
So we'll say update reservations.
Set, processed, equal to dollar sign one where ID equals dollar sign, too, and we'll say here processed
an ID and that should do it.
So if we hand this an ID of five and a process to one, it will change the idea of five.
The record with the idea of five and the reservations table to whatever we passed is processed, processed
and that's it.
Let's give this a comment.
Update's processed for a reservation by ID, copy the whole thing.
Put it into our test repo, just have it returned nil for now and change its signature or its receiver
and then copy the whole function signature and put it in repository.
And we should be good to go at this point.
OK, so let's make sure everything compiles.
It does perfect, so now in the next lecture, we'll update our handler to take advantage of the update
reservation method.
We just put in the database and then we'll write handlers for deleting a reservation and for updating
the process status of a reservation and make the necessary changes in our template.
And that should be good to go at that point.