WEBVTT

00:05.170 --> 00:06.760
Probably everyone will come back.

00:07.060 --> 00:14.800
So in this video we're going to be finishing the four last resources in the API for the bank and we're

00:14.800 --> 00:18.030
going to be wrapping up the whole API basically.

00:18.040 --> 00:18.390
OK.

00:18.400 --> 00:19.800
So let's get started.

00:20.140 --> 00:25.090
So the next class that we're going to be riding's Let's go back to your robot I'm writing the next class

00:25.090 --> 00:27.720
which is the transfer transfer ability.

00:27.720 --> 00:28.140
OK.

00:28.300 --> 00:31.250
So we're going to have a class called transfer.

00:31.460 --> 00:34.120
Then we're going to inherit from resource.

00:34.870 --> 00:35.870
OK.

00:36.880 --> 00:39.580
And then we're going to do define boast self.

00:39.640 --> 00:44.000
So we're going to only support posts because all of them support posts here.

00:44.030 --> 00:48.730
So you can post post post post post and post it.

00:49.020 --> 00:50.350
All of them support post.

00:50.470 --> 00:57.460
Someone I knew posted data is equal to your request so we get to the crux of the first step was always

00:57.460 --> 00:58.940
to get the posts the data.

00:59.140 --> 01:01.990
Then for this one I have a couple of things right.

01:01.990 --> 01:04.740
I have the username the password that.

01:04.770 --> 01:05.490
And the money.

01:05.530 --> 01:07.120
OK so is your memory here.

01:07.270 --> 01:10.720
I have the username password too and the amount.

01:10.950 --> 01:19.680
OK so when a new user name is equal to posted data the user name the and want to get the username password

01:19.690 --> 01:22.770
as usual.

01:24.220 --> 01:30.670
And then there's a certain thing I want to get to Gaisford do is equal to posted data and then I want

01:30.670 --> 01:39.670
to get to just let's just leave the field to them the money is going to be posted data and then amount.

01:39.700 --> 01:43.810
OK so how much amount or how much money do you want to transfer from what I got to you.

01:44.010 --> 01:46.450
OK now a couple things.

01:46.450 --> 01:49.820
First of all we need to verify as usual the credentials.

01:49.840 --> 01:56.990
OK so I want to say return on error is equal to verify credentials.

01:57.070 --> 02:05.350
With this username and password then I'm going to say if there is any errors in the code in that this

02:05.350 --> 02:12.370
function finds out that I'm going to return the size I The Returned is OK.

02:12.700 --> 02:17.270
All right so now I've checked the credentials of the user.

02:17.290 --> 02:21.340
Now I need to check that the catch of the user is enough to transfer right.

02:21.460 --> 02:28.630
So what to say cash is equal to cash with user usernames I must see how much money does he have.

02:28.770 --> 02:36.100
Then I say if cash is less than or equal to zero then in that case I'm going to be returning an error

02:36.100 --> 02:43.300
message which is going to be used on inside and then generate return dictionary.

02:43.390 --> 02:49.120
This is going to be a three or four if you remember three or four is not enough.

02:49.350 --> 02:53.990
So you're out of money so he usually needs to add more money than you're going to do.

02:54.040 --> 02:56.280
You're out of money.

02:56.590 --> 02:59.270
Please add or take a loan.

02:59.650 --> 03:03.260
OK and that's it.

03:03.310 --> 03:06.400
OK so that's if the money is less than or equal to zero.

03:06.400 --> 03:09.000
Now what about if the user does not exist right.

03:09.010 --> 03:11.320
So which user do you mean here.

03:11.410 --> 03:12.800
I mean they use it too.

03:12.860 --> 03:20.710
So let's say you're trying to say two to no sense mind to Santa Claus or Santa Claus doesn't exist right.

03:20.780 --> 03:21.230
Hopeful.

03:21.240 --> 03:23.180
Well if you're a kid and he does exist.

03:23.200 --> 03:30.620
But anyways so if this account doesn't exist in the bank then I can't just transfer it to that account.

03:30.760 --> 03:34.270
So I'm going to do if not use or exists.

03:34.270 --> 03:44.550
So if this user was the name two doesn't exist then in that case I'm going to return the sun if I generate

03:44.560 --> 03:50.950
return dictionary that I'm going to pass to the user a serial one because this user doesn't exist so

03:50.950 --> 03:52.560
it's an invalid username.

03:52.620 --> 03:56.690
Now I'm going to pass the message receiver.

03:56.740 --> 03:58.880
User name is invalid.

03:58.960 --> 03:59.830
OK.

04:00.060 --> 04:01.310
And we're done.

04:01.840 --> 04:02.980
Ok cool.

04:03.100 --> 04:05.930
So other than that what do we need to do.

04:06.010 --> 04:12.660
Well I think to first see how much money does the user how how much money does the recipient have said

04:12.660 --> 04:19.490
the receiver how and also how much money is in the bank because I'm going to take $1 from the trans

04:19.590 --> 04:28.750
as a transaction fee some say cash from is equal to cash with a user username then I'm also going to

04:28.750 --> 04:34.300
see cash to is equal to cash with the user too.

04:34.330 --> 04:38.310
So this is the cash from is the money with me the cash.

04:38.310 --> 04:39.090
Who has the money.

04:39.100 --> 04:40.680
The person I'm sending do.

04:40.900 --> 04:47.750
And the bank cash is equal to cash with user.

04:48.190 --> 04:49.770
His name is bank.

04:50.190 --> 04:52.260
Man in all capitals.

04:52.630 --> 04:56.550
Now going to update the account update account.

04:56.690 --> 05:05.150
Bank and some guy at a desk bank underscore cash plus want someone to add $1 into the bank count as

05:05.150 --> 05:07.250
a transaction fee.

05:07.250 --> 05:09.600
I'm also going to add.

05:10.580 --> 05:16.820
So I'm going to also update the account of the person to reset the money.

05:16.820 --> 05:20.530
And I'm going to send in cash too.

05:20.570 --> 05:28.040
So the money that he already had plus the amount of case plus the money that was sent to him minus one

05:28.130 --> 05:31.830
which is the transaction fee that I that the bank got.

05:31.850 --> 05:33.380
Correct.

05:33.380 --> 05:38.050
And then finally I want to update the account of the person who sent.

05:38.060 --> 05:44.260
So it's the journey that I'm going to basically subtract the money from him.

05:44.270 --> 05:45.020
OK.

05:46.110 --> 05:53.290
So I'm going to do cash no score from minus money and that's it.

05:53.340 --> 05:54.390
OK.

05:54.900 --> 05:56.710
Now of course you can argue that.

05:56.750 --> 06:01.020
Or how do I know that he has enough money that we can add also this next yearbook.

06:01.110 --> 06:05.300
Feel free to if you don't want to do that then that's fine too.

06:05.300 --> 06:06.030
All right.

06:06.210 --> 06:12.720
So now once we're taken taking away the money from the amount that he had then the only thing left is

06:12.720 --> 06:16.280
to journey to success is a success message.

06:16.290 --> 06:16.980
OK.

06:17.220 --> 06:30.660
So I'm going to return Sunnyside and then Gennari to return dictionary as do hundred pounds amount transferred

06:32.220 --> 06:33.160
successfully.

06:33.210 --> 06:35.130
OK great.

06:35.430 --> 06:39.850
And that's it for the for the transfer function.

06:39.850 --> 06:42.630
So that's the transfer function over here.

06:42.690 --> 06:46.980
So it's transferred some money from one account to the other account every day.

06:47.050 --> 06:47.950
OK.

06:48.450 --> 06:51.800
Now the next one is to you and we tried the balance function right.

06:51.810 --> 06:55.070
How much balance are these are Hatsune this one is over.

06:55.410 --> 07:03.580
So how much balance are they use or have someone write class balance that inherits from resource then

07:03.690 --> 07:10.590
I'm going to support the post because all of them are post and then the first step is as usual get the

07:10.590 --> 07:15.560
posted data and we get it from request dobbed get their score.

07:15.600 --> 07:23.520
Jason OK once they have that then I want the username and the password so my user name is equal to posted

07:23.520 --> 07:32.710
data username and password is you to post a data password.

07:33.090 --> 07:34.210
All right.

07:34.260 --> 07:39.160
Now the next thing is I need to check for credentials again sir returned Jason.

07:39.330 --> 07:44.150
Error is difficult to verify credentials.

07:44.220 --> 07:51.040
This username and password none of my check if there then return.

07:51.380 --> 07:55.100
If I the return Jason.

07:55.170 --> 07:55.660
OK.

07:55.710 --> 07:58.940
So that's the one that has years.

07:59.630 --> 08:00.710
All right.

08:00.800 --> 08:04.850
Now a return Jason is equal to users.

08:04.890 --> 08:07.310
Signed.

08:07.420 --> 08:12.400
Going to find the user name the user with this user name.

08:13.050 --> 08:15.400
And then you get access.

08:15.600 --> 08:17.740
Well I'm going to basically.

08:17.820 --> 08:19.460
So I'm trying to find a user.

08:19.460 --> 08:19.980
OK.

08:20.160 --> 08:27.390
But this user I want to get their response that I want to get is they want to get only his user name

08:27.860 --> 08:34.110
his 0 0 1 or 0 1 and his debt.

08:34.110 --> 08:34.680
OK.

08:34.710 --> 08:39.980
So I don't want to see the I.D. and I don't want to see the password of this user return.

08:40.110 --> 08:46.080
So we're glad to hear the projection if you remember from the Mongo D-B slides we talked about projection

08:46.290 --> 08:53.670
which is to hide some of the some of the fields from showing up so I'm going to do a comma here so I'll

08:53.670 --> 08:57.610
come here and then I'm to do another.

08:57.840 --> 08:59.160
Ansal here.

08:59.420 --> 09:00.630
No mercy password.

09:00.650 --> 09:02.810
I don't want to see that password return.

09:02.910 --> 09:04.780
So I'm going to do zero.

09:05.100 --> 09:05.860
OK.

09:06.030 --> 09:12.760
Then I also don't want to see the underscore ID automatic feel underscore ID and then also put zero

09:12.820 --> 09:13.470
aside.

09:13.620 --> 09:23.130
So that means it seems to me the the file off the user with this user name but omit the fields password

09:23.220 --> 09:28.740
and amid the fields ID because they don't want the user to see you know to transmit to him the hashed

09:28.740 --> 09:29.280
password.

09:29.280 --> 09:29.550
Right.

09:29.550 --> 09:33.620
It doesn't make sense and it doesn't make sense to send him the underscore ID.

09:33.630 --> 09:34.060
OK.

09:34.200 --> 09:38.590
So I'm going to make both of these Troung being sent in get.

09:39.180 --> 09:39.630
All right.

09:39.660 --> 09:43.490
And then of course zero because that's the first person right.

09:43.500 --> 09:46.590
There's only one person to find.

09:46.650 --> 09:47.480
OK.

09:47.730 --> 09:50.580
So now what we need to do is to simply return.

09:50.610 --> 09:54.330
Jason if I return Jason and that's it.

09:54.390 --> 09:56.340
And we have basically we are done.

09:56.460 --> 09:57.300
OK.

09:57.620 --> 10:03.570
And we're done with the class we have gotten that balance the bounce information for this user and can

10:03.570 --> 10:09.950
tell you what the user what his balance is what he owns and what he what that he has.

10:10.020 --> 10:11.390
OK.

10:12.120 --> 10:12.600
OK.

10:12.630 --> 10:16.680
So now the last two classes that we have so let's go back here.

10:16.860 --> 10:20.860
So now we're done with the check balance and that we need to take a loan and pay low.

10:20.890 --> 10:22.110
OK.

10:22.830 --> 10:27.410
So the first one is the the payload.

10:27.450 --> 10:35.490
OK slow or let's do the take long first class take loan and then we're going to do research

10:38.070 --> 10:42.570
and we're going to define the post function on itself because all of them are ghosts.

10:43.080 --> 10:45.060
And then we're going to get the posted data.

10:45.070 --> 10:48.910
So the data is equal to request I get discouraged.

10:49.480 --> 10:56.310
We're going to get the user name is equal to posted data username

10:59.950 --> 11:07.310
you're also going to get the password from the post posted data to who posted data password.

11:07.930 --> 11:08.710
OK.

11:08.920 --> 11:14.080
Now what else do or are we going to get where we want to know how much money does the user want to take

11:14.080 --> 11:15.160
as loans or what to do.

11:15.160 --> 11:19.780
Money is equal to posted data amount.

11:19.840 --> 11:20.980
OK.

11:21.580 --> 11:22.030
All right.

11:22.060 --> 11:26.580
So the first step is as usual verify that the credentials are correct.

11:26.650 --> 11:34.110
So return Jason and password is equal to verify the credentials.

11:34.280 --> 11:38.610
And then with this username and password then.

11:38.660 --> 11:40.540
So this one should be here.

11:41.300 --> 11:44.740
So return Jason an air is able to verify credentials.

11:44.740 --> 11:50.150
Then again I say if there then return this on if I return Jason.

11:50.180 --> 11:51.100
OK.

11:51.540 --> 11:59.640
All right now there is no ears that I need to see the cash with the user and his debt.

11:59.890 --> 12:02.630
And then I need to increase his cash and his debt.

12:02.680 --> 12:03.340
OK.

12:03.340 --> 12:07.200
So when I do cash is you go to cash with the user.

12:07.770 --> 12:10.420
You don't want to do.

12:10.420 --> 12:16.380
Debt is equal to cash with user or debt.

12:16.380 --> 12:19.250
True these are some that this one isn't cash with the user.

12:19.270 --> 12:27.800
This one's going to be debt whether user user name that are going to say update account.

12:28.000 --> 12:31.690
So I'm going to update the account the user name.

12:32.410 --> 12:33.080
OK.

12:33.340 --> 12:36.940
And then I'm going to add change to happen cash plus money.

12:37.030 --> 12:41.920
So now this user has withdrawn or took a loan off this money.

12:41.950 --> 12:42.320
Right.

12:42.350 --> 12:44.440
Of this amount from the bank.

12:44.440 --> 12:50.800
So I'm going to increase his own by this money so if you're for example you have zero debt and you have

12:50.800 --> 12:52.900
zero money in the bank account.

12:52.930 --> 12:56.360
So if you take a loan will you increase your money by two.

12:56.410 --> 12:58.610
Let's say you take a loan of $200.

12:58.710 --> 13:01.190
Then you increase your account by $200.

13:01.290 --> 13:10.810
But you also increase your debt so update debt here increase your debt with so that it's the previous

13:10.810 --> 13:17.280
debt plus then you know that you took the new loan that that your debt is now OK.

13:17.530 --> 13:20.600
And then now you can just return Jason if I

13:23.230 --> 13:27.500
generate return dictionary and then we're going to say 200.

13:27.790 --> 13:34.470
And then a message for example loan added to your account.

13:34.510 --> 13:35.230
OK.

13:35.680 --> 13:39.910
So that's basically you're saying the loan was added to your account as a money.

13:40.490 --> 13:40.960
OK.

13:40.990 --> 13:47.380
So the last class that we're going on right is finally class pillow cases where he is going to be the

13:47.440 --> 13:48.790
opposite of this class.

13:48.790 --> 13:50.570
Exactly the opposite right.

13:50.650 --> 13:58.150
Because what we're doing is well we're taking away the debt subtracting the debt that he has.

13:58.150 --> 13:58.710
OK.

13:58.870 --> 14:04.780
So when do you class pay the loan and then resource.

14:05.390 --> 14:07.730
Then we're going to find the post function.

14:07.750 --> 14:08.670
So.

14:08.980 --> 14:09.820
All right.

14:10.180 --> 14:16.280
And then we're going to get first of all as usual Vost and Dana and you go to request that get underscored

14:16.330 --> 14:20.990
any on that we're going to use your name is equal to posted Nina.

14:21.160 --> 14:27.970
You didn't name and password UKL the posted data password.

14:29.690 --> 14:35.790
And then money is equal to the posted data amount.

14:36.400 --> 14:37.620
OK cool.

14:37.680 --> 14:38.820
So far so good.

14:38.820 --> 14:45.480
Now we checked the credentials.

14:47.280 --> 14:49.370
And then we see if there is any error.

14:49.380 --> 14:57.930
So if there then return your son if I turn Jason the Greek or answer once we're done with that we want

14:57.930 --> 15:06.740
to check how much money is they use your house we say cash is equal to cash with user on the username

15:08.970 --> 15:15.280
McCain and then I'm going to say if cash is less than money say the cash is less than the amount that

15:15.280 --> 15:17.680
he's paying that he doesn't have enough money.

15:17.720 --> 15:28.420
So I'm going to say return the sun if I generate return dictionary of three or three and then not enough

15:28.600 --> 15:31.040
cash in your account.

15:31.090 --> 15:32.150
OK.

15:32.930 --> 15:34.160
And we're done.

15:34.690 --> 15:37.560
If on the other hand this is not true then I'm going to do.

15:37.570 --> 15:41.120
Debt is equal to debt with the user.

15:41.110 --> 15:47.350
So when I see how much debt does he have then I'm going to subtract the amount.

15:47.350 --> 15:53.920
So the the accounts are going to subtract the amount that he paid from his from what he owns.

15:54.400 --> 15:56.580
So I'm going to do cash.

15:56.590 --> 16:03.790
So the previous cash that he had minus money and now and then add subtract also what he goes to the

16:03.790 --> 16:13.330
bank to do update debt and then this username with debt minus moneys and such like this amount from

16:13.330 --> 16:14.100
his debt.

16:14.110 --> 16:15.020
OK.

16:15.550 --> 16:16.590
And that should be it.

16:16.660 --> 16:26.450
And we're just going to return to the user return on if I generate return dictionary of 200.

16:26.710 --> 16:34.910
You've successfully paid your loan something like that or your loan in Spain.

16:35.030 --> 16:37.270
Ok done.

16:37.540 --> 16:42.690
So the only thing left to do is to actually add the resources or are going to do it API.

16:42.920 --> 16:44.910
And underscore resource.

16:45.470 --> 16:49.500
And then I'm going to copy that and then I copy it since we have six classes.

16:49.660 --> 16:51.730
So I'm going to copy that six times.

16:51.760 --> 16:52.110
OK.

16:52.130 --> 16:55.710
So one two three four five six.

16:55.810 --> 16:56.340
OK.

16:56.650 --> 17:01.920
So we have the register class which is at slash register.

17:02.950 --> 17:06.390
We have the case let's go back here.

17:06.850 --> 17:16.120
All the spaces we have the add which is add slash and we have also the transfer.

17:16.140 --> 17:17.040
Right.

17:17.950 --> 17:21.090
And slash transfer.

17:21.730 --> 17:22.470
We have.

17:22.510 --> 17:23.470
What else do we have.

17:23.470 --> 17:29.300
So we have the transfer you have also the balance which is at slash balance.

17:29.530 --> 17:36.700
And finally we're now finally we have two new ones which appear to take low and the payload to each

17:36.700 --> 17:42.150
of them and take loan and the other one is at payload bay.

17:42.400 --> 17:48.700
So pay long and slash the loan so that all the resources into our API.

17:48.820 --> 17:59.170
Now the last thing we do is you say if name is equal to underscore main then at door around then host

17:59.170 --> 18:02.990
is equal to zero point zero point zero point zero.

18:03.030 --> 18:04.310
Okay.

18:05.140 --> 18:06.040
And that's it.

18:06.040 --> 18:10.410
So we have successfully written and finished the entire API.

18:11.260 --> 18:15.610
So we're going to stop here and in the next video we're going to be testing the entire API and seeing

18:16.330 --> 18:18.640
how it works.

18:18.640 --> 18:23.890
We're going to do several accounts and see how we can transfer money from one account to the other and

18:23.890 --> 18:24.650
so on.

18:25.330 --> 18:28.440
So we're going to stop here and we're going to complete the next video.

18:28.480 --> 18:30.400
So until the next video decoding.
