1
00:00:02,190 --> 00:00:08,550
So the last thing we have to do is to actually write the database handlers to insert or delete a block,

2
00:00:08,550 --> 00:00:14,080
so the delete block is right here in my handler's dacko and the insert block would be right here.

3
00:00:14,100 --> 00:00:16,200
So let's go create those database functions.

4
00:00:16,230 --> 00:00:22,620
So I'm over in PostgreSQL and I'll create a new function and I'll call the first one with a receiver

5
00:00:22,620 --> 00:00:24,660
of type postgrads DB repo.

6
00:00:25,020 --> 00:00:27,540
I'll call it insert block.

7
00:00:29,210 --> 00:00:37,100
For room, and it will take two parameters and ID, which is the remedy of type INT and it will take

8
00:00:37,100 --> 00:00:43,580
the start date, which is of type time, time, and it will return nothing more than an error or nil

9
00:00:43,580 --> 00:00:44,420
if there is no error.

10
00:00:44,480 --> 00:00:51,710
So as I always do, I'll copy the context bit so I don't have to rewrite that pasted in here and write

11
00:00:51,710 --> 00:00:52,220
McQueary.

12
00:00:52,460 --> 00:00:54,440
And McQueary is quite straightforward.

13
00:00:54,630 --> 00:01:00,610
It is insert into room restrictions and what are we going to insert?

14
00:01:00,620 --> 00:01:08,060
We are going to insert the start date, the end date, which will always be one day long, the start

15
00:01:08,060 --> 00:01:15,950
date to end date because it's a block the remedy, the restriction ID, which will be to in this case

16
00:01:17,840 --> 00:01:18,560
and.

17
00:01:23,300 --> 00:01:27,440
The crater that created an updated it created a.

18
00:01:29,430 --> 00:01:35,820
Updated at values, and these will just be placeholders and there are six of them, I think, dollar

19
00:01:35,880 --> 00:01:42,090
and one dollar sign, two dollar sign, three dollar sign for dollar sign five and dollar signs six.

20
00:01:43,110 --> 00:01:44,050
So that's our query.

21
00:01:45,120 --> 00:01:46,350
Now let's execute our query.

22
00:01:46,680 --> 00:01:49,830
And I don't care about the first result, but I do care about the error.

23
00:01:50,760 --> 00:02:00,300
That's a sign the value of IMDB and exact context handled the context, handed the query and now handed

24
00:02:00,300 --> 00:02:01,890
our six parameters.

25
00:02:01,890 --> 00:02:08,280
And they are start date and then end date, which is just one day longer than start date.

26
00:02:08,280 --> 00:02:12,840
So I can just say start date and date.

27
00:02:13,080 --> 00:02:14,610
No years, no months.

28
00:02:14,620 --> 00:02:15,210
One day.

29
00:02:16,380 --> 00:02:19,410
The next thing is the remedy, which is just ID.

30
00:02:21,720 --> 00:02:28,740
Then the restriction is which will be two, because that's a block and then just timed out now and timed

31
00:02:28,740 --> 00:02:31,860
out now, check for an error.

32
00:02:32,040 --> 00:02:44,040
If error is not equal to nil, a Sloggett log print line error and return the error, otherwise return

33
00:02:44,040 --> 00:02:44,340
null.

34
00:02:46,950 --> 00:02:47,970
So that's our first one.

35
00:02:48,540 --> 00:02:49,460
Let's give it a comment.

36
00:02:53,770 --> 00:03:00,760
Inserts a room restriction and lets save some typing will copy the whole thing, because the delete

37
00:03:00,760 --> 00:03:02,000
is almost the same.

38
00:03:02,170 --> 00:03:04,240
All the changes is the query in the parameters.

39
00:03:04,720 --> 00:03:08,050
The parameters will just be an ID, which is the restriction ID.

40
00:03:08,590 --> 00:03:20,410
I'll name the function, delete block by ID and change my comment and say deletes a room restriction.

41
00:03:20,500 --> 00:03:22,270
And let's change our query to.

42
00:03:26,850 --> 00:03:36,540
Delete from room restrictions where ID equals dollar, sign one and all we need to pass in here is one

43
00:03:36,540 --> 00:03:41,780
parameter, which is our ID, and that should do it.

44
00:03:41,820 --> 00:03:49,560
So let's copy both of these and put them in our test repo so we'll be actually able to write tests,

45
00:03:50,100 --> 00:03:58,440
make them absolutely simple, just have returned nil for both of them and change the receiver to test

46
00:03:58,440 --> 00:03:59,130
DB repo.

47
00:04:01,200 --> 00:04:11,040
And the last step for this part is to copy the function entirely, put it in our repository and do the

48
00:04:11,040 --> 00:04:12,210
same thing for the other one.

49
00:04:18,370 --> 00:04:19,780
Let's make sure it compiles.

50
00:04:25,300 --> 00:04:27,680
It does good sound.

51
00:04:27,730 --> 00:04:33,940
Let's go update our handlers, so find our handlers and here we instead of the comment.

52
00:04:37,600 --> 00:04:47,530
Let's actually do the deletion, so error is a the value of IMDB repo or not repo and what am I doing

53
00:04:47,530 --> 00:04:47,740
here?

54
00:04:47,750 --> 00:04:54,310
Delete block by ID and the ID I am going to pass in there is value.

55
00:04:55,780 --> 00:05:01,390
So that should work and check for an error if error is not equal to nil.

56
00:05:01,420 --> 00:05:03,220
And what I'll do here is just log the error.

57
00:05:06,500 --> 00:05:06,990
OK.

58
00:05:07,010 --> 00:05:12,000
And down here, instead of inserting or instead of logging, let's do the actual insertion.

59
00:05:13,130 --> 00:05:21,980
So that would be error is a sign the value of IMDB dot insert block forum and we need the room ID,

60
00:05:23,120 --> 00:05:27,150
which is room ID, and we also need to have the start date.

61
00:05:27,170 --> 00:05:34,550
Well, I don't have that yet, but I can get it easily enough just by using the name of the that, using

62
00:05:34,550 --> 00:05:36,260
the name and passing that into a time.

63
00:05:36,260 --> 00:05:45,590
So time and I'll ignore the error is a sign the value of time pass and the layout would be 2006 zero

64
00:05:45,590 --> 00:05:50,590
one two for a four digit year, a two digit month and a one or two digit day.

65
00:05:50,870 --> 00:05:59,930
And what I'm passing is exploded three, OK, and now I can put the time in there and check for an error.

66
00:05:59,930 --> 00:06:03,080
So I'll copy this pasted in here.

67
00:06:04,840 --> 00:06:05,540
It's not going to work.

68
00:06:06,030 --> 00:06:06,580
Type it out.

69
00:06:06,650 --> 00:06:16,050
And if error is not equal to nil, we'll just log the error log print line error.

70
00:06:17,190 --> 00:06:21,320
OK, so let's try starting our application and see what we got wrong.

71
00:06:23,830 --> 00:06:24,850
So far, so good.

72
00:06:25,120 --> 00:06:26,310
Let's go to the calendar.

73
00:06:28,550 --> 00:06:35,990
OK, I'll make sure this is absolutely current, let's try deleting the one in the 12th, OK, that

74
00:06:35,990 --> 00:06:36,720
looks like it worked.

75
00:06:37,430 --> 00:06:38,170
No errors.

76
00:06:38,540 --> 00:06:40,760
Let's try adding the 12th and 13th.

77
00:06:42,710 --> 00:06:46,310
Good analysts said the 12th, 13th and 14th here.

78
00:06:47,820 --> 00:06:53,880
And let's delete the 13th, so far so good, let's try it on a month, that is not the current month,

79
00:06:53,880 --> 00:06:57,810
so I'll put the 19th, 20th and 21st and the first.

80
00:06:59,450 --> 00:07:00,080
Perfect.

81
00:07:02,090 --> 00:07:07,400
All right, so a reservation calendar appears to be functional at this point, and I don't think there's

82
00:07:07,400 --> 00:07:14,480
a whole lot left to do except I think if I look at an actual reservation and try to market as processed,

83
00:07:14,900 --> 00:07:17,140
it's probably not going to redirect properly.

84
00:07:17,150 --> 00:07:19,630
Let's make sure I think this is one thing we overlooked.

85
00:07:21,790 --> 00:07:26,050
And it says Page not found, it tries to take us through reservations, Carol, so we need to make one

86
00:07:26,050 --> 00:07:33,430
more change and that is just doing the redirect when you make a reservation as processed after getting

87
00:07:33,430 --> 00:07:34,530
there from the calendar.

88
00:07:34,540 --> 00:07:37,870
So that's the last step and will take care of that in the next lecture.
