1
00:00:00,840 --> 00:00:07,800
We have the model, so now it's just set up functionality for creating the job and then one by one we'll

2
00:00:07,800 --> 00:00:10,860
deal with the rest of the controllers as well.

3
00:00:11,460 --> 00:00:17,520
And in order to set everything up first, of course, from the postman, we need to send the data.

4
00:00:18,030 --> 00:00:19,620
And what data are we looking for?

5
00:00:19,620 --> 00:00:21,540
Again, let's jog our memory.

6
00:00:21,990 --> 00:00:27,910
We have the job model and I'm looking for a company name as well as the position.

7
00:00:28,330 --> 00:00:34,530
Now, let's not worry about the created by yet that one we will get from our middleware.

8
00:00:34,950 --> 00:00:39,020
And here let's just set up some kind of values in the body.

9
00:00:39,390 --> 00:00:42,900
So let's go with the raw and we're going with Jason, of course.

10
00:00:43,470 --> 00:00:45,780
And then in here, let's say company.

11
00:00:46,680 --> 00:00:52,400
Company, and then I'm just going to go to Google because we're not online as far as the position,

12
00:00:52,650 --> 00:00:59,470
well, but just go with intern so position and then we pass in the Internet.

13
00:01:00,330 --> 00:01:05,910
Now, let's go back to our controller when we have the jobs one created job.

14
00:01:06,270 --> 00:01:14,340
And instead of sending back the user, I want to send back the body again just so we can test whether

15
00:01:14,340 --> 00:01:15,200
everything works.

16
00:01:15,510 --> 00:01:17,200
So I create job out.

17
00:01:17,220 --> 00:01:25,470
I stand here and of course I have invalid authentication because I didn't fix my Barrone.

18
00:01:25,800 --> 00:01:29,280
So let me go back and let me just add that space.

19
00:01:29,580 --> 00:01:35,640
And now everything should work where, of course, I'm getting the values for the company as well as

20
00:01:35,640 --> 00:01:36,360
the position.

21
00:01:36,870 --> 00:01:40,590
So now it's left to do is go back to create job.

22
00:01:40,920 --> 00:01:44,910
And of course, in here we want to import finally our model.

23
00:01:45,030 --> 00:01:45,540
Correct.

24
00:01:45,840 --> 00:01:47,970
And we want to create a new one.

25
00:01:48,330 --> 00:01:49,170
So let's do that.

26
00:01:49,470 --> 00:01:53,430
We're going to go at the top here and we'll create our imports.

27
00:01:53,610 --> 00:01:55,830
And effectively, we're looking for three things.

28
00:01:56,250 --> 00:01:58,200
I want to get these tax codes.

29
00:01:58,200 --> 00:02:03,900
I want to get the job model as well as the requests and requests.

30
00:02:03,900 --> 00:02:04,770
We have two options.

31
00:02:05,010 --> 00:02:08,970
We have bad request error as well as not found one.

32
00:02:08,970 --> 00:02:10,740
So let's go with Carns job.

33
00:02:11,370 --> 00:02:12,630
So that's going to be my model.

34
00:02:12,720 --> 00:02:18,750
So require and of course we're looking in the models here and more specifically, job.

35
00:02:19,850 --> 00:02:25,420
Then we want to get these tax codes so and then start codes.

36
00:02:25,820 --> 00:02:31,750
Now that is coming from our library, of course, so require an HTTP status codes.

37
00:02:32,000 --> 00:02:34,390
And then lastly, we have those two errors.

38
00:02:34,670 --> 00:02:36,500
So let's go here with Bud.

39
00:02:37,410 --> 00:02:46,680
Request an hour, and the second one will be the northbound one, not found error, and both of them

40
00:02:46,680 --> 00:02:50,200
are coming from and of course, the errors.

41
00:02:50,730 --> 00:02:55,530
So let's go two levels up and we're looking in the errors folder.

42
00:02:56,250 --> 00:03:00,810
And once we have all the important place, we'll swing back to create job.

43
00:03:01,080 --> 00:03:07,620
And essentially the idea is following where, of course, at the moment I'm just passing in the right

44
00:03:07,620 --> 00:03:09,720
that body and just responds.

45
00:03:09,720 --> 00:03:10,160
Correct.

46
00:03:10,560 --> 00:03:15,390
And if you remember, what was the method name to create new document?

47
00:03:15,390 --> 00:03:16,800
Well, that was, of course, created.

48
00:03:17,130 --> 00:03:19,950
And of course, in this case, we're looking for a job one.

49
00:03:20,280 --> 00:03:20,730
Correct.

50
00:03:20,850 --> 00:03:26,220
So the way the setup is going to look like we're going to go with the job, then we'll await, of course,

51
00:03:26,460 --> 00:03:31,380
and then we go with model name and create and we pass in the right body.

52
00:03:31,800 --> 00:03:35,310
But at the moment, what we're missing is that user.

53
00:03:35,670 --> 00:03:37,320
And where is the user located?

54
00:03:37,640 --> 00:03:41,140
Of course, it is located in the wreck, that user.

55
00:03:41,460 --> 00:03:43,020
Now, what are we really looking for?

56
00:03:43,290 --> 00:03:45,030
Is the idea correct?

57
00:03:45,300 --> 00:03:49,770
So what do we want to do here is just go with that body again.

58
00:03:49,770 --> 00:03:50,710
If you want to control.

59
00:03:51,150 --> 00:03:52,920
Of course, you can definitely do so.

60
00:03:52,920 --> 00:03:56,850
But I'm just going to skip that part and we'll go wreck that body.

61
00:03:57,090 --> 00:04:04,570
Then we want to create on RAGBRAI a new property by the name of created by Y.

62
00:04:04,620 --> 00:04:08,760
Well, because in our job model, that's how I called my property.

63
00:04:09,180 --> 00:04:12,360
So I had this property on a record body.

64
00:04:12,600 --> 00:04:13,980
And where is it located.

65
00:04:14,250 --> 00:04:20,940
It's located in rec user and the property name is user ID like.

66
00:04:20,940 --> 00:04:26,250
So, so now of course once we pass in the rec that body will still have the validations.

67
00:04:26,550 --> 00:04:30,240
But if everything is correct, we create a new job.

68
00:04:30,480 --> 00:04:33,060
And now of course we just need to handle that as far as the response.

69
00:04:33,330 --> 00:04:35,790
So let's just set up resident status.

70
00:04:36,180 --> 00:04:38,190
Now again, this is going to be the created one.

71
00:04:38,400 --> 00:04:42,360
So let's go with status codes, status codes.

72
00:04:42,360 --> 00:04:48,930
Then we go with comma R I'm sorry, the dot and then we go with created and then as far as the JSON,

73
00:04:49,080 --> 00:04:50,700
I just want to send back the job.

74
00:04:51,060 --> 00:04:53,640
So let's go over here and let's test it out.

75
00:04:53,820 --> 00:05:00,480
So now I'm getting back to the company and position, but if everything is correct I should get way

76
00:05:00,480 --> 00:05:01,230
more than that.

77
00:05:01,500 --> 00:05:08,400
And once we send unfortunately instead of getting back the job, I get back there where it says created

78
00:05:08,400 --> 00:05:08,970
by.

79
00:05:09,270 --> 00:05:15,660
And it is a validation error, which actually just showcases that our validation still works, which

80
00:05:15,660 --> 00:05:16,740
is really, really good.

81
00:05:17,070 --> 00:05:24,300
And the problem, of course, is in here where I went with that body and it should be created by not

82
00:05:24,300 --> 00:05:24,930
created by.

83
00:05:25,230 --> 00:05:32,130
So me save and let me start out one more time and once I send now, of course, I'm getting back the

84
00:05:32,130 --> 00:05:32,550
job.

85
00:05:32,880 --> 00:05:35,130
And as far as the job, I have status.

86
00:05:35,220 --> 00:05:37,170
So like I said, by default, it's going to be pending.

87
00:05:37,420 --> 00:05:38,970
So this is going to be the job.

88
00:05:39,190 --> 00:05:40,550
And this is very, very important.

89
00:05:40,860 --> 00:05:48,240
That's why on the OTH I set up that user idea and that's why also when I was up the dress, on what

90
00:05:48,240 --> 00:05:50,780
token I prefer using that user already.

91
00:05:51,060 --> 00:05:57,990
Once you start building a bigger application, you'll get a bunch of these undergrads and it gets confusing

92
00:05:57,990 --> 00:05:58,620
quite fast.

93
00:05:58,830 --> 00:06:06,840
And therefore I prefer setting up that extra piece of code when I go with user ID or Jabateh or whatever.

94
00:06:07,050 --> 00:06:11,250
And if you keep looking at it, OK, you can see the Google, you can see the position.

95
00:06:11,550 --> 00:06:19,520
All that is nice, but you're also probably noticing the created by and essentially this points to Ana.

96
00:06:19,680 --> 00:06:25,050
And of course, what that means is that now this job will always, always be tied to Ana.

97
00:06:25,320 --> 00:06:33,240
So once I register and log in and get my token and all that, I won't be able to modify, look at it

98
00:06:33,450 --> 00:06:34,350
or whatever.

99
00:06:34,710 --> 00:06:36,960
And you're probably noticing these ones as well.

100
00:06:37,290 --> 00:06:40,200
The created at an update to that.

101
00:06:40,470 --> 00:06:46,050
And effectively we get them by default once we set up timestamps astral.

102
00:06:46,560 --> 00:06:54,490
So Mongo's Schemas have that timestamps option that tells Mongo's to automatically manage, created

103
00:06:54,500 --> 00:06:58,830
that and update it at properties on our documents.

104
00:06:59,130 --> 00:07:04,500
So what that means is that of course, we don't need to set them up manually and you can probably already

105
00:07:04,500 --> 00:07:10,950
guess that this one will always point to the time when the document was created and this one will change

106
00:07:11,220 --> 00:07:12,600
as we're updating.

107
00:07:12,600 --> 00:07:16,230
And of course, we can use these properties, for example, in filters.

108
00:07:16,380 --> 00:07:22,170
And essentially this is exactly what we'll do when we're getting all the jobs and once we can successfully

109
00:07:22,170 --> 00:07:23,880
get back our first job.

110
00:07:24,150 --> 00:07:31,860
I want to congratulate you on pretty much getting over the biggest hurdle, because from now on, everything

111
00:07:31,860 --> 00:07:33,420
is going to be exactly the same.

112
00:07:33,570 --> 00:07:35,760
Like we worked in previous projects.

113
00:07:36,060 --> 00:07:36,840
The only the.

114
00:07:37,090 --> 00:07:44,470
Of course, as far as the controllers will always, always get that user ID as well, because, of course,

115
00:07:44,650 --> 00:07:49,570
we'll need to use it, search for jobs to update jobs and all that cool stuff.

