1
00:00:00,210 --> 00:00:00,750
Wonderful.

2
00:00:00,990 --> 00:00:07,950
And once we have the review structure in place, the first draft to work on is the creator of you one.

3
00:00:08,460 --> 00:00:13,500
And here the steps are following first, I want you to check for the product.

4
00:00:13,500 --> 00:00:18,030
Essentially, that is going to be a product idea in the rock that body.

5
00:00:18,630 --> 00:00:25,380
Now of will send other things as well, like what is the title and what is the comment and writing?

6
00:00:25,380 --> 00:00:29,610
But I mean, for now, we're just focused on the product in the controller.

7
00:00:30,120 --> 00:00:38,970
Then the second thing we want to do, we want to attach a user property on to a that body to wreck,

8
00:00:39,570 --> 00:00:41,680
right, not the body and where we get the value.

9
00:00:41,700 --> 00:00:50,520
Well, there is a middle order, correct, and we have access to that user and more specifically, user

10
00:00:50,520 --> 00:00:58,800
I.D. Then we want to create the review, but I suggest not testing it yet in the postman because there's

11
00:00:58,800 --> 00:01:01,380
two more things that I want to showcase.

12
00:01:01,590 --> 00:01:02,760
So let's get rolling.

13
00:01:03,420 --> 00:01:09,110
And I'm looking for a review controller, and we'll start over here by importing some stuff.

14
00:01:09,120 --> 00:01:18,760
So Konst and I'm looking for you, of course, and this will be equal to my models and I'm looking for

15
00:01:18,840 --> 00:01:21,480
you, and we'll right away also get the product.

16
00:01:21,500 --> 00:01:23,490
And this is not going to make sense right now.

17
00:01:23,490 --> 00:01:25,140
But you'll see in a second why.

18
00:01:25,560 --> 00:01:33,000
So in here, let's say product is equal to models of you and not for its lush product, then we want

19
00:01:33,000 --> 00:01:39,210
to get the status codes custom error as well as check permissions.

20
00:01:39,210 --> 00:01:47,520
And this is the case where we can speed this up a little bit, where I want to go to my user or off

21
00:01:48,000 --> 00:01:49,410
which one had all of them.

22
00:01:49,680 --> 00:01:51,330
So let me take this.

23
00:01:51,570 --> 00:01:54,000
So I'm in the user controller.

24
00:01:54,510 --> 00:02:01,860
Grab everything so status codes, custom error as well as the utils one, and we'll have to just trim

25
00:02:01,860 --> 00:02:06,810
it down a little bit where I'm going to copy and paste and in here.

26
00:02:07,900 --> 00:02:10,810
We're going to still look for status codes, yep, custom.

27
00:02:11,110 --> 00:02:15,220
Yeah, that's the case, but we only want check permissions.

28
00:02:15,610 --> 00:02:19,720
So that's the only thing we'll look in the uterus for.

29
00:02:20,200 --> 00:02:24,970
And then as far as the functionality, like I said, eventually there's going to be more things.

30
00:02:25,420 --> 00:02:33,100
But for the time being, I just want to grab the product and I wanted to structure it.

31
00:02:33,260 --> 00:02:34,960
And say in second why we want to do that.

32
00:02:34,960 --> 00:02:37,900
So first, I just check for the product.

33
00:02:39,160 --> 00:02:40,590
Product ready.

34
00:02:40,930 --> 00:02:42,670
And that is equal to what I is.

35
00:02:42,670 --> 00:02:44,320
Equal to a record body.

36
00:02:44,620 --> 00:02:44,980
Correct.

37
00:02:45,400 --> 00:02:46,480
More things coming in.

38
00:02:46,480 --> 00:02:52,300
But for now, we just want to focus on the product I.D. since the user is going to be sending in the

39
00:02:52,300 --> 00:02:58,390
titles, the descriptions, the ratings, as well as product.

40
00:02:58,720 --> 00:03:00,520
So we're interested in that product.

41
00:03:00,520 --> 00:03:08,020
And now once we get the product I.D., let's just do a quick and dirty first and then we'll worry about

42
00:03:08,020 --> 00:03:09,160
the rest of the functionality.

43
00:03:09,580 --> 00:03:16,900
So in here, I want to go with a rag about body and I want to right away attach that user property on

44
00:03:16,900 --> 00:03:17,050
it.

45
00:03:17,260 --> 00:03:23,950
So say there's going to be a user property that is equal to that user and then user ID?

46
00:03:24,430 --> 00:03:24,790
All right.

47
00:03:25,000 --> 00:03:26,230
Again, we have the middleware.

48
00:03:26,230 --> 00:03:27,310
That's why we can do that.

49
00:03:27,700 --> 00:03:33,940
And then let's right away create the interview and then I'll cover two more things we need to do.

50
00:03:34,150 --> 00:03:41,320
So we're going to go here with a review, then create, create and we'll just pass the record body.

51
00:03:41,770 --> 00:03:45,760
So at the moment, this one is somewhat useless.

52
00:03:45,940 --> 00:03:51,960
I'm not doing anything with that product either, because that product should be already there, correct?

53
00:03:52,000 --> 00:03:56,980
And since it is required, if the user is not going to send it in, there's going to be a big, fat

54
00:03:56,980 --> 00:03:57,250
error.

55
00:03:57,640 --> 00:04:00,460
And then we want to go with a resident status.

56
00:04:01,430 --> 00:04:07,100
Will gold status codes and or say created and then we'll say, Jason.

57
00:04:07,460 --> 00:04:10,610
And what's perhaps in the review now?

58
00:04:11,240 --> 00:04:14,600
What is issue with our current setup?

59
00:04:17,450 --> 00:04:23,660
If the user sends some kind of product ID that doesn't exist, we're not checking.

60
00:04:23,930 --> 00:04:24,320
Are we?

61
00:04:25,480 --> 00:04:29,220
I'm just saying, if it exists, yeah, I'm just going to create our view.

62
00:04:29,890 --> 00:04:35,800
But before we can do that, it would make sense if we check whether the product exists correct and therefore

63
00:04:35,800 --> 00:04:38,290
we grab the product out of the rock that body.

64
00:04:39,040 --> 00:04:43,260
So and here I look for product I.D., meaning I gave it an alias.

65
00:04:43,750 --> 00:04:49,430
So before we do anything, I want to check whether it is an actually valid product.

66
00:04:49,450 --> 00:04:50,680
So we want to go with is.

67
00:04:51,600 --> 00:04:58,030
Broward product is equal to await one product, one find one.

68
00:04:58,050 --> 00:05:00,300
And this is why we want to use the model.

69
00:05:00,540 --> 00:05:03,390
This is why we need it here where we go and find one.

70
00:05:03,630 --> 00:05:04,890
And we're looking for.

71
00:05:05,820 --> 00:05:08,790
Product where I'd be equal to what?

72
00:05:09,210 --> 00:05:11,130
To a product right now.

73
00:05:11,220 --> 00:05:14,820
If there is no product, what do we do when we throw back the error?

74
00:05:14,850 --> 00:05:15,210
Correct?

75
00:05:15,630 --> 00:05:16,470
You say if?

76
00:05:17,410 --> 00:05:18,250
It's false.

77
00:05:19,290 --> 00:05:22,380
Then let's send back for 04.

78
00:05:22,830 --> 00:05:25,110
We have no product with I.D. such and such.

79
00:05:25,740 --> 00:05:32,790
So let's go retro new custom error dot van not found error.

80
00:05:33,210 --> 00:05:36,060
And as far as the message template strings, no product.

81
00:05:36,660 --> 00:05:42,330
We have I.D. and then we're looking for product I.D. Beautiful.

82
00:05:42,870 --> 00:05:50,010
And the second thing that I want to show you is how we can do that in the controller, where we check

83
00:05:50,010 --> 00:05:56,880
whether the user already left a review before we pass anything before we create a review.

84
00:05:57,270 --> 00:06:04,470
I also want to check whether the user already submitted a review for this specific product.

85
00:06:05,040 --> 00:06:05,840
How do we do that?

86
00:06:05,850 --> 00:06:09,330
Well, come up with some kind of variable name already.

87
00:06:10,590 --> 00:06:16,620
Submitted, submitted and the matter will be equal to await.

88
00:06:16,770 --> 00:06:20,640
Now we're looking for more of you and I'll say find one.

89
00:06:20,910 --> 00:06:28,860
Now in the fine one up pass in two things I'll say get me the review where product is equal to a product,

90
00:06:28,860 --> 00:06:34,830
any and second, where user is equal to what rank user?

91
00:06:35,450 --> 00:06:35,830
Already?

92
00:06:36,180 --> 00:06:39,840
Now, if you want a question, you can structure it here as well.

93
00:06:40,230 --> 00:06:43,950
If that makes a little bit more sense to you, since we are using in two places.

94
00:06:44,300 --> 00:06:44,760
My case?

95
00:06:44,760 --> 00:06:46,100
I'm just going to leave it the way it is.

96
00:06:46,110 --> 00:06:48,400
And again, we do the check.

97
00:06:48,420 --> 00:06:53,940
We say, if already submitted, if there is such product, why do I want to?

98
00:06:53,940 --> 00:06:58,620
Do I want to throw a custom error where I'll say bad request?

99
00:06:58,920 --> 00:07:06,210
So we'll go throw new custom error and we're looking for bad request.

100
00:07:07,260 --> 00:07:09,510
Passed in the spring, so already.

101
00:07:10,530 --> 00:07:14,370
Submitted submitted review for this product.

102
00:07:14,700 --> 00:07:20,650
And now we can start finally submitting the reviews because we handled both cases.

103
00:07:21,180 --> 00:07:30,120
We first handled the non-existing product and we also check whether the user has already submitted the

104
00:07:30,120 --> 00:07:32,430
review for this product.

105
00:07:32,940 --> 00:07:38,820
So now let's come back to the post man, or we want to go to create review and not first.

106
00:07:38,830 --> 00:07:42,120
Let me just log in as you're old, Susan.

107
00:07:43,230 --> 00:07:47,970
And then once I logged in, I want to create, are you here?

108
00:07:48,600 --> 00:07:53,530
And actually, before we can submit their review, I want to get all the product.

109
00:07:53,540 --> 00:07:55,740
So let me grab this one here.

110
00:07:56,550 --> 00:07:59,430
I mean, just say that I'm looking for the first one.

111
00:08:00,570 --> 00:08:04,200
And as far as that, are you in the body?

112
00:08:04,920 --> 00:08:10,740
Say, raw address on and start over here, I'll say product.

113
00:08:11,570 --> 00:08:16,100
Not all will be equal to the product the next we want to go with the rating.

114
00:08:16,640 --> 00:08:25,460
And I want to keep it as real as possible or star rating will be one when we want to go with the title,

115
00:08:25,460 --> 00:08:25,970
I believe.

116
00:08:26,630 --> 00:08:33,530
So let me just double check what I've said up there in the review model motto or you?

117
00:08:34,980 --> 00:08:38,669
Title and comment, yep, that's the one title.

118
00:08:39,030 --> 00:08:47,430
I'll say bad product and then a comma and we'll go with comment and comment will be very, very bad

119
00:08:47,430 --> 00:08:47,880
product.

120
00:08:47,880 --> 00:08:51,240
Very, very bad product.

121
00:08:51,720 --> 00:08:52,680
Let's save it.

122
00:08:53,070 --> 00:08:54,180
Let's send.

123
00:08:54,780 --> 00:08:56,550
And now we have better review.

124
00:08:57,150 --> 00:09:00,450
So we have the user I.D., We have the product.

125
00:09:00,450 --> 00:09:06,000
And on the score, I.D. is the are the for the review.

126
00:09:06,300 --> 00:09:13,530
And if I'll try to send one more time now have already submitted a review for this product, which is

127
00:09:13,530 --> 00:09:15,510
coming from our controller.

128
00:09:15,660 --> 00:09:20,520
And with this in place, we're done with Create Review controller.

