WEBVTT

1
00:00:01.620 --> 00:00:09.500
So, our application has a couple of requirements and therefore we got a couple of suggestions

2
00:00:09.500 --> 00:00:16.100
here by ChatGPT regarding routes and files and code we might need.

3
00:00:16.980 --> 00:00:22.500
And I'll use CursorComposer to now generate some of that code and some of these files.

4
00:00:23.580 --> 00:00:26.880
And I'll use this full screen mode here.

5
00:00:28.280 --> 00:00:34.360
Now as I mentioned before, earlier in the course, it is typically a good idea to break

6
00:00:34.360 --> 00:00:37.200
up problems into multiple steps.

7
00:00:38.080 --> 00:00:43.920
So I won't put my entire app description here into one prompt and send it to Cursor.

8
00:00:44.100 --> 00:00:50.360
It might work, I might get a decent result, but I improve my chances by splitting up the

9
00:00:50.360 --> 00:00:54.560
problem of building the entire app into multiple smaller problems.

10
00:00:56.000 --> 00:01:01.280
And the first problem, if you want to call it like this, would be user registration and

11
00:01:01.280 --> 00:01:02.580
login for me.

12
00:01:02.700 --> 00:01:04.360
And that's actually quite a big problem.

13
00:01:05.180 --> 00:01:07.360
We might even need to split up that.

14
00:01:07.620 --> 00:01:08.860
But let's give it a try.

15
00:01:09.920 --> 00:01:17.480
So I'll say this REST API needs user authentication.

16
00:01:19.360 --> 00:01:24.640
Users must be able to register, sign up, and log in.

17
00:01:28.260 --> 00:01:37.960
Don't add any JWT code or anything like that, just generate a user model without using classes

18
00:01:37.960 --> 00:01:40.920
because I don't want to use object-oriented programming here.

19
00:01:43.800 --> 00:01:50.540
In the models folder, to give it some hint where it should store that file and code.

20
00:01:53.380 --> 00:02:04.820
Also generate sign up and log in routes, e.g. slash users sign up in the routes folder.

21
00:02:06.520 --> 00:02:20.680
Last but not least, add the code for linking route and model to a user's controller folder

22
00:02:21.299 --> 00:02:25.560
or controller's folder because in my project I got a folder named controllers.

23
00:02:28.120 --> 00:02:36.840
Don't add any code for storing user data in a database yet because we'll do that later

24
00:02:36.840 --> 00:02:37.780
in a second step.

25
00:02:38.800 --> 00:02:40.460
So that's my first instruction.

26
00:02:40.680 --> 00:02:43.060
Might be too complex, might be too simple.

27
00:02:43.320 --> 00:02:44.340
Let's simply give it a try.

28
00:02:44.720 --> 00:02:48.480
I'll send it to cursor and we'll see what that gives us.

29
00:02:49.280 --> 00:02:55.020
Well, it now created, I already saw that, a user object as it seems.

30
00:02:55.400 --> 00:02:58.580
I want it to have some individual functions, but we can change this.

31
00:02:59.980 --> 00:03:04.500
And in general, it generates a bunch of files here, which is good, makes sense.

32
00:03:04.840 --> 00:03:08.020
It generates a user.js file in the models folder.

33
00:03:09.100 --> 00:03:11.500
In there it has an object with two methods.

34
00:03:11.780 --> 00:03:15.620
I want it to have two separate functions, but I didn't clearly specify that.

35
00:03:15.840 --> 00:03:16.840
So we can change this.

36
00:03:17.180 --> 00:03:18.820
We can also tell it to change that.

37
00:03:20.200 --> 00:03:24.640
And then it got the routes here with the sign up and log in routes.

38
00:03:25.660 --> 00:03:30.980
It calls or it points at some functions in the user's controller.

39
00:03:32.120 --> 00:03:37.480
The user's controller then is a file which also has an object exported with methods.

40
00:03:39.460 --> 00:03:45.440
And then in app.js, it brings in those user's routes by using the user's prefix.

41
00:03:47.060 --> 00:03:49.440
In general, that's not looking too bad.

42
00:03:49.620 --> 00:03:57.940
It also adds this JSON body parser middleware here, which will make sure that requests sent

43
00:03:57.940 --> 00:04:03.460
to that API will be parsed by the express framework and any data attached to the request

44
00:04:03.460 --> 00:04:07.040
body will be made available for easy access in our code.

45
00:04:08.280 --> 00:04:13.420
So that's not too bad, but there are a couple of things I don't like regarding these suggestions.

