1
00:00:02,210 --> 00:00:07,920
So let's work on the admin side then. We get a products.ejs file and in the end I want to render

2
00:00:07,920 --> 00:00:09,360
my products there.

3
00:00:09,420 --> 00:00:16,380
So what we can do is we can copy the product-list.ejs file content and in products.ejs in the

4
00:00:16,470 --> 00:00:18,520
admin area, we can copy that in,

5
00:00:18,840 --> 00:00:24,240
if I now reload this page, we see the same as we see on shop and products but obviously I want to show

6
00:00:24,240 --> 00:00:28,550
different buttons there let's say, so that we can edit or delete them there

7
00:00:28,650 --> 00:00:31,850
and of course we could even change the whole way we display the products

8
00:00:31,860 --> 00:00:36,650
but for now let's focus on the logic and less on how we display that.

9
00:00:36,660 --> 00:00:40,500
So here I have my add to cart button,

10
00:00:40,530 --> 00:00:48,160
now time to change this maybe to an edit button and let's add a second button where I say delete. With that

11
00:00:49,560 --> 00:00:55,200
if we reload, these two buttons are now there and obviously, they don't do anything if I click them, just

12
00:00:55,210 --> 00:00:57,360
as the add to cart button doesn't do anything

13
00:00:57,360 --> 00:00:58,650
by the way.

14
00:00:58,650 --> 00:01:04,380
So as a next step, I want to make sure I can load this to edit it and now to do that,

15
00:01:04,410 --> 00:01:11,390
I first of all need to make sure that clicking this button does send a request and actually I want to send

16
00:01:11,390 --> 00:01:14,880
a simple get request and get onto another page.

17
00:01:15,050 --> 00:01:21,810
We could change this to a link with a reference to another page like this,

18
00:01:21,950 --> 00:01:25,920
if we do that, doesn't look too bad,

19
00:01:26,110 --> 00:01:30,560
styling changed a bit because well some things would have to be adjusted

20
00:01:30,730 --> 00:01:33,060
and I will do that later.

21
00:01:33,070 --> 00:01:43,160
Now we got that link which should of course now lead us to /admin/edit-product, like this. If

22
00:01:43,160 --> 00:01:48,170
I do that we get to the Page Not Found page because we haven't registered a route yet

23
00:01:48,350 --> 00:01:54,650
and the reason for this is that we don't just need to go to /edit-product but obviously we want

24
00:01:54,650 --> 00:01:57,370
to go to a very different route here,

25
00:01:57,410 --> 00:02:02,640
we want to make sure that we go to a route where we know which product to edit.

26
00:02:02,810 --> 00:02:06,990
So actually we'll need to pass something dynamic as part of that

27
00:02:07,010 --> 00:02:12,470
url, it would be great if we could pass something like edit product for the ID 1 and then we can

28
00:02:12,470 --> 00:02:19,730
retrieve that ID in the route that we're loading so that we know which product we need to fetch from

29
00:02:19,730 --> 00:02:22,940
the database or from our file for now.

30
00:02:22,940 --> 00:02:27,410
Now this is some logic we'll add in the next module though because some people might have skipped this

31
00:02:27,410 --> 00:02:32,330
module, so let's ignore this for now and let's focus on deleting

32
00:02:32,540 --> 00:02:37,940
but to be honest we'll face the same problem there because we want to delete a specific product and

33
00:02:37,940 --> 00:02:40,700
not all products obviously.

34
00:02:40,700 --> 00:02:48,290
So therefore here, we can also add a link but technically a delete process should not send a get request

35
00:02:48,290 --> 00:02:49,680
to some route, instead

36
00:02:49,810 --> 00:02:58,340
here I will simply wrap this in a form which leads to admin delete product and sends a post requests

37
00:02:58,340 --> 00:03:03,940
there to indicate that we really want to change something and not just load something or display something

38
00:03:04,270 --> 00:03:11,040
and then I wrap my button in there and give it the type submit so that it does submit this.

39
00:03:11,110 --> 00:03:18,030
So now we get that connected and therefore on admin products, you see that changed due to the form I

40
00:03:18,030 --> 00:03:24,660
added, we'll work on the styling or I will work on the styling between modules, both styles or both routes

41
00:03:24,660 --> 00:03:29,840
will not work because we haven't implemented them but we'll do that later.

42
00:03:30,000 --> 00:03:35,930
The same problem can be found for our Add to Cart here by the way, there

43
00:03:35,970 --> 00:03:40,520
I also want to do something which needs extra information,

44
00:03:40,560 --> 00:03:45,690
I need to have the ID of the product I want to add and I want to add it to the route we're loading

45
00:03:45,720 --> 00:03:47,610
or to the path we're loading.

46
00:03:47,640 --> 00:03:53,220
So here I also want to have a form which goes to something like add to cart,

47
00:03:53,220 --> 00:04:00,660
we don't have that route yet and then adds a method, post and then here I will have a button inside of

48
00:04:00,660 --> 00:04:07,020
that form and obviously I don't just want to go to Add to Cart but I would want something like add to

49
00:04:07,020 --> 00:04:12,120
cart one so that I know which product with which ID to add to a cart.

50
00:04:12,390 --> 00:04:16,340
But again this is something I will do in the next module

51
00:04:16,350 --> 00:04:18,690
just as for the admin routes.

52
00:04:19,110 --> 00:04:21,670
So for now, we're pretty much done,

53
00:04:21,690 --> 00:04:25,770
we added more views, we restructured our controller a little bit,

54
00:04:25,830 --> 00:04:28,420
we practiced what we did thus far

55
00:04:28,650 --> 00:04:35,280
but now of course the exciting thing will be when we finally start working more with dynamic data in

56
00:04:35,280 --> 00:04:42,540
our route paths and when we therefore can start adding items to the cart and editing and deleting items.

57
00:04:42,770 --> 00:04:45,490
We'll do that over the next modules of course.
