1
00:00:01,070 --> 00:00:01,700
Welcome back.

2
00:00:02,120 --> 00:00:08,810
Now what they need to do is that we need to insert a new movie into the array and to do that.

3
00:00:09,410 --> 00:00:11,690
First, we need to check the movies that we have.

4
00:00:11,700 --> 00:00:13,280
So let me check all the movies.

5
00:00:13,280 --> 00:00:14,840
As you can see, we have all of these movies.

6
00:00:15,560 --> 00:00:21,140
Suppose that for some reason you want to edit the title or the year, for example, you want you inserted

7
00:00:21,140 --> 00:00:26,110
the year incorrectly and you want to update that the year or even the title.

8
00:00:26,120 --> 00:00:30,050
Maybe you have a typo or maybe you want to.

9
00:00:31,220 --> 00:00:34,460
Maybe you want to do fix that for some reason.

10
00:00:34,760 --> 00:00:38,660
For example, here we have let me show you this we have your Batman begins.

11
00:00:38,960 --> 00:00:41,000
Let's, for example, change the.

12
00:00:41,840 --> 00:00:46,280
Let's change the year here instead of 2005, let's say, 2000.

13
00:00:47,030 --> 00:00:48,180
Any, any other year.

14
00:00:48,200 --> 00:00:48,980
Let's test.

15
00:00:49,090 --> 00:00:49,880
Let's try this.

16
00:00:50,720 --> 00:01:00,530
So to do this first, we need to know the movie I.D. So in order to update, we need to know the movie

17
00:01:00,770 --> 00:01:01,810
because we can.

18
00:01:02,330 --> 00:01:03,170
We cannot.

19
00:01:03,500 --> 00:01:08,210
We cannot update a movie without the idea of that movie.

20
00:01:09,080 --> 00:01:17,750
And it's also important to know that whenever we are updating a movie or any resource or any type of

21
00:01:17,750 --> 00:01:26,660
data, we also need to get from the user with the ID along with it to get the new or the the the the

22
00:01:26,660 --> 00:01:28,640
piece of data that the user wants to update.

23
00:01:29,330 --> 00:01:33,290
So the year this is out of your comments, I'm going to say you could get.

24
00:01:34,710 --> 00:01:35,130
Movie.

25
00:01:36,610 --> 00:01:44,440
And here for the update so far, the Update Update movie for the update, we also need to use the post

26
00:01:44,440 --> 00:01:44,830
request.

27
00:01:44,840 --> 00:01:51,760
We need to say an app that fast and you are ill again is for a slash.

28
00:01:53,430 --> 00:01:57,210
First and then let's say moving.

29
00:01:59,340 --> 00:01:59,760
Movie.

30
00:02:00,930 --> 00:02:08,670
However, the difference between creating a movie and updating a movie is that the response, the the

31
00:02:08,670 --> 00:02:17,490
request, the body takes the movie it unlike the is unlike, do you think, a movie when, when, when

32
00:02:17,490 --> 00:02:26,490
we were creating a movie, we didn't know the idea of that movie because that movie wasn't created yet.

33
00:02:26,490 --> 00:02:29,910
So it was it was just about to be inserted.

34
00:02:29,910 --> 00:02:32,730
So it had no idea.

35
00:02:33,450 --> 00:02:38,520
Unlike in here, whenever we are updating a movie, we already know that movie.

36
00:02:39,270 --> 00:02:42,240
We already know the idea of that movie and we can't update.

37
00:02:42,420 --> 00:02:47,190
So therefore we we need to provide the movie.

38
00:02:48,120 --> 00:02:55,920
So I'm going to say this, and then I'm going to say updates on their score movie, and we need to pass

39
00:02:56,400 --> 00:02:58,680
two things we need to pass the movie it.

40
00:03:00,370 --> 00:03:04,390
Which is integer and we need to pass the movie itself.

41
00:03:04,630 --> 00:03:14,380
The new the the updated data, the data that we want to update and then we just need to say movie movies,

42
00:03:14,380 --> 00:03:15,970
we need to access the movies, right?

43
00:03:16,690 --> 00:03:19,770
And then we need to get that movie from there, from there.

44
00:03:19,900 --> 00:03:26,680
So we need to same movies and then we need to say movie it because we want to get that movie and store

45
00:03:26,680 --> 00:03:28,570
it in a variable in any variable.

46
00:03:28,570 --> 00:03:32,740
It's a movie and their score to be.

47
00:03:34,220 --> 00:03:34,730
To be.

48
00:03:36,160 --> 00:03:43,210
Updated to be updated, so this is the movie to be updated, which is which is this movie's movie?

49
00:03:43,540 --> 00:03:45,700
Now we have that movie now.

50
00:03:46,000 --> 00:03:52,990
We want to change the title and or the the year of that movie.

51
00:03:52,990 --> 00:03:55,630
So we have the movie, the movie that we want to update.

52
00:03:56,530 --> 00:04:01,000
It doesn't matter which movie it is, but it's only a single movie.

53
00:04:01,420 --> 00:04:06,700
So we get that movie and then we need to access its title and its year, and then we need to update

54
00:04:07,570 --> 00:04:08,920
both of them or one of them.

55
00:04:09,460 --> 00:04:16,150
So we need to say here movie to be updated and then that title, we access the title.

56
00:04:16,810 --> 00:04:21,130
And it's going to be equal to the movie that title.

57
00:04:21,490 --> 00:04:30,700
So the all the title will be overridden by the new movie title that has been inserted by the user that

58
00:04:30,700 --> 00:04:32,170
has been provided by the user.

59
00:04:32,790 --> 00:04:42,580
Similar similarly for the year we the same movie to be updated that year is equal to movie movie that

60
00:04:42,580 --> 00:04:43,030
year.

61
00:04:43,420 --> 00:04:49,930
So we we access the movie that we, we already have in the array and then we access its title.

62
00:04:50,350 --> 00:04:56,050
And then we change its title with the with the title of the movie that the user has provided us.

63
00:04:56,800 --> 00:05:02,680
And we do the same with the year we get the we get the movie to be updated, we get its year and then

64
00:05:02,680 --> 00:05:03,380
we change it.

65
00:05:04,000 --> 00:05:08,140
We updated with the with a year of the movie that the user has provided us.

66
00:05:08,920 --> 00:05:18,010
And lastly, we just return that knew that that that updated movie to the to the to the array.

67
00:05:18,010 --> 00:05:22,180
So we need to say we need to say movies, movies.

68
00:05:23,660 --> 00:05:24,290
Movies.

69
00:05:25,530 --> 00:05:31,740
Movie ID movie ID is going to be equal to the movie to be updated.

70
00:05:31,890 --> 00:05:32,970
Movie to be updated.

71
00:05:32,970 --> 00:05:37,410
So this movie to be updated here at this point, at this point, at this line.

72
00:05:38,190 --> 00:05:44,160
It has been updated successfully, so successfully.

73
00:05:44,970 --> 00:05:46,560
So here we get the movie.

74
00:05:46,770 --> 00:05:53,490
Here's the other comment I'm going to say it movie to be updated.

75
00:05:54,480 --> 00:05:59,130
And then the second line we update the title.

76
00:06:01,100 --> 00:06:09,440
The third line, we update the year, and if the year is the same and or if the title is the same,

77
00:06:09,830 --> 00:06:13,810
it's just going to be it's just going to insert the same data and it's not going to be updated.

78
00:06:13,820 --> 00:06:16,780
It's just going to insert the same title on the same year.

79
00:06:16,790 --> 00:06:23,030
If the user doesn't want to update, it doesn't want to update, for example, the title over the year.

80
00:06:23,630 --> 00:06:29,540
And lastly, we eat at this point, we insert the movie to be updated, which has been updated at this

81
00:06:29,540 --> 00:06:29,870
point.

82
00:06:30,200 --> 00:06:36,260
We inserted back into the irony because if we don't do so, it will not update that movie entirely.

83
00:06:37,010 --> 00:06:38,240
And lastly, we return.

84
00:06:38,660 --> 00:06:42,890
We can return with that movie, or we can return with all of the movies.

85
00:06:43,370 --> 00:06:47,150
Let's return with the movie that has been updated, I'm going to say movie to be updated.

86
00:06:48,920 --> 00:06:54,890
However, since we are dealing with dictionaries instead of accessing the title and the like this,

87
00:06:55,310 --> 00:06:58,430
we need to access the the the title of The Onion.

88
00:06:58,430 --> 00:07:04,730
Like this using the square, the square brackets as a title.

89
00:07:05,330 --> 00:07:13,310
And here as well, we need to say title because in Python, this is a way of accessing keys of a dictionary.

90
00:07:14,770 --> 00:07:19,410
We as well we say here and then we need to say you.

91
00:07:20,500 --> 00:07:23,860
Let me now save and let's head on over to the browser to test.

92
00:07:28,250 --> 00:07:33,740
And you will find that we have a new policy quest, which has a a an endpoint of movie.

93
00:07:34,220 --> 00:07:39,920
However, in order to distinguish between updating and creating a movie, we need to change their names.

94
00:07:39,920 --> 00:07:45,980
So here I'm going to say create another score movie for creating a movie and for updating a movie.

95
00:07:45,980 --> 00:07:48,440
I'm going to say updates underscore movie.

96
00:07:48,860 --> 00:07:51,590
Let me say one more time now.

97
00:07:51,590 --> 00:07:55,580
If I refresh, we should have two distinct end points.

98
00:07:55,580 --> 00:07:59,870
We have two years apart and both are both requests.

99
00:07:59,900 --> 00:08:04,950
However, the difference is that getting a movie doesn't require an ID.

100
00:08:05,090 --> 00:08:11,330
Obviously, it doesn't require an I.D. Unlike updating a movie whenever we are, we are updating a movie.

101
00:08:11,370 --> 00:08:15,320
We need to know the idea of the movie that we want to update.

102
00:08:15,830 --> 00:08:17,600
Let's now update a linear.

103
00:08:18,610 --> 00:08:20,830
Click on it and let me click on, try it out.

104
00:08:21,430 --> 00:08:29,350
And I'm going to update movie number six and then I'm going to hear say, let's update the title, I'm

105
00:08:29,350 --> 00:08:30,160
going to say a title.

106
00:08:34,010 --> 00:08:40,550
I'm going to say Batman Begins, I'm not going to change the title I keep, it's like this, but we

107
00:08:40,550 --> 00:08:41,630
need to provide it.

108
00:08:42,470 --> 00:08:43,540
I'm going to change the here.

109
00:08:43,550 --> 00:08:48,500
I'm going to say we're here, let's say 2015, for example.

110
00:08:49,250 --> 00:08:50,600
Let me click on Execute.

111
00:08:52,360 --> 00:08:57,930
As you can see, it has been updated successfully, and it's returned the movie that we have updated,

112
00:08:57,940 --> 00:09:03,100
and if you want to check that, if you want to make sure that it has been updated, you can use the

113
00:09:03,100 --> 00:09:03,670
get all.

114
00:09:03,670 --> 00:09:06,280
You can use this endpoint and excuse this endpoint.

115
00:09:06,910 --> 00:09:12,580
And if you execute this, you will get the movie, which which is the new updated movie.

116
00:09:12,700 --> 00:09:15,850
The date is different, so the date has been updated successfully.

117
00:09:16,420 --> 00:09:22,360
So now we know how to update a resource or a piece of data that we have in our API.
