1
00:00:01,710 --> 00:00:06,750
So we have a few things to take care of now, first of all, we want to be able to update this reservation.

2
00:00:06,750 --> 00:00:10,800
So if I change the first name or the last name or whatever, that it saves the changes.

3
00:00:11,340 --> 00:00:14,160
Secondly, we need a means of deleting a reservation.

4
00:00:14,590 --> 00:00:21,570
And thirdly, we need need a means of updating the processed status of our reservation to processed

5
00:00:22,350 --> 00:00:25,080
equals one instead of the default of zero.

6
00:00:25,320 --> 00:00:26,590
And none of that is difficult.

7
00:00:26,610 --> 00:00:27,360
So let's get started.

8
00:00:27,390 --> 00:00:29,190
We'll do our database routines first.

9
00:00:30,570 --> 00:00:36,540
So I'm in postgrads Dutko and I already have one function that doesn't update, so I'm going to copy

10
00:00:36,540 --> 00:00:38,100
that as a starting place.

11
00:00:38,550 --> 00:00:39,450
So let me copy that.

12
00:00:40,020 --> 00:00:46,080
Go to the very bottom of this file and paste it in here and change the name from update user to update

13
00:00:48,040 --> 00:00:48,680
reservation.

14
00:00:49,860 --> 00:00:51,370
And it won't take a model's user.

15
00:00:51,390 --> 00:00:54,990
It'll take a model's reservation and we'll fix the comment.

16
00:00:58,760 --> 00:01:05,330
And I would just need to change the query, so update reservations set first name equals to one last

17
00:01:05,330 --> 00:01:08,090
name equals to two email equals equals to three.

18
00:01:08,600 --> 00:01:12,920
And we'll put phone here equal to four and then update it up.

19
00:01:12,930 --> 00:01:14,780
And I think that's everything we need to worry about.

20
00:01:14,780 --> 00:01:18,680
Let's make sure first name, last name, email, phone, start date and end date.

21
00:01:18,680 --> 00:01:20,950
We're not going to change room and we're not going to change.

22
00:01:20,960 --> 00:01:22,120
Yeah, so that's everything.

23
00:01:22,130 --> 00:01:25,080
I'm not going to worry about processed right now because we'll handle that separately.

24
00:01:26,540 --> 00:01:31,310
So now we substitute our five placeholders with the five things we need.

25
00:01:31,520 --> 00:01:33,110
This just needs to change the phone.

26
00:01:35,410 --> 00:01:39,610
And everything else should be OK, so let's copy this.

27
00:01:45,810 --> 00:01:50,250
And put it in our repository, which is right here.

28
00:01:53,660 --> 00:02:02,480
And then copy the entire function and put it in our test repo, which is right here, and delete the

29
00:02:02,480 --> 00:02:04,630
things we don't need, so we'll just return.

30
00:02:04,640 --> 00:02:07,090
No, that will be sufficient for right now.

31
00:02:09,320 --> 00:02:10,790
Get the receiver correct.

32
00:02:12,710 --> 00:02:13,760
And paste it in there.

33
00:02:14,060 --> 00:02:16,730
OK, so that's the first thing we're going to have to do.

34
00:02:17,240 --> 00:02:18,650
What else are we going to have to do?

35
00:02:18,680 --> 00:02:21,680
Well, we want to be able to delete a reservation, and that should be pretty simple.

36
00:02:22,190 --> 00:02:32,720
Func M of postcrisis DB, repo receiver, delete reservation and we'll take an ID, which will be an

37
00:02:32,720 --> 00:02:37,760
ENT and return potentially an error and I'll copy my contact stuff.

38
00:02:39,450 --> 00:02:50,400
Pasted in here, write my query, delete from reservations where ID equals dollar, sign one, and this

39
00:02:50,400 --> 00:02:51,540
is just a query.

40
00:02:51,610 --> 00:02:52,080
Exactly.

41
00:02:52,440 --> 00:02:54,990
So we can do that as follows.

42
00:02:55,020 --> 00:03:00,660
IMDB query will be an exact context.

43
00:03:00,660 --> 00:03:03,380
There is the exact context and will pass it.

44
00:03:03,390 --> 00:03:08,280
The context will pass it, the query and we'll pass it our ID.

45
00:03:08,700 --> 00:03:10,800
And what does context return?

46
00:03:11,490 --> 00:03:15,420
It returns a result which we don't care about and an error that we do.

47
00:03:15,420 --> 00:03:16,440
So a result.

48
00:03:16,440 --> 00:03:19,110
I don't care about an error that I do.

49
00:03:22,890 --> 00:03:27,810
If air is not equal to nil, return the air.

50
00:03:31,040 --> 00:03:35,690
Otherwise, Richard, Neal, give it a comment.

51
00:03:38,980 --> 00:03:46,870
Deletes one reservation by I.D., copy the whole thing and put it in our test repo.

52
00:03:50,330 --> 00:03:52,400
Just have that return nil for now.

53
00:03:55,720 --> 00:04:03,970
And give it a new receiver and then copy the entire function's signature and put it in our repository.

54
00:04:06,660 --> 00:04:11,760
And there's one more databased routine we need to right here, and that's the one that changes the status

55
00:04:11,760 --> 00:04:19,860
and all right, one function that handles both cases, func M Postgrads DB Repo Update.

56
00:04:21,950 --> 00:04:33,470
Processed for reservation, and that will take an ID of Ent. and I'll also pass in the process status

57
00:04:33,830 --> 00:04:38,090
processed just in case we ever want to toggle this instead of just setting it to processed.

58
00:04:39,230 --> 00:04:42,140
And it will return an error, if any.

59
00:04:44,600 --> 00:04:48,670
And the rest of this, I could just copy right from here and change it as necessary.

60
00:04:50,270 --> 00:04:53,840
So we'll say update reservations.

61
00:04:56,810 --> 00:05:06,260
Set, processed, equal to dollar sign one where ID equals dollar sign, too, and we'll say here processed

62
00:05:07,070 --> 00:05:08,870
an ID and that should do it.

63
00:05:09,350 --> 00:05:15,170
So if we hand this an ID of five and a process to one, it will change the idea of five.

64
00:05:15,170 --> 00:05:20,570
The record with the idea of five and the reservations table to whatever we passed is processed, processed

65
00:05:20,570 --> 00:05:21,070
and that's it.

66
00:05:21,710 --> 00:05:22,820
Let's give this a comment.

67
00:05:24,140 --> 00:05:31,010
Update's processed for a reservation by ID, copy the whole thing.

68
00:05:33,820 --> 00:05:42,520
Put it into our test repo, just have it returned nil for now and change its signature or its receiver

69
00:05:44,080 --> 00:05:49,470
and then copy the whole function signature and put it in repository.

70
00:05:50,530 --> 00:05:52,180
And we should be good to go at this point.

71
00:05:52,630 --> 00:05:54,610
OK, so let's make sure everything compiles.

72
00:05:59,330 --> 00:06:07,760
It does perfect, so now in the next lecture, we'll update our handler to take advantage of the update

73
00:06:07,760 --> 00:06:10,190
reservation method.

74
00:06:10,190 --> 00:06:16,370
We just put in the database and then we'll write handlers for deleting a reservation and for updating

75
00:06:16,370 --> 00:06:20,990
the process status of a reservation and make the necessary changes in our template.

76
00:06:20,990 --> 00:06:23,180
And that should be good to go at that point.
