Transcripts
1. Introduction: Welcome to this exciting course is feed dotnet Core API and a blazer wasn't and server development. Yes, that's right. You're going to be looking at how to develop an API using a speed on a core. And you'll be exploring hall to build a client application using blazer. And we look at both the WebAssembly or wasn't for short and the server distributions of this laser technology. My name is trouble or Williams and I have over 10 years experience as a software engineer and a lecturer. And I can assure you, I'm going to make all the content very beginner friendly and we're going to have a lot of fun in this course. My objectives for you in this course is to have you fully functional. As a software developer, you should be able to build a fully data-driven web API and a blazer client application, whether in the server side are the WebAssembly said, you should be at least comfortable and proficient enough to appreciate why you would do one and not the other. We'll also look at some design patterns in the name of the repository pattern. And looking at dependency injection, we will get to understand how JSON Web Tokens or JWT for short, authentication on workflow works, we'll be looking at consuming rest APIs and setting up custom authentication in blazer. And at the end I'll be tall. We'll also look at how we can deploy our API and client applications to the internet for general use. Some technologies that we'll be exploring through ASP.net Core, we will look at Entity Framework Core API and JWT authentication, auto Mapper, API hosting, testing, Source Control, and even logging. I'm telling you this course is jam-packed with a lot of content. So with all that said, I'm excited about this course. I hope you are too, and I'll see you soon.
2. Install Visual Studio 2019 Community Edition: Hey, guys, in this video will be installing Visual Studio 2019 Community Edition Now to get to the visual studio website, we type in visual studio dot Microsoft dot com Photo Don't look bizarre studio, and we want to get the community edition. So we do have professional and we do have enterprise. But in the community edition is free for individuals on academic users on ditz. Also open, sir. So once again, um, if you are in an inter press sitting, you should get enterprise and you have to pay a license for that. But then for our pet project, an individual project or academic projects open source purposes, communities there it's free and it's fully powered and waiting to be used. So we just get community on then that triggers are don't lord for an installer. So we just click on that Insulted that was just downloaded Run. It will initialize Onda. We can go ahead with our installations so we could continue on that just fishes a few files for us. All right, so after it's finished with those initial workloads, then what it will do is ask us. What packages do we wish to install to support whatever it is that we're going to be developing. So, like I said, we're developing a web application, So we needed SP dotnet and Web development package or workload on. Then we take that, um, we take that box here on then to the right and said, You see that they're giving us a little list off what will be included. So the latest dot net framework is four point it. So you know, it is that we're getting 4.4 to 4.6. So I understand to go ahead on the teak. All of these all of these dot net framework 4.6 point 1.2 point seven point it on. But that's not all, though. We need that Met core, but then this course is based on dot net core 3.1, which is the latest. But if you go with visual studio and they're getting full 0.1 so we can leave that alone after this, then I'll show you how to get 3.1. Also, since we'll be doing a little as your stuff way, I'm just going to take the A zero box on. We don't have to modify much more there. I'm just ticking that box. Make sure that we have any libraries that would require you can do a drill down on. Just see what else is available to you. Safe. He quit the dot net core cross platform development. If you click that workload, then you get some more dot net core things. But I think a lot of those are already included in the Web development workload as you notice that the total space will increase with each workload that you choose. So I'm just going toe on Tick the 01 on. I'm just going to make sure I have the dot net core cross platform workload on the SB dot net and Web development workloads. We're not doing much development with as your so you can take it if you want. If you If you know you have the space, that's fine. And off course, the more you tick is longer will take the download. But I'm not going to take it for this particle, Of course, so once again we just have the sp dot net and Web development, and we have the darknet core cross platform development on the numbers one to click, Install on, then that will start the installation, which is really a don't load. So based on the Internet speed, this is going to vary in length. Some just quinto resume when everything is finished here. All right, so this process is finished. Burba took just unlearn our on their seeing that they require that I restart my computer in order to complete this set up. So I'm going to say not. No, not that you don't need to restart, but there's something else that I want to show you before I let you rebuild. So I'm going to say, not know which is basically just not going to complete the installation just yet. But I'm just going to minimize this and I'm going to show you that we need to download the dot net core 3.1 tools on, so I already have that open and you can get to this website through dot net dot Microsoft dot com on. Then I'm at slash Don't Lord, where it is showing me that I can don't know the dot net core 3.1 tools or the run time for that specifically as well as dot net framework four point it. So we actually just installed visual studio with the dot net framework. Four point. It's tools, so we don't need to pay attention to that. But we do need the core 3.1 on. I did say earlier that the dot net core is built for multiple platforms. It's cross platform. So you see that that the windows don't know that the Lennox Stone Lord, that the McCoys don't and they have a doctor don't Lord. All right, so we'll go with the windows. I'm using a Windows machine on I'm teaching you based on Windows. But that being said, whichever one year on you don't know the one that's appropriate for you on DWI Run the up so I'm Winton. Just don't load the dot net core runtime on. I'm also going to don't know the dot net core sdk, so I'm just going to don't know the X 64 cause I was 64 bits on. We can don't know that on install it. So when the installer comes off, it's pretty straightforward, a slick in star on. Then it will do what it needs to do on. Then you will see that it was successful. So I really didn't take that long to install on. I'm just going to go back and also get the sdk. So what I got was a run time. I went to download the SDK no sdk short for software development kit. So that's where the real development tools will be, um, made available for visual studio to interact with on notice. They're saying that this release is only compatible with visual Studio 2019. So if you have 2017 or an earlier version, then you may want to upgrade. So that's don't know. Did let's just install that so and then start A comes up with a stick install, let it do its thing. And then it says that everything was successfully installed and they use all their own times and all of the other pointing us. The different documents that we can use for your resource is so we can close that. I know that we've done all of this. Then I can restart the computers. I didn't want to restart and then forget the steps. So I just made sure to install everything and then we just do one big restart Onda low the computer to do its thing. All right, so know that Ari Start is complete. Letters. Go ahead and fire off Visual Studio 2019 on. You can find it by going to the start menu, and you can probably just type in Visual Studio will pop up already pinned my visual studio 2019 to my Start menu, as well as to my task bar. So just by clicking this purple icon that looks like that infinity sign, we will launch our visual studio the once it's launched. It encourages you to sign in or create an account, and you can up to do that later. No, with the community addition, it will actually give you a little, like a 30 day trial kind of feeling if you don't sign in. So if you choose, not know, maybe later and then later down the line, you you see like they're saying, or it has expired or something like that. It's really just saying that they expect that you signed in wants to sign in. Then there is no expiration experience that you have part, so I'm just going to sign in windows account, and this is the windows are cones. Are the Microsoft a corn that I hard long before? Andi. This is the one that abusing for any as your related activities that our house understand to go ahead and log in Once again, you can create a Microsoft cones or, if you already have one, just use it on log in. So whether you opted to sign in or you said not know, maybe later you'll be led to the speech where they ask you what style you like. So dark, dark theme is all the region. I t all right. No, but you can choose the theme that is appropriate for you on the development settings. I'm going to put that toe web development. So, General, Yeah, that's fine. But then what development? That kind of put certain things at certain places to make it more obvious for you to see. All right, So once you do all that, you can start results studio No, just no matter. I'm toe signing feel because I'm on a server and they're certain restrictions, our own certain activities. And so I'm just highlighting that to show that if you said not know, maybe later, then this is a screen you'll get. Once visual studio Florentines, you'll be prompted to sign in and to the right. You see that you have a 30 day trial. So once again, your evaluation period as and that please sign in tow a lot of products. All you really need to do is sign in on that evaluation message goes away. Someone's a sign in once again. All right, I know that I was signed in. You see that? I have the personalized cone they had at my content. And then that evaluation message really has gone away. And so I can pick clothes. And then this is the launch screen for visual Studio 2019. So from here, I can check out something from a source Control. I can open an existing project, open a local folder for creating new projects. So we're going to pause right here. If you got this far, then that's perfect. You've installed results Studio 2019 Community edition on. Then you're ready for the next activity.
3. Install SQL Server Express Edition: as welcome to the first video in discourse. Introduction to SQL Server 2017 on the Today will be looking at downloading and installing this bit off software. Now a database is pretty much a logical collection off related data on That's it. In a nutshell. If you have prior experience with databases, it probably came with Microsoft Access or my SQL. And you just want to extend your knowledge beyond that. And even if you have no prior knowledge off databases, this is an excellent course to get you up to speed with what databases are capable of. What preparation usable in place on how you can go about starting your journey towards becoming a database administrator or just manipulating data in databases altogether. As I said before, we'll be exploring all of these concepts using Microsoft SQL Server 2017. Andi. I already have it up on my screen. The page for Don't lose. So I have included the U. R L, as outlined here in the class notes, and this would get you to downloading the Microsoft SQL Server 2017 express database engine on the short description is that it's a powerful and reliable database management system that allows you to build lightweight websites and their stop application. So this is pretty good. Pretty decent is a decent starting place. If you don't have that high spec high end machine, he does have a regular machine. You just want to get started. This is an excellent option. There are other additions that you would probably see in your research, but if you follow this link, it will cut through all of that noise and all the other editions. And we can get started with express so you can go ahead and that download on Dinitia. Initiate that Donald procedure on then. Another bit of software that we're interested in is the SQL Server Management Studio. Now the management studio will be your gateway into actually interacting with the database , interrogating the data on writing what we call queries in a language. SQL. We'll get into all of those things in due time, but for no, you can follow this girl once again. It's in the class, notes on. We can just take this download button to initialize this download, which may take a while. It's a pretty big file, so as soon as that don't load is done, we reconvene. And then we walked through that installation process. Hey, guys, welcome back. Know that our don't lose our finished. We'll start by installing our SQL Express engine. So we just click on that insulation file, click run on. Then we will be greeted with this installation screen we can click. Basic custom would allow you to select certain features at this stage. We don't need to be doing that. We can just go with basic. We can go ahead and agree to the terms and conditions you can read it through if you wish. If you have other ideas than you may want to change its director, otherwise you means will use as a default. And you can see here that off six gigabytes, we only really need 300 megabytes. So I'm just going to go ahead and click Install on this may take a while, so you will reconvene once this is finished. Okay, so at the end off that installation procedure, you see that you were, you know, successful in doing this installation, and then they give you some information to give you a comics and string. So if you wanted to develop an application on top off this database, then you probably want to pay attention to this part. But that's not really necessary right now. And they just give you the paths for the love fires and other essential bits off the application. Another essential part off this installation process, as mentioned before, is to install the sequel Management Server studio at the end off this experts addition installation, they will actually give you an option to see installed SMS. And this will really just bring up your browser to navigates toe. Well, I figured this speech so the link to this page is already included in the class notes. Andi here. From here, you can get a direct don't Lord toe the management studio. So if you didn't do it before, you may just follow this link and get that file already have it in Don't loaded here. So I'll just initiate this installation. All of this will launch the installer and they really just give you one button to click, which is installed. Of course, you can change this location if you have other ideas for the path. Otherwise you may leave it as as the default on just click install. So this may also take a while So we'll reconvene at the end of this process. Okay, so our installation is finished on Doll we have to do is restarts to continue. So we can just do that quickly. Onda we in the next video we'll start looking at how we start piecing everything together. What a database is on. Why learning this skill is so important. Stay tuned.
4. Create a GitHub Account: Hey, guys in this video will be creating or get up accounts on. This is a really simple step. Get up. Makes it very easy for us to sign up. You just need to go to get hopped up palm. That's G I T H u b dot c o m. Get hub dot com on. You'll land on this pitch. No, from here, if you already have an account and you can sign in and you can pretty much stop watching the video here if you don't, however, then the Senate form is right here. You can do a little reading. Just get an appreciation of what ghetto B is for. And it's all a boat. They do have pricing, so they do offer enterprise plans and education plans and different plans for different situations. But for the solar developer for very small, you know, teams that may not be enterprise ever than they do give you ah lot for free. So to sign up, you need only put in a user name on an email address and a password on Once you have provided all those things and provided that your user name is unique enough off course then you click. Sign up for ghetto on. You should be in. So I already have an account, Some real adjustments Assigning you saw my brothers are going crazy trying to provide information, so I'm just going to sign in with my existing account. So that's my what he can use. You're using him or e militarists to sign in. And the password on here I am. This is my landing pit. So they actually give you, like, a sense off community. It's almost like a Facebook for developers. To some extent, you can follow people on once they're following people, you see their activities on the flu landing page. You can jump to your repository. So obviously, if you're new to get up, then you wouldn't have anything listed to the side here. What? I'm not news. I've been quite busy. Um, putting up content on get off almost any little pet project that I start. I have a get over positive, actually need to go through and clean this up on Also, I've had students add me to their repose in the past. Eso that you know, we could collaborate. Maybe they're having a problem and I could just verify their cord through the re posits. Very all of those things are, you know, possible through this fair, powerful tool. But once you have created your cones and you're signed in Ondo well, you obviously wouldn't see what I'm seeing once again. But then that would complete the sign of active
5. Install and Explore PostMan: Hey, guys, in this video, we're going to be installing Postman. No. Postman is an excellent tool for collaboration on the A P I testing and validation on all of those wonderful things. So it's pretty easy to install, really? Just goto post man dot com Postman. Just like the guy who delivers the mail postman dot com You don't know the up and off course you choose your os, so have a 64 bit windows on, then the don't would starts. All right, so once that don't know this finished, you can go ahead on open the installation file Run the installer are so when it is finished , you will either see a screen prompting you to sign up or sign in or you see the screen. Either way, if you see something to sign in, I would encourage you to do so Actually had it on my machine already. So you know the flow may not be exactly like this, but if you do see this page come up, then it's finally Candace, Click the X, and you can take it off Onda. I'm not signed in anyway, So if you do see the our science upstream looking something like this. Then you know you can just go ahead and create an account. Sorry about that. You can create another cones quite easily using a password, or you just signing with Google. Now I like to just sign in with Google on. The thing is, that portion will keep a history off every test that you have done once you have an account . All right, so I'm just going to go ahead and sign in with Google, all right? And once you're signed in, then you know you can start working. So I'm just going to show you guys a sample of what postman is capable off. Firstly, I'm going just to do with the dark more because they're more this cool on. Then I'm going toe create a new request window. So using this plus sign, just like any browser with the plus signs at the top, you can deceive plus sign, and I gives you a new request. Now, I already went ahead and search for some public AP eyes as we discussed FBI's basically are in our gateway into your database. So people have a P eyes, various people of a PS and I phoned this website. Any dash FBI dot com Andi, I'll just strangle back to the very first PC, can see what they have to offer. So from the, you know, the landing page, they sure your bunch of public facing a p I so together you can just go ahead and click one on do you know, tested toads. So I went over to the Oxford Dictionary one where I would get a list off languages so they show you all off the end points, right? So in building off the FBI, they linked to the data. Be assured they have a common girl, but then they have different endpoints. I will give different bits of information right on then They have different methods. Get on posed on. You have put any of some other ones. But the fact is that you have to know the request type. You have to know the u R L through which you can get that requests. Satisfied? You have to know if you have to pass in headers. So here and I need a applications key on Di di on. Then they show me the responses. So 200 means OK on the initial an example in Jason. What that response would be on then. 44 means not phoned. 500 needs that. There's an internal error, usually with the home server. Not with you. Right. So for four music, you probably searching for something that doesn't exist. 500 means that the a p I provider has on error. All right, so message from any a p I and I want to free for free for ex FBI dot com. Sorry. So I took a closer look at any AP and I realize that all of those AP eyes require that you would have had on a cones be, You know, I registered user Probably a paying user off those platforms you can look through. You see, Instagram, you see you too, Google. Most of those are protected a PS, so they're using some amount of security around it on. We're going to go through all of those techniques in the scores. But right now, I just wanted to have a quick win on satisfaction of seeing what postman can do and relevance off it. Right. So I phoned the free four x eight p i dot com, right? You understand that's in free for ex FBI dot com on. Then we'll go to documentation. So that landing page is actually their demo off them. Consuming the data through the air p I that they're exposing. Right? So they have a database the built and FBI on then the they're making a serious off FBI cause to show the trading index city in your on us the u and G BP etcetera, etcetera. So if I go to documentation on, they will give me the terms off use. Tell me how to use it. So documentation is very, very important and vital when it comes to ap eyes and we'll be using swagger. Um, Sawyer, You why toe r slash vocal When we get there, you see, but will be focusing on documenting over FBI's to a great extent also. So from here, they surely that you have the That's the domain that the AP eyes hosted on right on. Then, as you grow, don't you see the different types of functionality that they exposed? So they get reads data, right? And then they say to me the request it is a gets request on. Then you have the the the endpoints. Sorry, the Ural and the end point. That's what he needs to look like on this is a sample response. All right. And if you look through, you see another one that you can get different piers. So right here you're only looking up the Euro USD one, and they return that the results of that quarter for you. Um and then in this one year, you can get more than one if you want. So you just put in both indexes that you're interested in as the parameter in that in point . All right, so that's a query string for the values the quarries run on. Then this is the response from the A P I. Once a queries run and the data is phoned No, the air records tell a good story because then you, if you pass into appears that don't exist in their system, then they're telling you that you will. It's it's if you don't pass in any, it's ending its required. And if you're passing something that's not there, then you'll see on a record 1000 and two. So you have standard error codes and you have some airports that you yourself can me. So let's try this sample Someone to try the 1st 1 where I'm getting Euro and U S cities. Understand to copy this link, which they said. That's how you get to the data on this end point on that I'm going to open a postman on. What I'm going to do is paste it inside off this it says, enter Questi Worrell. That's what we just copyright request on the URL. So I paced the request. You are l on. Then the verb here. Marble sink and get post. You have put patch. Deletes you have a bunch of them. So get is usually used when you're expecting to retrieve data. Right? So get on, then free for its AP, eh? Well, whatever that request Jarawas, I'm not once committed. Remember, because it's their documentation on. Then I will click. Send know what postman does is mimic a call. Well, not really mimic it actually performs the call to that a p i n point on then retrieves the data in the response. So we see here. It may not be as well formatted as how it is in the documentation. Off course, they're putting their best foot forward, but is the same bit off information we're getting a re it on. We're getting a time stump on. We're getting 1/4 200. If you look to the right, you see the status 200? Okay, So 200 is the universal response for old T. Want to get the 200 responsible? Everything is okay. So the different numbers have different meanings off worse, Right? The time it took to me the cause that this is a quick AP I took on the That's what Half a second on the size off the response, right, You can always format. It's so this you can click pretty or you can see raw or preview or visualize. I'm not sure why. Pretty Oh, that's right. I have to change the four months. So it's pretty html. So this is so we can look in html but the fact that this I can say something like XML while it's not XML, I said html let me quick Jason, which it is on. There we go. So no, it's pretty, Jason. So no, it looks a bit more like, Oh, it is being previewed in their documentation, right? So postman is very handy when you just want to test, Um, what the response will look like. Jason is the most widely used response type. Well, I'm saying that loosely I like to use Jason responses, but the closest alternative to that would be XML on Dwell. You know, once the data is being returned that the user expects on, you've documented what they can expect. Then you are You can feel confident that anybody can use your a p i when needed. So postman is going to come in handy as we go a boats developing our ap and just want a validates that the responses look the way we expect them toe.
6. Create .Net Core Web API Project: Hey, guys, welcome back in this video. What we're going to be doing is setting up our dot net core web ap I project. So that was a most full. But it will be much more fun than maybe I made its own. So let's get started. So let's get started by opening up Visual Studio 2019 Community Edition Onda. Well, when you get to this landing screen, you're going to see a beautiful over than you're going to see this landing screen. You may not have any recent projects have been working on quite a few projects in recent times, so this era might be empty, but the fact is that you want to focus on the get started section er, so we want to do is go ahead and create a new project on. Then we get to see a bunch off templates right now to the left I recent templates these are temples have been using in the various projects that I just alone. It'll you may have it blank, and that's fine. You want to focus once again to the right side, where you will be able to get all of the templates, so let me see if clear. All right. So clear off cleared out all of my filters. And you probably have something looking more like this Sophie one installed visual studio with the templates that I had suggested considering the Web on the dark net core stuff that will be doing Then we're going to see similar templates. I think I have basically everything that visual studio has to offer on my machine. So you may see things on my machine that you don't have one yours just focus on what I see is required. And if you don't have that, then you can, you know, you need to take some corrective measures. If you think you messed up the installation, you can always scroll to the bottom on. Then you'll see install more tools and features, which will actually relaunch that. We know where you choose the pack. Stay neat, install. So if you review the installation video on, do you realize that window? Then you would be able to see which one you may have missed included, and then it will update visual studio for you. Anyhow, what we want to focus on today is on sp dot net core Web application on. We're going to be using C sharp, so please make sure that you see c sharp. He receives a basic. You see someone who is a basic. That's not what we'll be using. Please make sure you see c sharp on. Then you click that click next. Then it's going to ask you for the project to name. So I'm going to name this one book store. Dash E G I R. So we're building. You know, you want to make your project names as really ventas possibility. Want to come back to next week and wonder, Or what project was this? The name should just tell the story right on Then. You don't need to click anything else here unless you want to change a little to your son. I'm going to turn to change my location. You can change your state, that stuff or to my documents or wherever you want the project faster. Cool. I leave that blank on. Then we can go ahead and click. Create. All right. So, no, we get to the part where they're asking us which dot net core template Would you like to use? No. I want you to get well, I want you to pay attention to this part because I'm going to get a bit creative on. I'm going to explain why I'm going to do with the way I'm doing it. Vs um the glaringly obvious we Right. So what they're asking here is do you want an empty project with, you know, you have to put, you know, the files. Do you want an e p I project? Considering that this is an e p a e p I, of course, that one looks at the obvious one, right? They asked, Do you want a web application with razor pages? They want a web application with the traditional more the view controller Leo Oats. And then you can also bootstrap, angular react, um, on Redux templates on top, off the standard with the application. No, I just went through all of that just to give you a preview on well, AP, I would be the obvious one, but here's what we want accomplish. We want that our AP, eyes going toe have some user authentication because, well, we saw when we were starting postman that there were FBI's old there, and that's hot. You know, some keys are some using impossible third requirements on. We want to definitely have using the impossible requirements on top of where FBI, because that will help us still prevent malicious and unwanted persons from accessing our EPA. It will also beat us in handling longings for persons who are bro zing our bookstore on then the a p. I will need to authentic it all that to say that when we go with a p a um dot net score does give us option to choose what authentication we want. So by default, it will say no authentication. If you try to change it, he gives you some options. No windows authentication is not an option, because that means you've been logging in with your Windows credentials. That's best for Internet and not in turn it right, so that would be for internal use. Work or school accounts would assume that this person's on all 3 65 cones on that would not be ideal. Would want to me that the some sun and then individual user cones would be the best one to use. However, by default, it is assuming that you are a user in the cloud, so we don't have any Azura concepto have anything through that Syria probably don't fully appreciate. What does here is upon to this point, and that's fine. But my point is that this is assuming that you already have some as your functionality set up. So I went to forego the use off the the authentication and furthermore I'm went off for would use off the A P I template on. I'm going to go to the Web application template right on. Then I'm also going to look at the authentication options that they have. How electric individual usar cones. You see that it's different. So yes, it's seeing well. It's seeing the on to connect on existing using the clothes. I still have that option, but I also have the option off store in the up, bones in up. So that means I can have my own database and store my users on my database on my machine or on my premises or wherever I want. So that is really what I want. So I'm going to choose individual user are cones. Click OK on. Once again, I'm using the Web application. It really doesn't matter which one I think this one is easier because it's easier to delete what we don't want on. I'm about to show you what I'm talking about. What? The point is that amusing web application, right? It's not a P I this time, but Web application All right, Andi. Individual user columns for the authentication. And then I went to go ahead. Oh, and make sure that you have dot net core 3.1 selected up top, right? So you would have gone through installing attorney. Make sure because you have different dot net core were being with 3.1, which is the latest and greatest off Microsoft technology, as at the time off the recording off this course. All right, so I just go ahead and click create, and then that's going to start doing some magic in visual studio. This might take a while, all right? And once it is done, then we have our project created circle to the left. Well, to my left, I have my solution. Explorer. No, I have a video where we're going to go through bizarre studio and look at all the folders and all the wonderful things, but right? No, my social explorers to the left. It's actually moveable. So by default, I think you would see its dear right. But I can't off preferred to my left because some more natural movement for me toe, you know, find what I want on the left and then work and then, you know, left to right at least in my Western contexts lift direct. So this is it for creating our project. When I when we get back, I will show you around this project our own, the interferes what It's capable off. I'll also explain to you why we would have gone with the razor pages on the authentication as opposed to the A p I and no authentication wrote on. Then this will all make sense to you. But, you know, since we're here, I'm just going to show you a preview. So just this template. Give us a few files. We have ages. So inside off pages we haven't experienced a privacy page on Do we have a startup file? And I'm just going to click the play button here. So the playbook launches the application, it goes into build more checking if there any errors off course, they just gave us project. There are no errors, Onda. Once that is finished, then we will see our Broza launch with our application. No notice that we have by default register and a log in button. So if we had chosen authentication that we wouldn't have this register and longing. But by choosing individual a cones, we have the we have bean. Well, the project was generated inclusive, off all off the libraries and functionality required to support registering on logging off course. This can be extended and manipulated hole we want, and that is exactly what we're going to be doing. But this interface will go away because you don't need interferes for over a p I. And it's not yet. Andi, I'll explain all of that to you in the next video on. We'll start building on something where it looks more like what an FBI is expected to look like. On a bit more sensible
7. Tour of Project Structure and Files: Hey, guys, Welcome back in this video we're going to be taking a tour off our fuller structure and dual generally off visual studio. Now to get started. You want toe open visual studio which will then lead you to this landing screen where he can you know, Go ahead and open or create a new project onto the left hand side. You will see your projects listed toe in that list. Right? So our project is both store AP. I can click that and then it will launch the mean window. We fear Solution Explorer and all of your files. No, my solution experienced the left by default. I think yours is over to the right on. But then you know it's documents on DACA beak and would around the camp in it on UNP in it highlighted all of these wonderful things. So you know, you can make this interface your or however you feel comfortable viewing your stuff. You can dragon drop it anywhere resize at will on then. In solution Explorer, it shows you all of your project files. So you have the www route which is going to have static files even to have areas which usually holds is some pages relating to the identity, as in, you know, user management on, you know, log in, register anything with user authentication and management was inside of this default areas border. You have data where you store all of your data related classes and 100 migrations. I'm just really skimming over because I just want you to have an appreciation off what you're looking at. If this is your fair first time. All right, So then you have pages. No, because we have a razor template working with there. Some things that we really just don't need since we're going to be building out an A p I. All right. So, uh, like I said in the previous video, the reason I chose the razor or I would have chosen to NBC is so that we could take advantage off the default. Um, user authentication for individual A cones features. So by doing that, the project was recreated with some default things I wouldn't have to spend time building again. But then also other default things that we really just don't need on. We're going to spend time fixing the project, are deleting what we don't want and rewarding what we do want. But I want you to also have an appreciation for what dot net core really affords you moving on before I get into the adjustments to be made. We also have the up settings that Jason if you click that, that is ah, conflict file, which shows you some default configurations at the connection string to the database logging configurations and a lot whole starts. So I'm not getting to be once again on Do you have the program not see us? Which is the default file that is run each time you you click the play or each time your application is started. The program that CS is like the initial Isar file and then last. But by no means least we have our start up Nazi s, which basically embodies what we call the middle were so a lot of configurations happen here a lot off default things that need to be included at start up literally. That's why it's got started that CS all of those things are put into this file. No, this fire will require some modification by us in order to get it a PR ready now to be fair , if we have chosen the A P a template, then we wouldn't need to meet these modifications. But I chose reason templates. So I'm going to take off some of the reason related functions and put in some a P I related functions. Another reason taking it on this journey is that if you don't have a full understanding off what dotnet court is, because if you were using dotnet framework, I know you're making the transition to dot net core. It's sometimes related in a very abstract manner. What the services and what exactly needs to go on to get the dominant core application open running so dot net core is like a baseline. It cause it's a number of functions, a number off capabilities out of the box with them. Based on your context, it is going to have certain capabilities included by default on. Then, if you want more, you can add them based on your cunt exponents again. So, within our context, we created a razor application using dotnet court. So by default, without a number off razor, really, it'd, um, phone sons included in the start of Nazi s so we can start off Canada and 35. We see that we're adding a result pages we can go on and we see that we have you static files on its going toe mop Reza pages. So these are certain little configurations that were going to be changing, probably for removing because we don't need razor related functions. Really want a P I related functions. So it's as easy as deleting what we don't want changing your thought. And that is the literal adjustment to change the behavior off our entire dominant core application. And that's why not make war is so cool. So let me just give you a load off the modifications that we're going to be meeting freshly . We're going to be changing some of the configurations here in the startle file. Then we're going to be deleting certain Fuller's that we don't want and in creating folders so that we can folders and other files that are the FBI specific so that we can get this party started. So let's begin. So in the line 35. So I'm going to leave all of these configurations because these are saying that when the application starts up, I want to use a DVD context using SQL Server Onda Um F core or into different work core because it's a number of connectors for other databases you can use SQL Server. You can also use my SQL on. You have quite a few connectors available, so we're using SQL Server because we have an SQL server database on, we will be using the Default Connection string. I'm also going toe modify what we're are also going to use the default identity. So that means the default use authentication libraries. Unfortunately, that would have included when we created the projects that individual user cones authentication option. Yeah, it's all of that is kind of bootstrap in these two calls, right? So we're saying we're using the database that is phoned at this tea for connection later on . We will change that on. We will be using that BB context. The holes over user authentication data storage needs, right? That's what this is saying. But then the part where it says arteries or pages, I'm not really interested in arteries of pages. I'm interested in controller, so you have Reza pages any half NBC and we see the sea says for controllers so AP eyes are usually based on controller functionality. So I'm going to be changing this from batteries of pages toe Adah controllers. So I'm telling the application that I'm going to be using controllers for, you know, whatever it is I need to be doing next, we're going to be changing from you Static files someone to remove you static files because I really don't need static files in my a p I static files are you'll spoil when you have, you know, javascript and CSS. Those files that are required for, you know, styling. I don't need those because an FBI is not going to happen. Interferes at least the AP eyes. Were you just called sitting on top off a database, right? So I'm removing the use static files on I'm also going toe change line 63 to say endpoints that mop controllers. All right, so anything that was saying razor, I'm changing it, Toto Controllers? No, with all that, don't we can trigger a build, and that is by holding on control shift on B. That's a keyboard. Shark cuts. Alternatively, you can just go to the menu item build on click build solution, which will indicate the same keyboard shark. What? For you. So whichever option you prefer, you may do so no. All right, So this building is finished on What I'm going to do is the lead, some off the folders that we really don't need. So I'm going to start off with www route. So if I look in www routines, you will see what we will see. CSS gs lib. Right. So, like I said, all of the static files that are required for, you know, javascript styling all of those wonderful things for user interface would be stored in W W route. Now, I just removed the need toe, have static files. So I really don't need www roots. I'm going to remove this, so I just click it. Press delete. It will say everything will be permanently deleted, I say. Okay, let it go on. All right. Next up. We have areas we don't need era. So, like I said, areas comes with some identity stuff, but it's not the identity functionality, right? So I can remove areas on. I just hold on on control on click pages also so we can remove areas on pages. So by clicking on, then hold it on control and taking another one. I'm selecting two at a time and then I press delete so just removed everything. One time on your project is getting a bit slimmer. So you know it's cutting, though decides so really? Actually, an e p. A project doesn't have tohave a lot off $4 right? Because once again, we really just have court files that are manipulating, handing requests and manipulating theater to give responses. Right. But in orderto handle the requests, what we need are controllers, right? So I'm going toe right click on my project. So we have the solution at the top. But there were the project fire below on. I'm going to right click on. Then I went to go to new or sorry, add on, then first them without a new folder. So let's say add folder and then the full I'm going to have controllers. No, My suggestion to you is that if you see me right capital C for something, you also write capital C on your side. A lot of the times he was spend time debugging things just to realize that you know, you had a common little where it should have been capital and vice versa. So I will always try to maintain good coding standards on def. You just, you know, do follow the convention that I am suggesting that he should have no problem. So we have a folder called Controllers? No. Our controllers folder will hold special class fires or special court file Literally called controllers and controllers do exactly that. They control the flow off the application. So our request will go into an address that at control will pick up on. Then it will say, OK, here is our response for your request. So the first thing I'm going to do our next thing I'm going to do or other is racket. My controller smolder. Go. Don't Ida on that. We're going to add a new controller. See? It should be at the top. If you don't see controller than you can click new item, it will bring up the same that are box. What? I just think New item Because I'll get back to the same any item. So if you create new item, you see controller class on then the default name. Also it. Sorry. You see, Controller class and you see a P I controller class or what we want really is an A P I controller. All right, so that's if you had to go to new item. I'm going to cancel and I went to go toe new controller. So I click. Add Goto controller on. Then this money comes up where it's giving me more pointed options. So I will see a FBI controller empty. It could control with read write options. Andi pair controller with options using into different work hard. So right now, I'm just going to choose a P I controller. Empty. All right, on. Then I'm going to click, Add, then it's going to ask me, what name do I want to give it? So the defaults name is going to be default, but I'm going to call it home, someone to say Home control. And that's the name off my first AP I controller on. Then I click add, and it's been to spend some time. Scaffolding loads the controller. All right, so no, our controller is done being scuffled and scaffolding is just the technical term. To see auto generated pretty much right. So when we get this controller. I mean, it's a straightforward come see sharp court file. We have are using statements at the top or name space, which is our projects. Name dots, the fuller name. Right. So we have the project on, then the folder. Right on. Then we have the roots. So the rudest telling us that to get to this controller, we have to type in, You know, the basic girls on, then slash ap I slash the name off the control. All right, So to get started in over, controller were went to creo will call an action. So on action is usually what handles the request coming in from, you know, some third party applications. So on actual would have to be a public on. It's a phone shown, right, So we have the return type. I actually results right on. Then we give it a name. In this case, I'm going to call it Index because index is like a defaults path for the first please, you heat when you call. Certain websites are with ur else on. Then what we're going to do inside off this action is return a result. So I'm just going to see a return and then with the FBI's different numbers represent different things and the best number you can get when you try something on an e p a is the number 200. That means everything is okay. The cool thing is that dot net gives us functions that I lost the return. These, um, response is quite easily so. I would just say OK, on this is a function. So if you look at the intelligence, it's telling that it creates an okay result object that produces an empty status scored off 200 right? So if I just said return okay, it would just return 200 But I want to return a message of its I can actually just include data inside off the phone shown right. So there's an overload where can include on object. So if I have it, I want to return with the status. Okay, then I can do that. So just say, hello world. He's going to return. Start us 200 Orochi with the text. Hello world. So that stay this for a spin. So I'm just going to click the play button on. It's going to go into build with Misha have no syntax errors and it's going to spin up light version off. I I s on then Probably the browser. All right, so when your browser loads, they're probably going to be seeing for a status for a four. And the http called for a for me, it's not phone. What it's saying is that it did not find any default pass or any content to return at this default pot. So this is our baby girl. Every time we go into de boat moored, we're going to get some local host the colon on some port. Andi Well, it generally doesn't work unless you're in B, but more so where in the boatman It's not working, Um, on. So that's sort of an anomaly or cause for concern, right? So what happens is that if you look closely, it said that to get to the controller, we need to say slash ap I slash controller. So we do have our base. You are. L know which is Okay. A hose colon 4432 Let me disclose on necessary tops on what we need to do is say, slash ap I slash And then he said, Controller and square brackets. So when it's a control insert brackets, what he really meant was slash the name off the controller, which we called home. So when I do that, we'll see Hello World being returned. But that's not exactly where I want us to test and validate this. Remember, it's an FBI. So the FBI can be returning all sorts off things that can be returning. At least they can be returning some Jason objects, stuff like that. Hello World is just a cheap couple so that we can have a quick win for the duration off this lesson. But just the top it all off. I want us to use postman. So I have spent here, and what I'm going to do is create a new request. All right, so I'm just going to replace it with the same path on I put it into postman. It's I get, Then I click send on. Then we get the same response. Little world, nor the reason showing you in postman is us because off the status. So you don't see that in the Broza. At least it's not readily available to you, but you will see the status 200. Okay, being returned. All right. All right. Someone to end this lesson right here. I think we've done enough. We rearrange the folders to be more conducive toe watches acquired for or a P I project to coat all of the fight all the static fans and classifies I really don't need. We created a controller on. We created our first option where we tested the FBI with postman, just to make sure that we're getting the right results from the action. So in our next lesson will continue some configurations as we get started, toe, you know, bring this whole FBI in tow Reality.
8. Configuring and Using Swagger UI: Hey guys, welcome back in this veal we're going to be reviewing, configuring and using stronger. Anyway, now I have mentioned before the importance of having well documented AP eyes. They do act as a guide to persons who would consume the A P. A. On git tells them how it's used, what to call when they want. What kind of information on DSO Swagger does an excellent job off, you know, creating documents are helping us to create documents. As a matter of fact, he took us the auto generate documents based on what we've developed. And so we're going to use this time toe, integrate it into our FBI. Right now we only have one in point, but then, you know we'll put in the struggle. I look at it with one in point and then put in something else and then just look at whole everything just gets generated for us. So to get started, we have to include swash buckle. Your swash buckle is swagger. Is dotnet library Pretty much so to do that, we're going to use a tool calls you get, so we just right click our project on. Then we go down to manage new get packages. Once that lords up, it's a window that's going to show us a bunch of packages of packages are like libraries that have functionality, right? So you don't know what a package for a particular thing and you get a bundle off functions and functionality pretty much so you will see here these are all of the ones that are already installed. So we want to Boro's because you want those that are not installers it on. I would advise that you click the include pre release just in case that the version that you're using version of donna corps that you're using the version off the library may not be included. If you don't click, include pre release. They want the latest library for the latest version of that core. Anyway, we're going to go ahead and search on. I'm looking for for Boco. So that's S W A s wash Boco. All right, And then once we do that search will see a few results and we're going to don't Lord the ones for his feeding it dot net core so that that will be thes three year, right? These are just we wanted one slugger one Sergeant. I want swagger. You. Why? So Don't know what it You just need to hover over the line and you will see the down arrow , right? C to sleep that down arrow, and then it will connect to the servers, ask you to accept something on. Then you let it do its thing. And then when it successfully installed, you see that green arrow? So we've gotten that one. Let's get the next one, which is slugger. Gin. Just don't know that one. That its do its thing. All right, so we have that one tool on. Then the last one would be swaggered out. You. Why? So we just don't know that one also. Now, after we've don't load it, all of those libraries. If we go back to the installed stab, you would see them listed there. Off course. You want to clear the search so they can see all off the libraries that, you know, have courtesy off new get the ones that the blue up arrow are up. It's so I mean, you can come over to the appropriate stub. You can select all and he can update, but I'm not going to do that sometimes off its require you to make some major poor changes . And I'm not going to go through that in this video or in this, you know lesson, so we can leave that until later. But the most important thing is that we have swash buckle installed and we just used to get for the first time anyhow, moving on. The next thing that we want to do is to set up some configuration. So as we would have discussed, prepare to this starts about CS file hoses, a bunch off con figuration and initialize er's that are needed when our Danek or application starts off. So, of course you want to include or new service or our new library, which is stronger. R slash vocal, um, into our middle where? So that's when the application starts up. It's aware that this is a service that needs to be included, someone to start introducing it after I've initialized the database. But before I initialized my controllers so sometimes order matters when you're initializing services. Sometimes you don't want to initialize this service before that one. I usually leave that controls for last because by the time adding the controllers. Everything else should have been in place. I don't if I hope that makes sense. So I just always say order matters on if you can't bother. Are the order seems toe, you know, hard to understand. Just leave this controllers one for last. Pretty much. All right, So let us add soccer service. So to start off, we're going to say services dot on. Then you may not see a list of the missing ad on. Then after abuses, Swagger. There we go. Add swagger Jensen by including our, um, libraries. You know how this new extension method. So add soccer gin on. Then we're going to have to put in something like a wound expression. So we'll see talking. Have you see on, then? An arrow, Right. Um, Andi, open and close. Create a breeze. So that's that's just the start. We're not finished at all. So services that ad saw Gourgeon open. Brace on, then. You're you're lambda expression. You are talking the arrow on. Then open it. Lost. Really breeze close breeze for parentheses and then cynical. And so, where when to start filling out inside of the curly braces? No. With some information needed for sergeant to be able to operate. So I'm just breaking the line and I'm with the top so that it looks beat. Alright on. Then I'm going to start off with my expression, which is the sea or land. A token. Would you see that Onda slugger? No. All right, on then, Open. Brace on. Then I'm going to send me call and again. So I'm just doing it land by lines so that, you know, it doesn't mixed up by the time you try to produce it. Then we're going to start feeling on some information about saga. So if I look at be the function parameters for the soccer doc forms and it's asking for a name on, then it's asking for open a P I info. All right, so the name I'm going to give it is V one, as in version one, this is the first version of the FBI, so soccer knock actually does help with version. You know, when you have more than one versions off the game, maybe at the BBC version I have that sponsors and a free version and paid version. You can actually have Dom. Soccer generates separate documents beast on that. But it's all up to your configuration. So this is the first version of the pair that were preparing to build. So V one on, Then I'm going to see a noon open FBI in full. Sorry. The type of their open a p I being full right on then. This is a new a p a in for open a b a in for object. But I'm just went to initialize it here on then inside off the limiter stores this parentheses that then inside of open a b a in for these are the data points adjusted control and space And show me all the data points that I'm a lot of filo inside off this so I can see a title is equal to and I want to call it my book store 80 i for a lunatic, all the my that looks a bit too personal. We're trying to, you know, prepare for professional world. So bookstore a p I on then comma version. Andi, I can say version is equal toe V one. All right, But when you see that you have a gnome off all the things that you could feeling he could just toe comma. You can put in contact information, more off a description. Seven putting war for description. So I'm just going to brake line so that it doesn't look too jumbled. Friends. Oh, our enemy. Yes. Sometimes I get obsessed with these things. All right, Sam, this breaking line, trying to make it all look needs. So don't type with me just yet. Rides that a little bit better at. So the next thing that I was going to put in was description on then description. This is on educational for a book store. All right, so that is step one to setting up our slugger. So we added the service for soccer. You know, document generation. Pretty much. That's what this one's only seeing on. Then we're telling it that in generating the document, these are some static values that we need to have. So that's a title off the document. The version ing off the paper and the documentation Onda the description. All right, so next up, we're going to go over toe our configure method. So that was the conficker services method, right? That gets called buyer of the runtime. No, we're going to dumb with the conficker, which also get scholar on time. And it's used for the TTP request pipeline. So the first thing I'm going to add for this section on I'm going to do right underneath this statement is up That use slugger. All right, open And those brace. So I'm seeing up with terrible to run these you swagger on. Then there's another land that anyone who I have to say up that use swagger. You I remember that. We don't know that three libraries, right? So, Swagger, Jen was the service. I'm saying, you slugger, I No, I'm saying you swagger you. Why? Which is, well, us short for user interface. And then this one requires a little bit off the lambda like expression similar to what we just saw. So I have to open and close parentheses. Put in my alarm, the talk and I'm using. See, you can use pretty much anything you want here. God sees, start for configuration in my head. But I'm not seeing you most. You see, um, the arrow on then open includes breeze on, then semi colon. So inside off the braces were going to say si dot slugger endpoints rights to see intelligence is speaking up exactly what we want to do. All right, Andi, After we say, see that sucker in points inside off this and you're going to have to type this very similar. The whole I'm typing. It's where without before slash slugger cess again, v one slash Slager dot j, son. All right, so that's probably one thing that you mean, that's how much leeway wish interval of typing. And you probably do. You can probably make it a bit easier, but we can just leave it like that under spontaneity, um, and then comma on then the name. So I'm just mento reuse the title that I had appear on Put it as the name here. All right, so, no, we've told our application that we intend to use slugger. So please, Lord, these, um, libraries when the application runs just in case. All right? No. Let us try and see what difference it makes when I goto debug moored orb Roeser will load on, go to the 40 for sure. But then I want to see the soccer documentation so I can see slash on the very path that I just put in, which was slugger slash v one slash slugger, not J son. So when I do that All right. So I'm getting this arrow, and I do know wife. I do know why. So I'm going to go back to my projects. All right, So the problem just know was because off the controller that I have for the FBI. So what happens is that if you have a public action in an A p I control of, but you haven't given it any rest attributes and we soon gettinto other rest. Actually, terrible. The point is that it's just there. It's actually going to fend off, compete with the swagger. All right, so here's what we're going to do. I'm going to delete this controller. All right? So at home, control of this was our experiment, just to make sure that our people I was working, so we thought it would. So I'm just going to delete it on. Then I'm going to add a new one, so I'm just going to right click click I goto controller on. Then this time we're going to say I want an AP controller with read right actions. So this one is going to give us, like a template? No. So it's not a blonde. Control of force a fill in. This is a template. Right? So I just click add I'm going to call this one. Uh, well, I guess I can call it Home Control again. So I'm just recreating home controllable with auto generated cord. All right. And here we go. So you can see that this one it's a bit more colorful, a bit more lively than the previous one on what I was saying about the rest attributes would be these, um attributes data annotations that are a notations that are put above the action. So this is I get that said, rest verb. I'm not. I get that supports. That's another ver put. Deletes Those are all wrist verbs. All right, so those are the wrist attributes that they're talking about, So I'm going to try that again. I'm goingto go back in to devote more, though, making any other change, but recreating my controller I'm just going to go back into debug more all right. And we're back Attar for four. So let me try that again. Slash swagger slash v one slash Slager dot j. Son, when I do that no, you're seeing all right, some documentation. But then this obviously is not very decipherable. If you've never seen Jason before, this would make no sense to you. If you know Jason, then it still doesn't mean what sense does. No. You have to sit down and study it. So to get to the actual swagger you I, the beautiful of user interface, are the beautiful document that we're talking about boats. You would just take off everything and c slash Slager. So it's local host colon airport slash swagger. And once you do that, it will redirect on index dot html with a nicely generated documents showing you all off your in points. Miss, if I can bring this down a little and bring it beside Well, we have in visual studio, right? So you can see the static values bookstore. Ap I. This is an educational a pair for a bookstore. That's the description, Appleton. Um, you know, we have strength. Well, get all right. So have the get function. I would return all the values on, then. That's phone at a p slash home. Say see, it says you get it be a slash home can drill down into it and it shows you, um, some, you know, schematics are boats, the function. So off course, this can get far more advanced is a very basic and it's was auto generated from basically nothing. So, you know, it's it's a good step in the right direction. They also show that ever get where you can see a ps slash home slash i D, which is a method that we have here on. Then if we drill down into that, it shows you the description off the parliament and that it expects on the possible responses. All right, so I'm not quite ready to start going into an explaining what you know, what each function is on, how it works, right? Nowhere just focusing on based line configurations because we get these things out of the way to begin with, so that when we start our development, you don't after double back on do these things again. No going back toe our projects on our start off that CS file. I can't stress it enough that documentation is very, very important. It's annoying, but it is important because, you know, if we provide a good documents than that reduces the need for people to reach out to you for support. So what we're going to do is increase the capabilities off the auto generated documents. So we're going to in, um, include what we call external documentation, which is default in visual studio well after neighborhood, but it comes in visual studio. But then swagger can actually take advantage of it and include it in its beautiful documentation. And so what we want to do is go to the project, right click, go down to properties on, then inside properties. We're going to go toe build on Once in build, we're going to do two things. The 1st 1 to me is this One word says all put path or output. I see XML documentation file. We just take that. So what we're seeing is that in the background, we want a project. The documents keep its own documents. That and it will be in the form of an XML file. Also, once we've included that we're going to start getting some warnings are boats you know they need every single function to be documented. I'm going to show you an example. So I'm going to me that change, save, and then go back to home controller. And then you start noticing that you're getting green lines, um, under the class, under the under the name off the action. And if you're over over, the function is saying or the air. Oh, sorry. Seeing missing XML comment for publicly visible member that so once of a public property function or class, they expect that you're going to document it. And that's what that any bring that option meant. So when they say documented, I mean, you put three, you know, that is a regular common tracked. But when you put three off those, it generates that summary, and then you see that? So that warning using old gone All right, So if you do that over every single one kind of generates a summary where it says okay, returns, we want to tell people what it returns. We ought to give a description off this function, our class, whatever it is, Right. So this is really cool. It kind of auto generated. If you have ah, parameters. I have an int perimeter here. It's seeing Param name I d. You know, so it's very cool. But the thing is that you can get annoying, they can get annoying, especially when you don't need to document every single public facing, um, property and function. Right. So what we're going to do is double buck to the same properties window and the build on We're going to suppress the warning. So if we hover over the arrow Oh, well, I'm sorry. I thought they would show you the error number, but there's usually like a cord associate id with our You see if there we go. So if you go down toe era list right on, then you look at the warnings that you're getting. You see that there's a number associated with the warning. So you see, just by enabling that No, it's expecting that I'm going to put that XML comment on every single thing that's public, and that's not practical. But I don't need toe document the start off fan and those things. So what I want to do suppress this warning court, which is 159 Once I go back to my properties window and you see this option as they suppress warnings, I'm already suppressing 17 01 and 17. 02 I'm sure you are too. But we went at 1/3 1 semicolon. 1591 On the when I tick, save and go back to my comptroller. Then you will see that those lines are no gone on if I go to the air, unless you see that there no more warnings off that nature. So by suppressing the warning, it's pretty much saying that. Okay, I want you know I won't annoy you with with this one, right? But as we go forward, though, when we do our controllers we're going to want to put in our summary documentation any whole littlest continue with this configurations. I did the chain share to enable the XML documentation on file back in my start off that CS there's something that I need to do on. I have to go back upto the conficker services. Um, function on then after the lines where I set up, slugger Jen, I'm not going to tell it where you can find the excellent documentation. I'm sorry. No, it's not under its inside off. Right. Sorry. So it's inside of here that I'm going to continue documentation, so I'm still inside off the curly braces from at soccer origin. We did the soccer dark stuff on. Then under the stronger dot stuff, I'm going to continue, so I'm going to declare something and see bar exposed expanse amuse start for star X file. You short for its amount file. You can write it simplified if you want. That's fine on. Then I went to right. So it's a very complicated looking path here, so I would use interpretation. What I'm going to see is, um so I have a dollar sign open and close quotation marks inside of the quotation marks. Have my open and close brace on that. I'm looking for assembly. All right, dots, get executing assembly. So intelligence will help you along the way. And that's a function ducts. And then I'm getting name right dots on. That's also a phone shown on there. Say that name. All right, so this is basically saying get the executing a similar. So this is me getting the path where the project sits. So this is a very dynamic weaves and I could ever note the literally in for the project, but then that would be unique to the project and I would have to do that every single time . I have a new project. So by doing it this way I'm just saying What is the path on the name off this project? Right on, then. I just want all off that upended toe the extension dot xml So you will find a an XML file by this name wherever it is, right? So it's just a nice dynamic. We're finding that external fire. So by enabling this, you would see that this is the path it generated an XML file with the same name as a project. So that's all that we're doing right here instead, off trying to type Oh, it all off this as a static thing. We're just being dynamic, so you can copy in pieces this line in as many projects as you will have once you've enable that function for the excellent documentation. The next line we see ex path provide expat physique, Words of path not combine. Pass the combine on. Then you see, I'm getting the red lion's share. So that means I need to include elaborates. I can just go to the red line. Hold on out press enter on. Then I will get the suggestion. Under the light bulbs, everything I need to include system that I own once that stone, that's fine. So if you get rid lines, you just need toe over over them. Hit the lad Bold. You will tell you what library you're missing so part. But combine on inside off the fire indices. I'm going to say up context dots based directory. Alright, calm all X file. All right, so after making these tool and so I'm just getting the XML file pretty much that I'm going to say, See that include XML comments on. Then I'm telling it that you can find the comments at X path. All right, so whatever we put into the summary section off any function or fire that we have, it's going to go into that. It's in a file that we see being generated having into the XML documentation file on. Then we're seeing that when swagger is generating its documentation, it should take into account the contents off these fires. So I'm going to put in to summer Is this is a test controller artist ap a controller on then this one is just been to see gets values. This one is going to say get up value. All right, so I'm just putting in some stuff on. Then one more change that we're going to meet the slugger is a line under Strugar. You I so understood her. You after we defined the juice on file, I'm going to put one more line there to say, si dot wrote prefix is equal. It'll well this open and close quotation marks. All right, so this is going to make it come upon the start up. So, you know, when we go into debug mode instead, off it going in tow, the you know where after bro's to get there, it should come up on the first page. So let's see if that works on Douala. So I just went into Debo mood and the first thing that came up was, or slugger documents. And if you take a closer look, you see that some of the documentation or some off the the comments that I had put it for the options are there, right? So I said, gets values right for that one on gets get a value. What should be gets a value cerebral that. But yet the point is that it works, right? So that s so we set up soccer, and once again it's very important that we maintain this documents. There are a number of other attributes that will be adding along the way, and you would just see whole soccer will enveloped them and include them in the documentation and make it easier for us to share our AP eyes secrets with others.
9. Configure Logging using NLog: Hey, guys, Welcome back in this video, we're going to be setting up some logging utilities in our A PR project. Now, when I say longing, I mean, we're going to be setting off functionality so that we can pretty much write down or set up a mechanism by which you can write down whatever actions we deem important in our application. So the important thing about longing in especially in an FBI, is that it helps you to debunk. It helps you to track exactly what actually happened on where Soto accomplish this. We're going to be using in log on. There are other libraries that you know are good. I use love for nets also, but in this video for this purple servant abusing end log. So to get started, we're going to go over toe new gets on with directly the project, go to manage, get packages, then we're going to bro's on we're going to look for and that's a letter and L or G and a log. No, they're number off them here. But the one that we are really interested in is in love about extensions, that longing. All right, so we're going to click that one. Don't load it into our projects. And once that's done, we can always just go over to installed and verify that they're moving the filter and showing everything that is in or project, um, courtesy off new gets. All right, Next up, we want to set up a conflict. Facts already set up this conflict finally can find it in the resource is for this project , so you can actually just go ahead and copy it. Andi, create a file called end log dot convicts. So to create a file, you just right click the project go. To add on the new item on really? Actually doesn't matter which one. I just use a text file, but it must have the dot comfy extension. All right, so you can use a text file and you see in log dot conflict as the name on. Then you can just place the contents in. I didn't I'm not going to spend time writing it with you, but I will explain what is in the file. So the file is basically just initializing in log xml. Well, it's an XML configuration for four in log, so it's just doing some initialization sit in the scheme of that introduced some basic initialize er's on. Then we have the path. So the internal out file path, I'm sitting it so some path on my machine. All right, so you can change this. So the easiest thing, maybe for you So that you can see where your log school is. Just put it on your main drive, call on slash and probably create a folder called Logs. So I'm just going to make that change her. So it's C slash log. So, um c colon slash logs internal log on, then for the file name. So have targets target blood files. So the target love fire. Meaning where should all the logs school. All right, so we're going to say, found him on. Then you can put in our path once again, maybe to your project folder or to somewhere that is very easy to find. Right. Um and then lay out here. He's basically saying, How do you want me to name this file so Well, this is actually saying Hold your mutilated Named the fire. So the shark bait call unlock fatso for each day that you carry out actions. It will look at the date and generate a new file. Right. So it makes it easier to track what happened yesterday versus last week versus today, specifically on. Then the loads would be whole. Should each line look so you're going to have the long bit the level meaning Western error in for you. So see that level stuff on, then you're going to have the actual message relating to that line. All right, so that is what that is on some rules, as in the minimum delivery of maximal of land song. But I think this is good enough for us. The proceeds. I'm going to save that once again. This is included with the video so you can go ahead on the Fetchit if you wish. All right. So next up, we need to configure to classes and configure or start up so we can just do a quick build control shift and be just to make sure we didn't introduce any heros to break or program Andi. It was successful. So we can proceed someone to add to folders to my project. So I'm going to right click on click Add Onda new folder on then the 1st 1 is going to be contracts on, then the 2nd 1 So I'm going to go there again, right? Click on new folder. And this one has been to these services. All right, so under contracts and want to create class files on with direct click again click add class on. Then I'm going to call this one I longer service on. Then, on the services. I'm going to do the same thing. Create a class, and I'm going to call this one longer service. So one is longer service that's under the services for her on the other one is I longer service under the contracts folder? No, under I love the services or I love a service. Sorry, we're goingto create some old Sorry, this one is going to be an interfere. So the general naming convention for Interferes is that you put on I, um the front off the knee. Right. So public interface, not class, but interfere. So it's easier to describe the class and in change it to interface. But just make sure you don't miss that step. All right, so inside the interface of anti LaVoy, log in four on, then this phone son is going to take a parameter, um, off type string and we'll call it message. All right, So have ah, long in four string message on then. The thing is that there are basically a few types of things that will want to love may be in for warnings, debug messages and definitely errors who want to Sierra. So we have one function for a log in four on, then we're just going to creates three other functions for warn. So I just duplicated that I just use control and be so by selecting the landed just do control and be any duplicates that liner so have long in full aga warn on. Then I'm going tohave log, debug and then log error. All right, so I have these four functions that will be handling logging on based on how it's going to be configured. Each one is going to appear differently slightly differently inside off the log file. All right. So it would be easier for us to see all the arrows on cut through the noise off in four. Maybe warnings would be less useful, and definitely we don't need the book under certain situations. So that is it for our contracts? I can to save that and then go over to the service. Now the service is going toe. Have the definitions for those functions you just outlined in the interfere. So I'm going to do Colon. I longer service. All right, so this is what I call inheritance. So the class is going to be inheriting from the interface on then. Because of that, Smith to say I need toe include some missing stuff. So I'm just going to use the light bulb put in the using statement on then further to that , is going to tell me that I have been implemented after. No, go ahead and implement the interferes too. No, I get the function definitions her, um, per function that was declared in the contract file. Now, after doing that, I need, uh I need, uh, on elements, so ah, property. Pretty much someone have private static, and then this is going to be off type I longer. So I longer is apart off the end law. Glamorous after include cedar using n loud. So they have their own logging shore. But I'm using n log, so I want to make sure I'm using in log right? I longer, longer on. Then that's going to be equal toe love manager. Some initializing my longer object on Gwen to use Get current class longer. All right, so know that I have this lining. I can call on this object or this. Let's call it an object so I can call on this objects. Noto carry all my logging. So let's start off with log people right now. It's just during are not implemented. I'm implementing it. So I'm going to say when it's what I call the sorry when I call the love debug function. Then I want my longer toe create a d bold message. See that on then what it will send over is the message that I have passed into the function . All right. And that's pretty much it so longer. Log Arrow is going to do the same thing. I'm calling my longer object dot error. All right. On and off course, I'm the one controlling what messages are really being passed in. So if it's an error and I must make sure I passed in the air a message so that when I checked the logs I see the Arab that was throwing all right, So But I know I'm sure you got the hum of it if you didn't take and possibly on random off . But I'm hoping that you already posit video and finish a builder to hoping that you wrote the same thing I was going to read on where Both cart andi Few world to longer dot info for logging for longer that warren for warned. Then we're all on the same page. Now we have one more change to make on. That is to the startled about CSO. We have toe add that components the our middle where configurations and remember order matters always receive the controllers lying for last. So anything else here adding just a bit above right. So for in log art for the longer service to be initialized into our application that start up, I'm going to say services docked. Add singleton. So you can know add the service into the whole middle were on into the start up off the application by adding either singleton or transient or add scoped. So I mean, we're using single time, so I'm just going to say add single Thanh I logger service on. I'll explain the difference City in the single town underscore PTA and the transient later on its don't overwhelming with information just yet. So what we're doing is saying that we want to create Singleton instance off the service on this is our service. Really Our This is our contract for the service and this is the implementation off the contract. So anything that's missing, you know, you just over over it and include the library accordingly till you see no green lines on with that, we would have set up in love in our application in our entire donna core application on meat it ready for use. I know that we have set up in love. We need to test it, right? So the real test would be to try something or to put in a line off court that should create a log and then verify that a lot was indeed created. So I'm going to go over to my comptroller on what we're going to do is put in some lines in maybe two or four options of sissy. When we hit the action that it should write the log that the action was hit so to get started, what we need to do is perform this thing called dependency injection, where our service is going to be injected into the controller so the controller can interact with are in love service. Right. So we reference over service through the contract, someone to say private, and I'm we just call it read only Andi. I see I longer service. All right, so that's name off my contract that I created on. I can just go ahead and either use out, enter or just pick on the liable to include any missing dependency on, then underscore longer. So that's the name off my objects. That is when they embody the service that is logging. But then for dependency injection, we need toe. Be clear inside. Off. Over. Controller. Over. Um, constructor. Right. So I'm going to say public home controllers are constructors. A default function that gets called once a class is initialized. Right? So I'm going to say once you called home controller, I want you to initialize I longer service. I'm going to just pass in the eye longer service on then the parameters I longer so the cool thing about Donna Court refused to do dependency injection in previous versions off NBC, we need third party tools like inject or something like that, but NBC makes it that sorry dot net core makes it very easy to just dependence Inject because it comes biscotti built in on this whole ecosystem surrounds dependency injection. So that reduces some obstructions, Um, some duplications and doing things more than once It reduces the need for some off that. So I'm just going to initialize our read only object on the score longer toe the object longer that is going to be passed in when our home controllers called. I know that I have my object initialized. I can no interact with the service. So if I wanted to allow something I could say underscore longer not on then I have access to all of my functions that I just declared. So I would want to maybe doing in four on dsi accessed, accessed home controller. All right, so I'm going to say in the love that this that you access the home controller on I'm going toe, try and do a different one, some to stopping that on. Then under the gets let's say I log Debo instead. All right, on, then. I'm going to say God's value on don't know Post. Just based on that, I'm going to love an error this time. So in its post, I'm going to say this is an error, something like that on the last one under. Let's try the leads. Um, I was going to get a bit complicated, but that's fine. We can get that later on. So this one is going to be a warning. This is a warning. All right, on this is going to be love warn. So I forfeited. All of these functions are actions rather with longing functionality. So let's try someone to go into de boat moored, and I'm also going to launch postman. So if you have already installed it or if you even if you haven't, then you can go ahead and install it and launch it. All right, so we're going to put in our first AP I call. So I just copied the URL from our debug sessions, said US local host school on four. For my port is going to be different from your so whatever this base you are is on. Then in Postman, I said that you are l slash ap I slash home. So that's name off my controller. A p a is no situated at home. On when I do that, I got I went straight to the get right. If I do home slash five, then send it sends it toe value. Okay, so that's the sorry. So let me just show you what's happening. So when I went to home, it went to this one. So the expectation is that in the law file, I'm went to see this getting log before the results came back, right? The same forget would see a debug. And I suppose the value around really that's cerebral, That all right, got a value returned the value on then let's just do a post. So to do opposed, Understand? We've been doing get some just going to remove that value. And I just have to change this request, stop the post and and send. I never backtrack a little was going a bit too quickly. All right, So, um, back in our controller, we have our post. Do we get there through a P? I slash home. So that's what we have. It's a post method. So we are not using gets, but we're using post. All right, but then it is expecting some value from the body. Right? So that means using postman we have toe put in some faced are some value in the body. So if you click that body it out so appear you seep Arum's authorization, headers and body Right on. Then the default one selected is known. So we have to go where? Toe raw. All right, so you have different ways to submit data into the body off the request being sent. All right, so we're going to select a raw and then we're leaving test Jason. So you may see text. Jason is what we want. All right. So if you see texted us, click it and you see Jason in the list on, then we're just going to type in a string, and we're going to say test value. All right, on, then, when we send, let's see if that one works. All right? So we don't see anything coming back because, well, it's not returning anything, but we are seeing a status. Okay. Right. Um, I could even modify this, that it could return something else. But that's not really what we're here for. We tested the post on it went through on then the final one would be another one. That we want to test would be the delete. So if you look at the guideline or so to get to do, see FBI Slash and this is once again why documentation is so important. So it's FBI slash e p i with action slash five. All right, so let us try that one together. So this time we're doing a deletes. The requests type is not poses, not get, but it's delete right on. I'm expected to pass enough values. I'm going to save five. I don't need our body someone to say from known on the reason. No, I don't need our bodies that I am. If you look at the post, I also look at puts you see from body tsunamis is expecting the value from the body rights . Um, so I have this bad habit have a heavy hand when it comes suppressing the shift anyway, So let's try the delete. So I just change that to delete a ps slash On it is a pier with action slash five suddenly send and then it will replied, Okey, so that means it hit. And if you're not sure, you can always put our break points on the action. Oh, because I mean a modification. The break point will work out after restarts, but you can only just put a break points on a line off the action on. Then just make sure it hit the right on your click send. You will pause for Depot Guy in earlier at the right place, Any hole I just tested all off the options in which we put longer court. So what I'm going to do is find that path. So I forgot the path. My path is C slash project slash bookstore a ps slash project slash locks. I'm going to discuss Peel off that bring up my explorer window on. I'm going to navigate to it on here I am. So I navigated toe the file path on my system, and I see the file newly created. So if I right click and let's say open with Notify plus plus, then I'm going to see lines her requests that I sent so we, firstly, you can notice that it has in the date it was in the time stamp on, but it has in the type off log line or the level. Right. So we know all the in fours with all off the eros. We know all of the warnings, right? So it tells us the narrow don't where they was an just that general information or it wasn't error that occurred. Or if you just start warning off course where the ones who are determining which one gets written were in the court. So as the developer, you will be able to know that when this happens, put you down as a warranty. When this one happens, put you down as an error. So somebody calls in answers or, you know, they experience this difficulty at this time. On this day, you can find the file, find the time stamp on, find out what arrow may have occurred that contributed to that user's experience. So that is how we set up logging in our a p I. And that is why it is relevant to our application on, you know, you can review it once again. This is included with the resource is for videos. So that is the excellent configuration file on. You can go ahead on set up all the other stuff for a longing
10. CORS Configuration: in this lesson, we're going to be configuring our course policy. No cars is short for or it's an acronym for cross origin. Resource sharing. Pretty much it's a mechanism that gives rights toe other users who are not on the same don't mean as eso. If on application is hosted on another machine from my machine on it is trying to interrupt is my EPA. It would fail basically the way we have it. No. So the course policy is basically a way to enable the interruption across the pipe so that , you know, everybody from anywhere in the world can interact with the FBI if needs be. So I'm here in my startup dot CS fire on. We're going to go down toe the configure services function and so I can just add this right underneath where we're initializing oh, our identity in the entity framework. And I put that above the slugger implementation. So what I'm going to say here is services docked. God core. All right, so there it is, our course intelligence is going to help on. Then I'm just going to put my semi colon, but then we need some options, right? So I'm just going to use my whole Andi start up like a lambda expression talking, all right, and we'll really take myself there, open and close, Curly breeze on, then inside off this instead of the current breezes, we're going to see or not add policy. So after Adam policy on, we're going to call it the course policy. So I understand the core responses is there clear what published it? This is on, then. Come on on, then we need another. So a lot of the times, you're probably wondering, there you can't all these configurations and you're probably wondering, OK, Home, I suppose. Memorize these things. You know, honesty. You probably will memorize it. And you probably get used to the pattern. Andi, even if you don't, then there. Lots of resource is over there. That will help you dot Net core has great documentation. So as I go along, I may be using different tokens, so you may not see people using or you may not see builder, but it's the same concept, right? So we're doing I know it just building the policy. So I'm going to put builder in another line, so, you know, it doesn't drag outs, everything is clear. And then I went to say, builder dots alot any origin. So this one, this policy or despite the policy, is basically saying that you know, anywhere that the calling are the calling server rights or an application that is making, um, contact with my a p a. Anywhere it's coming from Hello? It right on, then under that I'm going to say dot on. I'm going to say hello. Any method. So that means I'm not going to restrict anybody Toe only be able to call certain parts of the FBI and not call others on. Then one more where I'm seeing a low any header because there might be headers. I don't know what hitters I'm going to require in my FBI calls just yet, so I don't want to put restrictions on the headers on not not noise. I'm just following any off course. We can restrict them otherwise, but it's good to have an open policy, at least based on the context. Here. It's good time on open policy, and then we restrict at the application that rather than a global level now, after we've done this and we've built that policy. We have two more lines off court that we need to write. And that's known in the configure. So we did that in the configure services were added that service for pores? No, we need toe let up. Know how it should be behaving. So I'm going to do this right above use rooting on. I'm going to say up that use cores. Alright, Some tenant up that most use cores on day. I have to specify what policy. So we just named it up here. We just build a policy and give it the name, course policy. Someone to reuse it. Don't hear you scores on. We're using the course policy on then we are pretty much finished. That's it. So we've added cores store application and know we're ready for a little about interaction
11. Review and Add Changes to GitHub: Hey, guys, we're back. And in this lesson, we're simply going to be reviewing what we've done on checking our changes in tow. Argueta Balcones. So I know I'm sure we already signed up on. What we want to do is add our new projects or current project as a repository on our ghetto balcones. So to get started with that, it's relatively easy. The first thing you want to do is look in the bottom right on a corner and you'll see are but in their dresses out of source control so you can click that on. Then you can choose get. So if you don't see that if you don't see at the source control on our if when you click it , you don't see get. That means you may have missed something in the installation so you can go ahead And don't Lord the third party tools for visual studio or review the insulation videos that you would have gone through before on this point on, make sure that you didn't miss any steps anyhow, if you do see it, you can proceed to click get, and once you've done that, you see some interface changes. One you no longer see that. But this is at the source control. But, you know, see one that says bookstore A p I. And you see the branch being called Master. All right, next up, you will want to published to get up. So you see this new team Explorer pee and come up and you see pushed as your develop services. We're not using them ups, but we're going to be using get hub Let maybe later and I can set up develop century how that works. But right now we will focus on get off. That's easier to get started with And then I'll go ahead and click publish to get help. You would then asked me to verify my user cone. So if you haven't signed it already than you can, it will probably part problem to to sign in. Um, if you already signed in then you will look something like this. So you just confirm you can change the name if you want. I'm going to leave. My Andi can add a description if you wish. If you make it private, that means all you will be able to see it and interact with it unless you directly invite somebody to come on, collaborate on it with you. I'm going to leave mine on Ticked on Click Publish so that it will be a public, publicly accessible repository. So what is going to do is create the repository. Synchronize on, make sure that it pushes its too ghetto dot com under my profile. Now, when I get to get hope, I will see all of my repositories, and I will see my newly created one bookstore AP I. When I click it, it will navigate to the space. So from here, I can add a description if I didn't put it there before at my website on, you know, fill in like a quick read me to give some information about their positives. I'll do all of that off here. You can go ahead and do your own boat by the time we reconvene, and then some information should be there. But yeah, that's it. So know if your computer crashes, it's you will always have a backup in Get up. You can always come back to clone or don't load where you can just open in visual studio will come down to your machine you can open it and start working again. And that's one of the major advantages with using 1/3 party, um, cold hosted source control provided like ghetto, where your cord will always be somewhere safe. If later on you want to change it from public, you can go to settings on. You can manage the access so well. I don't think you need to go to manage access their ago. So once you click settings and you scroll down, then you'll see. Make this report story private for public. You can transfer ownership, or you can delete it if you wish managed access with a lawyer to invite other persons to come and collaborate with you.
12. Create Database in SQL Server: Hey, guys, in this video, we're going to start designing the database that we're going to be using at least the base data me is that we're going to be using for this project. The overall scenario that we're working with is one where we have a bookstore on day. Want us develop an AP because, well, they have. There's a bookstore, they have a database. They've been storing data on the books and authors. Andi. So what happens, though, is that they want to actually provide their information about their books and their authors toe third party, um, personnel on the best way to do that is through an E p I. So that different websites can integrate with their database and pull data on their books on potentially even make purchases through those third party websites. So the scenarios, really that we're going to be building an FBI on top off on existing database. So that being said, the scripts for the database that we're about to build is provided in the resource is so if you already owe feel with building a database from scratch, then you can just don't know that script and go ahead and generated on your computer. For those a few who are not see, you know as comfortable. Then you can watch. This video will go through building all the database. We really only have two tables. One for the books, one for the authors. We're going to create a relationship on day as we build it told, and you'll see any little nuances about building the database through the the sequel management studio. If you want to improve your skills on database development, that you can check out my other course, which is entitled Microsoft SQL Server Development for everyone so you can check that out and improve your skills in SQL over. I'm going to continue so we would have already installed SQL Express, sir. Um SQL Express. If you have another edition off SQL Server on your machine and that's fine, you can just go ahead and bring up the management studio with that instance on when to start over in this instance, where I just open the management studio and the Spotswood pop up. So to conduct my SQL Express instance, I just use a dot and then about slash and in the word esque UAL Express. So once I do that and could connect, then I should be ableto get access toe this screen. So on the databases, I'm just going to right click and say new database. And then the first thing any to provide is the name off the database. I'm going to call it bookstore. Alright. Bookstore, camel case. Bigby Big s everything else, the lower case. So I just call it bookstore Click. Ok, no, to get to the database, any to expand databases. So you see that here that I have a bunch of other databases, but the one we're interested in is bookstore, so you probably have one. And if you're in your feet and you should be able to never get so we go down little bookstore and there were Actiq tables on. Then we click new. So radically tables, new table. All right on then, that will launch our table designer Now for more table designer, we're just going to start filling all the columns, the data type each column should have and whether we can accept no values in that column or not. Right? So the first column that every entity needs toe have in well designed database is an i d. All right, So I d would be would represent a unique identity fire, right For every single record that goes in, they can be uniquely identified by whatever value goes into the ID column. That's its purpose on then the data type I'm using for my own is int, But then, when it's a unique identifying honestly what you call a primary key, So to make it a primary key, I'm just going toe crickets, right click, and then you see the option set primary key on. Then the next thing that I want to do is make sure that the value changes by itself every time. So under column properties, I'm going to go down to the one that says I didn't see specification and then I'm going to set this to yes, I'm making an identity. So once this identity, he will increment by one Each time a record gets added, you can change that, but for no, we leave it alone. Next up, I'm going to be adding first name. So the author's first name on this data type of when to use environ char 50. So Environ tire is saying that I'm going to be Story in text on I want to store up to 50 characters worth off text. All right, next up, where last name, which is also going to be invite our 50 I'm goingto have viol and then this one I'm going to set us environ char marks because, you know, in case you want to say nice things about Author Marks means that there's no perceivable limits. So it's almost up to the limitation off your database versus your machine. But there's no like 50. You did this. Wants to get to 50 characters. Everything 51 beyond will get chopped off marks. There's no real number Limits writes on, then profile on. Then we'll said profile. Ah, all right, well, I think bio and profile are pretty much the same, so I actually just remove profiles. So the author has first name last name bio. If we think about anything else along the way in the project and we can add it some just going to do control s and save. Sorry, I did that without explaining. So just to save the name off the table, we do control SRE can't the floppy disk your on. Then we give it a name. Author Click OK, and then we have our first table, which is author the next table that we want. So Iraqi tables again go to new go to table on then the stable is going to be books. So if all of the same design pattern we have a 90 I'm making it tough type into a muscle in to make it a primary key on Set it to be identity. All right, so of course, you can always pause the video and rewind where I may have to quickly there. But I just press along. So each book has a title on the title is going to be environ Char. I'll put Environ chart here to be 100 because you know you have some books with long titles . Well, the year on, then this is always tricky When, when it comes to the year at the publishing year, do you see it? Us on integer you save. It does maybe invite our four right? Um, it can get tricky, so I think because there's no year data type, there's also a beat time be at the time, but I don't want to store all of the deed time just to get the year rights. So what I'm going to do is I am going to story it as int, right. So, of course, when you're building the application, it's up to you to ensure that proper data gets through to the database. So all of those are rules. You have to be mindful, offering putting in the ESPN, which is, you know, the the books unique number that it may have on this can be a unique identify also. But you outside of having things that make a book, Uli, by having the book itself within the database, you want to generally make sure you have a primary key that is separate and apart from identifying factors off a book. All right, um, I'm going to put in a summary so summary would be like, you know, if you were to advertise it to somebody, let them read that summary. We're going to have an image for this book. So in a preview image on this one, I'm going to set us in March are 1 50 also. So I'm sitting in to be, you know, rather big in terms off So what happens is that the image is really going to be the path toe. Ah, file are I leave toe a file somewhere? All right. So we can just leave that as is When we get to that point, we'll explore it a bit more on. Then we have the price on. I'm going to set the price his money. So SQL MSs you'll actually gives us a data type. You have small money, and you have money where it's money. Money, right? So money is like a nice data type literally designed to store money values. Um and you know, it built into the engine to hunt these values better. All right, so the last one would be author I d All right. So author, I d know will act as a primary key. And that has to be in Tudor because sprint Sorry, foreign key, because foreign keys have to have the same Did the type of the corresponding primary key, right? So a foreign key. I'm basically saying that whatever value goes in here is going to link to what everybody goes in here. So if author one brought a book, um, we're going to store that books record I'm going to put in the title of the year and everything about the book. And then I went to put one as a value for author. I t to say that this book is associated with the other with the author. Sorry, who also has that I devalue? All right, So there are two things that we need to do here. And then we're done with this design for Know where I'm going? Toe one, save this table. So I'm going to save this one. Has books right on. That should be authors. I called it author. It should be authors. So if you have author, I suggest that you do us are about to do where Just expand tables and you see your two tables There you see author on books. So the name of the table should usually be plural ized to reflect that it's storing more than one record. So you're storing more than one records off off thirds. So you just put off thirds, right? So let me go through that renaming exercise again. Sorry. Sometimes I move quickly. All right. So you can right click. It's on, then you see rename right now. Once you do that, it becomes inevitable. So what I did just know was just double click, but very slowly. So it's already selected. And if I just take it one more time, it becomes inevitable. That's all I did differently. But it's the same effect. So authors and books And when you get that warning profitable renaming, click Yes, on Press Ahead. All right, so we have authors and books. So now that I've named it better, what I'm going to do is right. Click in the empty space under the books design, right? So go back to my books design right click, go to relationships on the number, spent the ad right on then beside tables on column specification. I'm going to click that role. I see this ellipsis the ellipsis on. Then I'm going to go to the primary key table, which is authors. So I want a primary key in. The author is stable, which is I D. On that. I'm saying that the corresponding column in the book stable in the Foreign Key table, The corresponding column would be author I d. Right. So limit author, I d makes it easy to know that all this is a foreign key to the author Stable Sonam, linking the meaning. I can't have author 100 in the book Stable for it for a book. But I only have five authors are known off them of the I d 100. So what we're creating here is a constraint in the value that it's possible once again if you know, I moved too quickly. Andya I'm using jargon is that you're not quite understanding the new canticle. My course Microsoft SQL server development for everyone on it will bring you from scratch. What databases are whole to develop databases for your purposes on Ben? You know, everything else was snapped into place. What operas Ahead here. So I click, OK, kick clothes on, then I save on. Then once I saved that, it's going to prompt me that I'm about to me changes. I say yes. No, you may get on era if you're not so familiar. Were you with with this kind off modification, you may get an error saying that you know, you can't change tables that exist already or you have to drop or something like that. What you can do is go to tools or two options. And then in the dialog box that comes up, you go down to designers on. Then you'll see this option. Asus prevent changes are required. Table recreation. So you you would have a ticked if you got area would have. Addict, you just unticketed it. All right, So once you on ticket and click, OK, and then you transit again. You should be OK. All right, so now that we've had we've designed this database or next mission will be to start building on the A P. I R. At least start off the project starts off the source scored our own building. Old's the FBI on top of it. Right? So we'll be putting example data and maybe making some modifications as we go along later on. But right now we've accomplished quite a bit. Once again, the script is available for you and what you can do with the script, and it will look, I will look like this. This is script. So what you do with it is open it in the management studio on you just click execute, and it will just, you know, build these tables. So I went through how you build them in the designer with the script. You just need to open the script in the in the management studio. Sorry. And then the slick execute, and it will go ahead and create both tables for you. All right. All right. So that's it for today soon.
13. Implement Data Classes and Entity Framework: you guys in this list of we're going to start setting off our data classes in our project so that we can start interacting with our data. Peace? No, We did set up the databases in SQL Server on. We use SQL Server Express on. What I have here is a Well, this is a database diagram or e r d. So pretty much of the so the generate this I would have drilled on into the database and then going to be to be a star. Grams directly cook new diagram. A dialog box came up. I added the tables on. Then it generated this. So it still showing me all of the columns, the primary keys on the foreign keys on Show me that there is a foreign key relationship. What Primerica foreign key relationship between these two tables. Anyhow, that's really just a guy because that's not where the work is going to be. The work is going to be in visual studio, so we have a few changes that were going to have to make in order for visual studio, our product in visual studio rather toe have some knowledge off the database that we're building on the other side. So the first change I'm going to make is in the up settings that Jason file. So in this file, you'll see a default connection, and it is going to have some server on some database information in there. Nobody defaults. They're giving you. Ah, rather unique name. So they give you is be nets dash. Whatever the name of your project is dash on, then some good value, right? You know, what this would do is tell entity framework that this the name off the database and if it doesn't exist, then created it does exist, then use it. So in our case, we already have a database. That's a simulation because we're building an FBI foreign databases that already exists. So what we will need to do is tell it one. What server is that database on? So this is ah, local DB server that basically came built into visual studio. It's perfectly capable, but we don't noted, and we're using SQL Express on the way to get rs. You express it still state the name. So you're going toe. You have three options. You can either say the name off here must machine box slash andan SQL Express or whatever instance it is you installed in case Maybe didn't follow me and get SQL Express Any of another instance you're using that that's fine. Just pointed to the right server. So if you followed me on your doing exactly what I'm doing and that's perfectly fine, then the server address that we need here would look something like either the machine name or we gonna write local host on, then the box slash and then you see SQL Express. So this is saying the local machine, which is my machine here on the SQL Express. Instance, If the databases on another server, then more often than not, you can actually just put in the name off that machine in that space. All right, on dso This is telling me that I have an invalid escape characters. So actually need a double backslash right there. Right? So it's if one slash, like backslash is something special. So it's just saying about illegal character. Just put that double on it should be fine, are So I'm saying that my server is a local machine and you're looking for SQL Express instance, which is pretty much what is displayed here or when we try to connect. Remember, we saw that SQL Express so you could have written it as it appears here. Of course, you need to double slash because a slash s is a problem or you can a local host backslash backslash SQL Express are uneven, short, illiterate. It would be to see full stop s your express, Our full stop slash SQL express. I could have said full stop right here. All right, so full stop backslash backslash eso that full stop represents local was pretty much, but I leave it at local host. Next up is the database part. So we need the name off our database. So I named my database book store. That's what I called it. So I'm going to change the name off this database, which is what they're giving me. And I said that they're giving me a part of a charity. They call it bookstore on the Square FBI, so I'm just going to delete the fat. All right. Either way, you just delete what was there. Leave the semi colons, please. So you just deleting around the semicolons? Do not trouble those semi colon so If you run into errors or you see that Greenland appearing, it's probably because it missed the top you can undo. Go back to the original and try it again. So, do you want to change the server name between the equal sign on the semi colon? Seem for the database Name Equal Sign into semi colon on. You don't have to trouble anything else in this line off toward practically so you can just click save. See this file and he can close that file So we're done with that fire for no next up we have the application db context. So for the application DB Context, which is phoned under your data folder on That's a file application. Db context. It's basically interacting with the up settings Jason D. For connection, and the reason is doing that is, in our start off. We had said that were used in the default connection. Uh, so the DB context is using that class file application. DB Context, which is using an SQL server on the configuration for the connection String, is found in the form of default connection in up settings. Jason So this DB context is is no no that we've made this adjustment. It no looks at our current database that we just told it is the database were working with . So, no, what we need to do is write some class files in our projects that will look just like over tables. So when I say right class files that look like our tables, what I'm seeing is on the you can just type Asyut type. We'll just start off by saying, db set on, please. The casing is very important. You want capital B Capital s BB set on, Then the first table would be authors, So I'm actually writing a class file. So I'm going to explain why I went to see Author are not authors. So Beebe said, Author. And then I'm giving it the name authors and it's a property, really. So it's gets set on the red line is there? Let's find over about it just yet. On then another one. So I just wrote the word prop. The Rop pressed up twice, and it generated that line for me. So I clearly missed off the public qualifier off that once Amigo boxes should be public. BB sets on author in hunger brackets and then authors on. Then let me try that again. So it's public TV set on then angle brackets. And then this one, his book on the name off the table is books are so these what's in this angle bracket is expecting a class. So what I'm going to do is hover over it. Put the light bulb on, then see generate a class author in a new file on. Then I'm going to do the same thing for book sales. He moved from being white and Underland to know being Sion or whatever color that is just like a really key words. So I went to the same thing for bookworm, went to generate book in a new file so that it was generated these two files author and book inside off my data folder right beside my application. Db context. Now the reason I named the class author but the table or the name off the property authors is really a matter of semantics, right? So we have a set off authors, right? But then whatever the class name is, you want to represent a singular instance often author. So one author represents one record representing one class in our, um you know, our concepts are project right, our program. So it's really somewhat of semantics, but yes. So we have a class for the author, and when we have a group off them, he would be authors. And that source mentum up in the data beast over table called authors on the CME concept for books. All right, so I'm going to start filling Haute our class files. Solidos hold on control and click. All right, So, control, click on it. Navigated till the classes definition. Right, That works 90% off the time. So I'm going to start laying wrote the properties for author relative to the properties on data types that we had outlined in our database. Or let us assume we didn't build this database, but we're inheriting a database that we have to develop on top off. We need to know what were the column names? What were the data types? Citron was the key on. We have to mimic all off that in our data class so that we can start interacting with the appropriate table. So I'm actually going to start off by telling it the table that it should map. So I can I have the opportunity to use over call data annotations onda. We start off with square brackets. So this is in between the Braves for near space on the public, right? And we're going to see table Capital, T table andan open and close burn disease. And then I'm going to tell you that the table er associated with is all third because that's the name off the table in the database. So if you mistyped it or maybe he didn't put on the s, that's fine. I won't kill afford a spelling. But just make sure that you put it back because visual studio will not allergy to proceed, or you'll run into problems if the spellings are not accurate. All right, so table needs something included. So I'm just going to include that dependency. So we get our Dana Data annotations for schematics on, Then we're going to start filling old over author class are also going to meet this a partial someone to say, author, partial cross. So it's public partial class order. Sorry. All right, so we're going tohave on idee column on We defined idea in the database to be integer or so going to our first name and last name both a string, because in the database we declared them as vier charge just to go back and check, You can always go back to your columns. I look at the data types So first name was March are or environment are first in my last name are both. That on bio was var char marks, which is pretty much just another string on. Then that's it. So there we would have defined all off the corresponding columns. So one column. Well, that's all of them. That's four columns and we have all four columns here. However, what happens is that on Author may have many books, So that's the point of the relationship with one author, many books. So if you're not so familiar with relationships on database designing canticle, my course Microsoft SQL for everyone all right, but not show the table with the foreign key. Pretty much is the many. So once you put a foreign key in a table, you're saying that you have one entity that can have many off these records. They have one author. Um, you know, one record for one person that you can have many books related to that one author. So then in C sharp, what we want to do is create ah, property that says that if I get an author and I want all the books associate ID, then I need at least off the books. So that's exactly what we're going to write out. So have public virtual on. Then I'm just going to include this. So we're using a list, which is a C sharp data type. I list off type book, right. So I want a list off book classes on. I'm going to call this list books. That's it. So if I get one author, then I would be able to include all off the related books inside off that record? No, for the book, we're going to start off by defining which table it is associated with, which is the table books on. Then I'm going to once again meet this one partials its public partial class book. No, I'm going to start building old or defining the different column. So have I d basically each one off them, so I just go through and remember too much them back to the beta tests that you stipulated in case you stipulated different data types from me and I went ahead and did it say composite video and failures in. But I'll explain what's happening here. So we have the idea. Of course we have the title where the in. So you see some question marks besides off them, I'm basically making no little. All right, so when we say notable in the database would of defined is no in C sharp, you have to put a question mark and it works on some data types. It doesn't work on somebody. Once we put the question mark, it means that it is a load toe. Have the value? No. So entity framework is going to enforce this kind of validation. So if I try to create a book on, I don't provide a vital for state title than it's different, work is probably going to kick it back and say you need a valid for this. It's usually is that strict with numeric on bullion. Once toyed string, it kind of has a bit more leniency, so I'm really just focusing on the integer. The double Andi, the other integer now have filled out all of the columns here that are present in the database on have author Odd I D. But then the cool thing about entity framework is that if you have, ah, relationship Ori of that foreign key relationship remember that I discussed that with author. By including this list off books, I can retrieve just an author and then automatically get the list off books. No, the same thing for book. If I retrieve one book on, I want some details on the author in SQL you'd after at an inner join, but in entity framework, it allows you to include a property off the type off the class file that has the data. So no, when I get that book, I would have a property in that book called Author on Off Course Author Ideas. What would link author? And you know that whatever the idea is off the author, it's on to retrieve it automatically on. Then I would be able to get their first name last name by on their details just by getting the book. So that's what into different work brings to the table so you can go ahead on and save that on that's it for no. So what we just did just to recap. And I'm just going to do a bill to make sure that I didn't introduce anything to break the program and it was successful. So that's good. So what we just did was one cheers the settings for the database to look at our appropriate database, which once again would be within this context on existing database. All right, we also went ahead on DWI configured the partial classes for our tables. Of these are like conduits are ambassadors for database. I don't know which other word I could use to describe them, but pretty much they're going to broker relations between our application here on the actual database. So our context db context? No, si, is that okay? I'm looking for a table called authors and I'm going to be using this class that we just defined toe broker Any relationship between those If I mean starting something, it will be relative to what I can insert through this class on as we go along. This will make a bit more sense, or just doing based on configuration. Some things will change that may have to revisit these things, but for nowhere does these configuration, so we don't have to do them again. Don't deny
14. Setup AutoMapper and DTOs: Welcome back in this. Listen, we're going to be setting off our data transfer objects, or DT owes four short as well as setting up Autumn Oper, which will handle the well mapping between our data. Friends are objects on our base data classes. So let me explain a little bit about why we need data transfer objects. So I have here the data classes that we recently created, which would be book on author. So we already know that these are mopping directly to the tables in the database. If we change the table in the data base, you have to change these classes accordingly just to make sure that we don't break anything along the way. Now, the thing is that we don't want to interact directly with these classes. These classes are supposed to be direct representation off the database on if we need to modify them, they should only be modified relative toe modifications in the database over throats building the MP I were going to be exposing certain functionality that would allow the interaction to be someone limited. So we are in control off what I user can do through our 80 I on that are begins with proper development. So I'm going to probably give an example where, you know, in inserting a new record, inserting a new book, we probably wouldn't allo them toe put in a value for the I d. Would probably just want to give them a title. Give them, sir. Give them the capacities to enter a title. Enter the year, maybe the ISBN number on maybe a summary on everything, but they're not the i d. Also probably to determine the author in anything. We probably wouldn't want them to be able to change the image boat on them to be able to change the price and so on. So a data transfer object is pretty much what we call a model. If we're in NBC would call it a model in in a pair. Development will call it a B t o. All right, so pretty much it's just going to be like a conduit. So it's a further obstruction away from the database where we're controlling what kindof beetle can be passed over on. Then we are handling that manipulation afterwards, so we're building that program. So the first thing that we're going to do is include Autumn Oper in our Solution. So we're going to right click on or project in our project. Sorry on then, Goto manage new get packages Then we go over to Bro's and then we're looking for auto Ma Per So auto is an automobile and mop er on the Semicon Take include pre release If you had unticketed from a previous exercise on, we're looking for auto Ma per So we're going to go ahead and install that autumn Oper on. Then we're also going to install the extensions dot Microsoft that it dependency injection . So just go ahead and start that. And then once we're done with that, we can go ahead and exit new get so no, we have autumn upper. No, we need toe. Let our application know about autumn upper Someone to go ahead and create a new folder on I want to call this folder. Ma pings So m e p p i n g. I have a spending error there, not see my cursor. Her mom pings on, then inside off this full that we're going to create a new class on. I'm going to call it mops. So you just want to choose names that won't clash with the keywords. Right? So you may not give. You can call it something different. Just make sure it doesn't crash with the keywords. So we have public class maps, and then I'm going to say call on profile. All right, so then it's going to ask me to include something I have to use. Autumn upper. That's fine on then. Well, this is just a configuration class, so we're not quite ready for this just yet, But we do let we do need to let our application or boat or autumn oper aspirations. So we go to start up, not CS on. Then I'm going toe. Add it all rights above this Strugar. Someone to say services, dots ad Oh, too mapper. And there it is, in the bottom of the list. So at autumn upper and then I want to say, type off on, then call the the place the name off our class, which is mops. So type off mops on semi colon off course go ahead and include anything that's needs to be included on. Then we're good to go on the part, so no, our application knows that it needs tomar Pratt sparked off the services. Next up, we're going to make a few details. So where we may not make every single DT all right? No, but I'm going to meet the base ones and then, as we go along with, probably make other ones. So I'm going to wreck, click again, create a new folder. So it folders are an excellent way to keep your like files together. Agita. One fires all over the place. So that's why I'll be creating a lot of bullets as they go along. So this time I'm going to call it DT holes. Right? So that's the name off the folder on. Then I would interact with the folder click add period, a new class on. Then I want to call this one author Beatty, or and I'm just going to create another class at the same time on call this one book, GTO. So for each data class that you have each table, you know, you probably want to make sure you have beat transfer objects so that you can skim off what shouldn't be modified on you track off what should be modified along the way. All right, so these are the base DT owes that I'm goingto have so real entry they're going to look pretty much like the the data class. So I'm actually just going to copy all of this over right from the data class on I'm going to put into the DT or here Not a good thing. So you may be wondering. OK, so why do I need to classes? And that's fine. That's a valid question. Eso I just copied everything from author into author DDO Everything from booking to book detail. The good thing about the DT Oh no, is that it's Low City and four certain validations from the forefront. So while we would have set up the database to say Okay in March are 50 you would notice that book is a string and there's no real limit to the string, so the string could be environ tire marks and it could be invite our 50 could be environ Taiwan. We don't know at this level we don't hear, however, when they come to the GTO, that is what our users will be interacting with. So whatever rules we set up for validation here, if it's required or if it is, you know, limited in the number of characters you can get Whatever it is that we want toe set up the limit. Um, our users off the A p i to be able to do, we would do at the data transfer objects level you see here that I copied and pasted directly from booby to have a red line. So you probably went ahead and included data, but really intially, I don't want the GTO to directly interact with the data class, so details should interact with each other. So I have author detail. So if I need some representation often author inside off my book detail, then the relative one would be author detail. All right, So details on data classes do not directly interact. Right? So that is why we have Autumn Oper so know that we have to details set up. All right, I can go back to my mops that CS file and finish up my configurations. So the configuration that I'm referring to here is to create the mapping. So I'm letting autumn upper nor that these two classes should be able to mark directly to each other. And that is why the same column or property names have to be present. So if I spelt one wrong or if I if I spoke summary with an old. But with that, you end up in the book data class both on or in the GTO, then automobiles going to ignore that because as far as automobile is concerned, they're not the same. They're not like right. So when I'm sitting on maps that CS that is what we're happy we're doing here. So I'm going to say, create mop and then open angle bracket. And then I'm going to see that I want to mop author and then save comma to author E T o. All right on. Then, after the angle bracket, I open and close parentheses and I'm going to say dot reverse mop. That means that mapping can go in either direction. No, you see that to have a number for it lands and I have a spelling error. Let me describe that on then. I'm just going to go ahead and include everything that needs to be included. So after including everything that needs to be included, Dad and I'm getting a Ridley. Oh, my bad, my bad. So what we need here in the class is Ah, constructor. My bad. So we should say public maps. So I didn't emigrate to the constructor. Apologize. So we have or class mops than we have our constructor on. Then we be clear arm UPI's All right. So I can just create the two mapping. So I have one for author and also detail on then I'm with one for book Onda Book DT. All right, so essentially, what this is going to do is alone me toe fill either one off these on then. So when I say Phil, I mean, if I run according to the database and I get back data class off book But then the detail that I have has maybe three fewer columns than the data class does. Then I can just do a direct mopping, and it will find the colors of the same names putting that data, ignore the others, and then I have ah book PTO object filled with the relevant data. Coming from the original class on the reverse is true because off this configuration, reverse mop, where the book details can be filled with data. I just need to map it and it will fill on object off type book with data which can then be passed over to the database. Off course. It would only get that fire if the validations that I set up in book video have been successful. No, just the close out. We're going to do one build and make sure that everything is intact on doing my build. And I see that I have to wear a serious so in author DT or I have the property and mapping toe book. So like I said before bto staff to DT also d t o right on the cool thing about autumn operators that once the mopping exists, if I have to mop something, um, from author GTO but relative to the book, it's automatically going to handle that mapping is such an awesome library to you. So I made that adjustment and I'm going to build again. I'm see if I have any missing assemblies. I do not want successful build on dso We're done
15. Review and Add Changes to GitHub: Welcome back. It's that time again when we review what we've done for this section and then check our changes into get hope. So for this portion off the course, we would have created a database in SQL Server Express on. Then we went ahead and changed our up settings to point to that newly created database. We implemented the data classes that were going to be using to interact to the tables in the database. And we also set up Autumn Oper with some DT owes to make sure that we have the mapping configuration for our user and versus our database. And in our a p I No, we're going to just check in our changes. So each red tick represents I changed the file. So if you see our it take, it means that the file has been changed since the last chicken. If you see a padlock that it means that no modification has taken place since that fire was checked in on. If you see that process enemy is that while you just added something new to the existing robust erso to chicken are changes. We went directly the solution click Commit on, give it a message so I can just write a nice the message so you can pause the video and writes the message like I wrote it. But I always encourage you to be relatively detailed in your message so that somebody else who comes along can have an idea as to what was done with this chicken. However, to check in completely just like this don't are beside the word commit all and then you see , commit all on the sink on what that will do is commit locally and then push it to get help . Once that is done, you can always go back to your positive and verify that your changes were done on. Then that's it.
16. Authors: Setup Repository and Service: Welcome back. We're going to start setting up our author repository now. Just a little background Are repositories pretty much like a collection off functions, right? So when we talk about our author repulsed or what we're doing is setting up a base structure through which will interact with our author table toe, carry out any database related operations. So it's another level of obstruction so that we're not directly calling on the data class every time. But we're just calling a function. Andi, this function can be used multiple places on. Then we'll sit up for dependency injection into our controllers for access. But we're also going to use this opportunity to set up a base repository. So that means that every table, well, every tape is going to carry out this guy. Four off the same functions are operations. Basically, the crowd operations create, read, update and delete. So we'll be setting up a base or buster with ah baseline definition for these functions. And then every other class or every other repository rather will inherit from this base a little. Start with that. So first them want to goto our contracts Folder, right click, click. Add on I'm adding class on. I'm really adding well, class or interferes, We're really creating an interferes. But I can use class regardless. Andi, I will call this one. I repository BCE. All right, So once you have put in that name, I repository basically ahead and click, add and wait for that to be generated. So once again, we're doing an interfere, So I'm going to change last the Inter fierce. All right on then. I'm just going to say I want the base to be relative toe some class entity that I'm calling tea. Where? Tea. Colon class. Parts of this column saying that this is a based repository on its functionality will be relative to water a class I say it is relative to. And when I say class, I do mean the data classes that are the direct brokers. For the appropriate table, you will all make sense. So I'm just going little by that stand. We're building it together. So we're going to have a fuel functions. Um, well defined, not defined. Declared inside. Off this interface on, we'll start off with this one called Find all No, I'm going to be using asynchronous programming so you look at a synchronous programming, which is, uh, parallel programming technique that that it makes very easy toe implement, and it will increase the responsiveness off your application on these operations. So let us sit together so toe due to declare on a synchronous function, we have to declare to the task and then we open angle brackets and then if it is returning value, and then you have to specify the value that is being returned or the data type off, the value be returned. So the 1st 1 that I'm doing is find all and I wanted to find all in the form of a list. So are I lists amusing? I list on that. I want the list off type t remember, teas just relative daughter, a class type is being passed in right on. Then I'm calling it find all. So basically, I'm seeing if this function gets called, it's an asynchronous function. It should return at least off Whatever class I am requesting on, I'm calling the function. Find off. Next we have a task on this one is just returning one instance off whatever class element or one object off whatever class type I'm requesting on. I'm calling this one. Find by Heidi on this one is going to take a parameter off int i d. Next up, we have task. Sorry. Task on bull. So this one is going to return a Boolean on. I'm calling this one. Create on what? I'm creating a some entity off type T. So t on, I'm calling it entity. That's my base name for it. So whatever class type, I am going to create an instance off, Understand? To pass in the object. It's expecting an object off that class type on. Then I want to also have a bit and delete which are going to look very identical to create . So I'm just going to duplicate that and say get Andi Deletes Remember, Control D is the duplicate Sharkey. And then I went up a final function called Task Bull on this one is going toe handle sieving. Right. So the thing within two different work when you create, you have to always save the changes for it Actually committed to the database. Now, this is just the base repository. No, I need a repository that is specific to my author operations. I'm going to go ahead in contracts. Create another interferes on. Then this one is going to be called I author repository. Alright on. Then I go ahead and click, add. But then once again, it's an inter fees. But then this interface is going to inherit from repository base. All right, so when I say inherit, I just mean I'm going to see I author repository Colon on. Then add repository base on then t is not what I'm passing but because I know I'm dealing with author, the exact entity will be author All right, so that means everything that will be done inside off this particular interferes will be relative to author. But then that's cool. It's going to be so for every data class that you're going to have a repository four. Then you're just going to specify which data class it is relative toe on, then your functions are going to be defined relative to that. All right, but this is just another interface. So that means if there are other Auster related operations that I want to carry out, that we're not, you know, are not a part off the beast. So the base is just you know, these are four operations that every table is going to be able to carry out over. I mean, have specific kinds off operations. Maybe I want to retrieve author by a book I d or something other out off the norm out of the norm of what is in the base. Then I can write those declarations inside off. This interferes part on guy will need to include what is missing. There we go. So once again, these are interfaces, and these are just declarations. So off course, we need a concrete class that is going to actually implement these operation. So the contract, sire interfaces with the declarations, but then your services. So I have a folder here services These will be files that will inherit. So we did something like that with the longer service where I had the contract with the declarations off the functions on then the service inherited from the contract. Andi actually put in the definitions for these functions. Right? So we're doing the same thing here we have I author repository, which is inheriting from the base on. Then what I'm going to do is go into services at a new class. Andi, This one will be author. Repository, click add Then I'm going to make the repository inherit from I bought Author Repository Right on. Then I went after include one The folder are using that name space on. Then I'm goingto have toe put in the definitions for other functions. So that's what that red line is. So if I hover, you will say implement interface and it will generate all off the method Stubbs relative toe what was defined. So you see, all of these are coming from B is because but inheriting I author Repository, I'm getting all off what is in the base. And then, if I had custom functions in here, then I would also have method Stubbs representing them in one place. No, I can perform a quick bill just to make sure that I'm not missing out anything. And it's always good to do builds after you make some court changes because you may have missed something along the way or it didn't do something properly on a build, will inform you off it on prevent you from going forward with glaring errors. Right? So the builder's successful and no, we're going to start implementing these functions. So to begin that what I need is an instance off my application db contact. So remember that application BB context and I just opened the file quickly. It has the definitions for Whole to connect to the database. It knows that these are the data classes that it should look toe on. It knows that the configurations, along with connection, string everything all of that is enveloped in this class. So what we need is an object off this class, which is our application db context inside of for Buster so that we can start interacting with the database. So I'm going to start off by defining property private read only on It's going to be off type application db context on. I'm going to call the objects name on the score. DB right? No, After doing that, I'm going to initialize it inside of the constructor. So I'm going to create a constructor. And to do that, I can read C t o r laptop and it generates a constructor. So that's a nice, sharp cut way off getting your constructor. So know that I'm a constructor. I'm going to tell it that it should take a parameter off type application. Db context on. I'm going to call the parameter db So one is underscore DB and one is just BD on. Then inside off this construct, I'm goingto initialize it on the score. B B is equal to DD, so this is what we call dependence injection, where you declare property on the new, initialize it in the constructor, and then you can use the object freely, anywhere in your application. Now I'm going to do the definitions are the right the functionality into each. My thoughts stop relative. The whole I define them are the order in which I defined them in the repository base, and there's a particulary someone to do it this week. So, actually, I'm going to start off with the save because that's the easiest one, right? So I want to do save and then we'll do from find all down to delete in that order. So let's start off with safe, so I want to find the save function on. Then what I'm going to do is remove that exception that is being throwing and then we're going to see var changes some bickering of variable calling it changes on, then I'm going to say underscore db So that's my objects that allows me to interact with the database are entity framework core which brokers all off the database operations on my behalf. So this is my object to talkto entity framework. Then I say dot and then I get a bunch of functions. So more often than not, you can look at the function. I kind of infer what it's supposed to do. So, like, add, I'm sure you can infer that ad would help uto add something to the database. You have updates, have deletes what we're going through them. So right now what we're looking to do is save. So we want to look for something that suggests safe, right? They have saved changes they have. See if changes a sink know the difference between the two is well, obviously one is asynchronous and one is not asynchronous. Save changes works. That's fine. But then because we're using a synchronous programming here, I'm going to you take advantage off entity frameworks. You're synchronous functions NC that that save changes a sink on, then open and close breeze. No, there are few things they need to note when it comes to asynchronous functions. One. Yes, we defined them to be tasks. But then you hover over this agency that it's Oh, I'm sorry. That's a different. Let me complete the court base and then explain the the whole It's interesting. So this is our bullion. So what it is supposed to do is return. If there were changes, meat are not. So if I submitted something to the database than entity framework, when it doesn't save changes, it should say that yes, there was a change home. Any records were changed or something like that, right? So if no records were changed, then that's from that's our problem, right? So I want to return to our falls. Was their problem or not? If there were records changed, then it's all good. So that would return true. So I'm just going to write return changes greater than zero. Right, So this is a nice and toe one line way off seeing check. If the changes was Britain and zero and then return the result off that No, I'm seeing on error here. So it is saying that I cannot, um, return basically this area, saying that it's I'm returning task into, um But something is in. So this area is not really clear. So that's what I'm explaining the synchronised into. So this error does not really tell you what the issue is. The issue is that when you make an asynchronous call, it is returning. And if you hover over this changes is task. It's remember we have task Bull here. It's returning task task int, but then for this operation toe happen, it needs an int. All right, so it's essentially saying that, you know, the data types don't much. So when we're making and a synchronous function call, you know, to get about the concrete type, as in to get back and into a not a task into, I will have to proceed it with the keyword await then that's another issue in itself because no is going to tell me that you can't do on how it without and a sink function. So then the suggestion here would be made the method a sink, which is introducing the keyword chasing after public and notice everything. No goes away. All of the errors now go away. So let me just some all of that up One. When you are a boat toe, define on asynchronous function. You have to say easing you give it the qualifier, of course, of public facing task and then to return type. And if it's void, then there would be no return types. It would just be task on. Then save will Save is a function name. So you need the keyword, a sink, the keyword task. If there's a data type involved, then you put it in the angle brackets. If not, then you don't. And then you have to make sure that you are actually going to be calling something that is a synchronous inside off that definition. Otherwise, you would be kind off obsolete tohave the a sink on the task. If you're not actually doing an asynchronous operation, right, whenever you're going to be making the function call, you have to proceed it with the keyword await. I noticed when I don't pick our it, eh, think automatic delegates highlighted so the two off them work well together. So if you don't have any asynchronous function cause in here, then you don't need an asynchronous function pretty much all right. No, the next one that we're going to work on is the find. All right, So you just go back to the base and make sure so we did save all right? No, we're going to look at find all so and find all. I want to return a list off authors. I want to return all the authors that are currently the database, so I'm going to declare a variable of our authors equal to on Then I went away. It's because I intend to use on asynchronous function right on the score db dot on by saying underscore d B that I have access to all off the data classes that would have been defined in the db context. So I have a date. A class called author on the properties called authors, Right, So that's a property. So db dot authors on just the double check again its authors, because that's what I called it here. That's the name of the property, the classes author. But the properties are third because the connection off authors All right, so I d be not authors dot on. I want at least some just fantasy to list he sink on, Then remember, if I'm going to await. Then I need to precede the task with the keyword a sink. All right, there we go. All air is gone. No, this area still here because it's saying it's the needs to return something, So I'm expecting it to return a list off. Author. So this is the list on then? I'm just going to see a return authors. So once this function gets called, it's going to return a list off objects off type author, Alright, Charities. The next one would be fined by I. D. So fired by I d will be pretty simple toe implement. It would be similar. So this one is expecting a parameter off i d. So I'm going to save our author because I'm expecting to find one author through this function on. Then I'm going to see a weight on the score db dot authors So looking the author stable on , then I want you to find he's synchronously on. Then I just need to pass in the i d are so the find you have find and find a sing pretty much what dysfunction does, is it, um, it looks in the database for or looks in that table for any element that has the primary key matching this. So we know that the Primerica is called idee. It will automatically know that. So we're expected to pass in on I devalue. That is supposed to be a primary key, and then it will find it on. Then this is expecting on object off type author. So we would have gotten on author records. We need to return. Author. There we go. All right, All right. So we're coming along nicely. Next up would be creates a little school, but toe a repository, find or create on. Then in this one, we would have gotten some entity off type authors. What we want to do is create a new author record using that data on It's pretty simple. So what would do is underscore db dot authors dots add. So have either, but then gets what We have had a sink. So we might as well use at a sink, right? So at a sink. And then I passed in the entity that is about to be added. All right, on then, if I do at a sing off course, I need a weight on. Then the final thing after you have. Don't this call? Oh, I have a wait and they think also it's a public a sink, So it's easy to forget that it's easy to write one and not remember the other. But I can assure you bizarre studio will always remind you that you need it on. Then the final thing here would be to return the bullion. So what happens that after you do this operation, you have to save changes? And I have ah, function dedicated to just calling save changes, which in effect, is actually are, um, on the synchronous function. So I need to return whatever value this would return. So the bullion that is expected is ah bullion relative. If changes were saved successfully are not so what I'm going to do, you just say return and then I'm calling on a sink function. So this time it's my facing function. I mean this asynchronous function. But once again, if you're calling an asynchronous function, you have to wait on that. I'm just going to call save right, so it's goingto do the entity. If the F core operation and that is going to call my function, await the results and then return it on. Then by the time it returns, it would be returning bullion on all sorts off. Wonderful thing. This is just one big nice ecosystem and it's really great to understand. All right, so next after creates, we have updates than delete. So let me just do update it. So be it is pretty much a straight forward, as adding, Except you have db you say underscore db dot authors But then there's no hope Bit a think. So it's really just that up a bit on. Then you're calling the entity that is being updated, um, or you're bossing the entity that should, you know, be up needed on. Then you're goingto do the CMC. If changes were, you return a wheat seve and then off course if I'm awaiting than I need a think serie essentially. If I did not declare this as a sink, then you wouldn't make sense. I have this as anything false. All right, so right, here's all the asynchronous operation is my own on then it is the same kind of dynamic for delete so much adjustment to copy this instead of typing it all out again on, go over to delete pasted, but instead off updating. I'm going to be removing so for delete, it's removed. Removed. Doesn't have on chasing function, easing version to it. So it's removed the entity on. Do you think toe elite the save operation on That's it. We would have concluded sitting off the base line Croat operations for our author table. Right. So from here we can create a new author we can remove on existing author. We can find all the authors or find a specific author. You can save all the changes off course which is required on we can also update on Author is data. All right, so that's it for sitting up. Our author Buster went through quite a bit, but we did some base work here that we won't need to repeat again because for any other repository that will be setting up, we already have the base so we won't have to redo the base every time. The all the differences would be that we need to go in and write the court specific toe that data class. That repository is being built for
17. Authors: Setup Controller: Hey, guys, welcome back in this video, we're going to be setting up our AP controller for our authors. Now, before we get started with setting that up, there are some. Or there's at least one more configuration that we need to carry out before we can successfully start setting up our control. And that is in the start up, not CS file. So when I got to start about CS, I'm going to be going down to the services section on. What I need to do is add to our start off the fact that we need a scoped instance off or repository. Right? So this is going to help us with our dependency injections. I'm going to say service is that ad scored. All right, on then you can always a steak. I look at what scoped means, but are how it's defined. But I had scoped. What I need to say is, I'm scoping the the author Repository, the eye author repository, Andi, the author repository, right? So the same thing that we did with the service six with the longer service except the longer service added single time. This time it's at scoped on. You also have had transient Now each version add sculpt, transient are singletons Each one has its own way off Working so far hours you scoped with my data operations I can include reading on what's the difference between each So on body doing with that? Um but body of knowledge. Right? Know So you can do that reading later on. But just do this ad sculpt. And there were Pasching I author Repository Onda, author Repository on If you need to include any missing name spaces then go ahead and do so . I know that it is in the startup file. I can know comfortably inject it as a dependency into any other class that will be used in the scope off this project. So the one that I am specifically referring to know is our controller. So we got our controller sport and we already have a home controller, which I was using as a test control. So if you want to remove it, you can I leave it there? It's our test one, so we can remove it later on when our application actually blossomed into something. So right now I'm just going to go ahead and right click and click Add controller on then. This time I want an empty controls. I don't want any controller with pre defined functions for me will be writing about each endpoint ourselves. Right, So a pair controller empty on, then click add Want to make sure that we give itto name so the name would be author authors . So authors controller, I think like odd. And when that operation is completed, we have our FBI controller we have or route, which is toe authors would be a p I slash authors. That's how you get to this controller. All right, now, while we're here will be doing some based configurations once again because we'll be building out all off the endpoints in separate up separate videos. But right now I just want to do so certain things so that we know exactly what this controller will do, and then we can preview it in the documentation. So one I want a summary someone to at a summary, I just wrote that Oh, quickly second positive video and copied. If you want our torture and summary, um, other things that I'm going to do or the next major thing that I'm going to do would be to inject the dependency off the author repository. So I need a private read only property off type I author repository. All right. And of course, if you need to include libraries, you go ahead and do that on. Then I'm going to call it author. Repository will underscore author Buster because, you know, that's that's just my naming convention for private properties. All right, so, uh, that is underscore, Author repository. And then I need a constructor. Remember, we have c tour on then that generous a constructor on. Then we passed in a parameter. Some just want to copy and paste that just move quickly. That's on the score. Andi Inside off our constructors, where we initialize the dependence is so as many dependence is as you might have, you might need more than one repositories represented in the CME controller. So you just add as many and make sure you put them in as parameters and then initialize them here. So it's underscore. Author repository is equal toe whatever value the application would pass in. So this is this is how dependence injection works. We would have defined our service and our contract we let the application know that the service on the contract are boned to each other. So whatever it sees this than it should know that it interacts with that based class on. Then inside a four controller, we can just pass it. We have our private object, but then it is getting initialized by whatever the starts off CS is passing over. That's pretty much dependency. Injection once again dot net core makes this very easy. Now, another thing that I want to define a boat or control. And this is really for documentation generation purposes. Once again, you want to make sure that your documentation is really good for whoever is going to consume your your a p I. So I'm going to show you one more. That notation that you can add to your controller on that is to tell the document that it produces response type on then. So response types basically refer toa the http cords so you have 200 for okay, 400 for butter. Question etcetera. On the different response types are status school. So we know that one started school that we're obviously going to return. He's going to be status 200 so I can say status codes because they gave us Ah, huge, you know. So we're stutter scores Dots on. Then from this Eelam, I can just see status 200. Okay, so that means that whenever somebody looks at the document for this, they will know that at least this response that can be returned. So let us just save our, you know, just build. Make sure we didn't break anything on then that's going to debug mode. And look at the documentation that is generated so far on the document is not reflecting our All right, OK? Yeah. So I mean, they've been backtrack a bit. So our documentation for our a p a controller for authors would not show up just yet because we don't have an end points for documentation. So Songer is ignoring it because there is literally nothing to documents. What? So when we start building on the FBI endpoints, then we will start seeing it appear in the documents. So that's basically it Ford sitting off the controller at its, you know, minimal level. The next operation would be to start sitting up or get endpoints, and then we'll start seeing the true beauty off or author controller come to life
18. Authors: Setup GET Endpoints: you guys. Welcome back in this video, we're going to start setting up our get endpoints for our author controller. No, I missed a step in the base configuration for the controllers where I should have included the longer service. So we're going to be logging. He'd step off the way, the interaction or the functionality off our AP and FBI, cause So what I'm going to do is introduce on mother Private Read only object on this one is going to be off type I longer service on, understand? To call it underscore longer on. Then I'm going to in the constructor at another parameter. I'll desperate the line so I don't go too far off, and it's going to be off type. I longer service. So I'm just introducing that dependency on. Then I'm just going to see the underscore longer is equal toe longer. All right, so now I have injected the longer service into the A p I controller on pretty much every other APEC controller. Well, at least if you intend to log what is going on, it would need to have this as a dependency also. All right, so let us get started. So I want Ah, on end point for getting all books. I know we're going to start looking at verbs. So I would have said there in the introduction that you do have a few verbs you have, get post put on and well, get postponed and delete. So the first thing that I want to do is let our control or north through the building and notations that I am went to define an http, get function. And that's literally all you have to type. Http. Get. All right. Next, I'm going to tell it that I want a public a sink task. Andi, I wanted off type I action result. So action results is the one if use if you're usedto M v c regular Web, NBC than you know, action results. I actually result is a little extension off option results meeting You have more that you can return. So option results. You could return so much. I know more. No. In my auction results, you can return even more, especially in the context off on FBI, where you'll be returning certain things. I wouldn't return in an NBC application, So task I action results on. I'm going to call this one. Get books. Sorry. Get authors. My bud. So are getting authors. This is the author controller. So we're getting authors hurt my back. So we're getting authors and then I'm just going to add a summary above this quickly. So this one I'm going to see get off authors. So I find it easier to just, you know, do the documentation he started on then, you know, refine it as you go along. But at least started when you are doing the thing does put it there so that you don't forget about it. So that is get all authors and it returns list off authors. All right, Aan den. What we need to define in here would be the functional that you want to invoke. So remember that we're not interacting with our data class directly were interacting is DT Also, the controller talks to the DEA to transfer objects Autumn Oper with my between the data transfer objects under author. So our repository is going to call the data object in the situation that we're going to mop it to the data transfer object on, then return the data transfer object to whoever is calling this a p I So let's look at how that's going toe work. So I start off by seeing bar authors is equal to on I'm calling an asynchronous function. As I say Await underscore Author reports story docked on to get all authors I have the function find all all right, now that I've gotten all authors, I need toe mop to my data transfer objects I went to see var Oh ther or will var that's the response is equal toe on dso That's another dependence that I'm going to need. So I would have included Autumn Oper in the in the startup dot CS file. So no, I can take this independence. So you see, as you go along, you're going to find that you need different dependence is on It's the same process. You just include an instance of it. So we're dealing with Ah, I mop er so just duplicated that line and I'm typing. I mop er and I'm going to call the object my per on. Then I'm going to do the same thing here where I'm going to introduce a comma and then introduce I'm upper to my list off parameters Andi assume backtrack Andi, change out. So I'm just doing this quickly. So copying and pasting is your friend who when you want to get things done quickly. But you can just include any missing, um, name space or using Autumn Oper. No, we have autumn upper injected into her application. We can just start using autumn upper. So when I want to mop, I would say underscore mop er not mop. All right, on then I'm going to say that I want to mop. So if you just look at the definition incident that dot maps is what is the destination you want a map toe on? What is the source? So I want TEM up toe a list off. Well, sir, theater transfer object. Our author detail is what we call it on. Then the source would be authors. All right, so I'm mopping my lip. My authors coming back from the database toe least off the data transfer object type. I remember that data transfer object Once again, I loves you to control what data you want. Are not so in other words, that this is a full record off the author. But what if we only wanted to send back some off the properties are the columns, some off the data and not all of the data. If I in my authored DT Oh said I left off the i d on. Maybe I didn't include the bio. I just wanted the first name and last name. If those were the only two properties that I had in the data transfer object, then this operation here I would say yes, I'm getting five properties, but I'm only taking all the tool that matter relative to the class on DSO. Whatever I returned to the caller would just be the properties that the data transfer object has defined. So that's what data transfer objects alloy to do. They allow you to control what data is really presented to the person who is calling the FBI relative to what is actually coming from the database. No. After I have made a database, skull mopped it. The next thing I would probably want to do is return, So I want to return the response. So there are built in functions for the response type. So if somebody made a call to get authors, then I would return the list off authors with our response cooled off. Okay. All right. So that's like a universal AP. I love which anybody building an application around an A P. I would know that when they see at 200 response, it's okay. So everything went well, So I would say, OK, because, well, that Nick or a P I gave me that building function on. I would say, Here is the payload with the smoky response. Right. So the pain would would be the march data or the list off authors so it returns. OK, then we get back. The the Lord. No, I want to boast that this a bit. So I want to add a bit off logging and a bit off exception handling too. So I always try to put in track catches. Right. So you try and operation, and then you catch any exception. So what I would do here is to try all of this. All right, on then. What I'll do is say you try this on return. Okay, on, then, if there's an exception, you want to catch it, so exception catch on, then you can True, But I prefer to maybe just reply so that it doesn't crash the application and see, um, return by request. Our rather I wouldn't return a butter question. Probably return something like so So butter questions 400 butter question would suggest that the caller or the client made up by the request to the server, which is not necessarily the kids because they only requested a list off authors. There's very little that they could do wrongly on and if it hit here and something went wrong with our operation and we don't want to tell them it was about a request, But we want to maybe suggest that something went wrong on all sides. So you have the function cause status scored, right, and then you can pass in the court. So this is where learning some of the numbers comes becomes important. So internal server error is 500. I think 501 is internal gate with There are something that s so the different numbers are there. I'm not saying you should memorize every number there. Certain numbers that you will be using over and over again on some off them are built in like OK and the bad request and those kind of things are built in, but, you know, it's good to know the numbers and hold toe, you know, maneuver around them. So I'm saying here that when you try to get all authors, if we do everything okay, you get the 200 response with the data associated with a call. If something goes wrong, however, I'm going to tell you Well, I'm just sending you about that 500 error to say something went wrong to see if there's on . There is even an override. So you can even give them, ah, message to save something So you can probably say something went wrong. Please contact the administrator. All right, so those are little things that you can add to your FBI to make it a little more personal than just you know, I robot responding to people. The next thing that I'm going to do is add some logging, so I want to love on dsi. Underscore longer dot In four, long in four on, then what? I want to log when the person makes ah car. So this is going to meet the call. So when it hits the tries going toe log and say this was attempted. So attempted, um, gets all authors, so there's no real form it. I mean, it's your long you're right, the messages you want. All right. You can even put in maybe a time stump. So I'm just going to use interpolation. Well, there's already a time stamp built into the log, actually. So I'm just saying attempted get all authors on then right before the okey response, I would say longer. That's log in four on. I would probably see success 40 God's off authors. So you know that that call was successful. All right, So you know, you can introduce those logging anywhere that you deem necessary. I'm just putting those there, for example, sake. You don't have to log every little line like that. Um, you can actually blow to love file. But then where it becomes very important for me would be in the in the tri on the catch in the church part. Sorry. So right before I returned that it was ah, on arrow. I would want to log for internal auditing purposes dot longer dot log. Terrible because it caught on exception it on then the details that I'm putting in this would be and I just used inter pollution here. Say, um e so he would be my exception object rent. So I want to log what the actual air awas ce that message on may be, but e not in the exception. So sometimes you have eat that message on. Then you have eat that inner exception with more details. So if there is ever an era, I want to see what that air awas, Andi maybe any other details necessary. And then we can tell them that it was an internal earl. It's after all that we can just do a quick build, making sure that everything is OK on. Once that has been successful, we can just go into debug more than see if our author FBI controller and there's no showing up in our documentation. And there we go. So we have authors no listed on. We see our a p. I call a p I slash authors and our summary get all authors on. Then we see here that well, the cord, it knows that is going to come back is 200 success. So we can further, um, informant that, you know, we would have the potential off 500 on other things. So the cool thing about slugger is that swagger. I lows you to test the a p a. Right here in the brochure. No Postman allows it to do certain things that soccer does not allow you to do, or it's more difficult to do it. Soldiers is good to have both tools on hand, so let's just test over a p a right know someone's going to trade vote on, then click executes. It says No Parliament is required. No problem. We execute on Dwell. There are no authors in our database, really. And truly so everything Well, it actually works. So the question where l was that it was our get operation on the response body was blank because there was no author in the database anyway. But we do see that our response called was 200. What I'm going to do is I went toe botch something in the definition for our database connections. And then I'm going to try and force off 500 air someone the type. I'm doing this. You can do it with me, But just make sure you corrected Philia Theron. Um But if you don't want to do it, no problem. You can just watch me. So I'm just changing the upsetting so that it feels on the database connection on I'm trying to force an intern out, um, server error. So let us go back into debug mode and try that again. This time amusing postman so attacked in the URL which would be the local host on the port number slash ap i slash authors. So I put that in the request on ditz. I get operation and I click send on its trying to go through. So now you see that it is giving me about the message. Something went wrong. Please contact the administrator on the status code is 500 to say internal server arrow. All right? No, the last thing I'm going to do is just look at the log real quickly, just to show you what that looks like on just taking a look at the log fire. You see where it said OK in for attempted to get all students or Sorry, all authors My bad. And then it was successful on. Then the second call went through. Attempted to get all authors on, then we're seeing the arrow where it is. No telling us a network related this that that that that on then it's well, this dot should have been for the inner Mrs. So this was the message on. Then I said, Dash, give me any inner message In the exception, there was none. But this would be enough for us to go off off internally. So you don't want to tell the users the details off why it failed necessarily. But you want to keep truck off, which caulfield on, then why? So this is a good way to know why. So that is, uh, these are just some good things to put into your to go and search for the path. Sorry to the log file, but let me just make sure I'm coming out of debug mode on by making sure to correct the APP settings file So I don't run into that problem again. Andi. So that is a good way, a good introduction to setting up our first endpoint. So that's get authors. The next one would be get author, which would be one author, so it's going to be pretty similar. It's also at http. Get so I'm just going toe. Copy this on. Then I'm going to see http. Get. But then this one I wanted let it know that this get requires parameter. So any time you have a parameter one or more parameters, you know, you can just write the parent to seize patina quotation marks, and then using current embraces, you indicate the parameter or the parameters. In this case, we're only have on idee how much? I just want to copy all off this. This function differently, son. Appear. Yeah, still, move a bit more quickly. Make sure you get may, um braces, credit braces card. So you can type it. Told you if you want. You don't have to. Copy and paste. Let me and trend do damage control. But then what I want to do is change this from get authors to get author. And then I also want to specify the parameter that is required. So I'm getting author, right. And I'm expecting a parameter of type I D on. I'm letting the A p I control. I know that this gets requires a parameter of type I d on. Then what? I'm going to be doing here is very similar soul. Um, let me just copy the logger slain, and I'm going to see longer info and tempted to get, and then he can be as deep Teyla's you want to get author with on. Then I'm going to say I d colon. Right? So I'm logging exactly what was attempted with the i d. And then I'm just going to specify the i d that came in through the parameter so attempted to get also with idee that right on then under that I'm going to save our author is equal to Ah, wait on the score. He'd not BB author, repository rights not find by i d And then I just passing the i d. All right, Then I'm going to see that my response will be serve ire response is equal to and then underscore my upper dots mop. And then this I'm a mop egg. A single instance off author. So the last time we did the least off author detailed this time just being a single instance off author DT or so mapping that to the author that was collected on. Then I went to respond. Sorry, I'm with the return okay with that response. All right. So of course you want to add logging here to see successfully got author with ideas. So successfully got author with Eddie. All right, so it's good to have nice detail log so that even somebody else can look at the logs and understand what was happening. But we're going to do a bit more in this operation. So once again, we have or try catch as always. So let me just got that try Top top generates that stub. So I'm going to try all off this. All right, So in the cat section, I would want to define the same lager and started scored message. But then I feel like I'm going to repeating myself because I'm going to do this are in other functions as well. So are other endpoints. What I'm going to do is create one function and I'm going to call it private, and it's going to be off type status school, the results. So the reason using status good results is that it's going to be returning this stuff to school, which is pretty much a status school result Data type Right on. I'm going to call this one internal era turn. No, Uh, and it's going to take ah, string parameter called message. Right? So the expectation here is that it will handle the logging on it will also, I returned the start of school that is required. So let me just say that firstly, I want the longer toe love on error because that's the only reason this function would get called on. The message is what is going to be loved, right? So went after. Make sure have a passing appropriate or a message each time into this car. Next, we're going to just return to stutter. Scored with the with the error. Onda. Andi, I'm getting an error here. Oh, art. So the data type is wrong. So it's saying that I should be returning on. Object is or not a status code results. So if it was just status scored, 500 would be started scored result. But because I have the additional information with it, it's an object result, right? So I mean, you don't have to, you know, worry about the different data types more often than not. If it does hover over whatever it is, you need to return, you'll see what kind off beat the type it is, and just make sure that you have the appropriate data type being represented. So when this function gets called, it's going toe. Love. Whatever messages being passed in, I'm just going to return 500. So that means I can just make this phone Sean call so I can just call interna error any time it gets to the exception. But then, remember, I need the message. So we need to do the same thing where I get the exception on. Then I'm just going to pass in a string values so using interpolation and want to build a string similar to what was put into the log air, some actually just going to take all off this on. I'm just going to pass it in as the message, right? So when we get to the catch way, hope we don't. But if we ever do, then it is going to call interna arrow, passing in the exception message on the inner exception on. Then, when he gets called, it's goingto do the appropriate logging and then return the start of scored, which would then be returned to the function right on then so I can actually just see return here. So I will be returning Internal Arrow right on. I can remove the throw. So once it gets there, it's just going to return whatever value this function called his attorney. So that means any time I hit the church section off, uh, call. I can just do this. One liner where just called internal second was replaced that in the previous one. Because I wanted to be consistent. I want everything to flow one way. Right. So the behavior for exceptions being caught should be the seam. You catch the exception on you just do a log on return to start a school at 500. Um, of course, if you want different messages, No. Then you mean need to look at, you know, finding it a bit. But ultimately for 500 I don't want to be more elaborate than something went wrong. Really. And truly right. Another thing that I want to do inside off my get author would be to check if I actually got back anything when I made this call. So I don't want to just return a 200. Okay. When there was nothing phone. Right? So I mean, I can return an empty list and say 200. Okay, but there was nothing phoned on. That's fine ride. Well, you know, Green off sought in this situation. I don't want you to search for I d with the, um sorry. Author with i d two and then not get the result would be getting a 200. Okay, so what I'm going to do here is I'm going to see if Author is no. Then I want to return. Uh, not phoned. All right, So not phone this four or four, right? You should be familiar with for four. When you click on something on the Internet on, then it leads it off for a four page and say, Hey, you probably ended up or you're searching for something that doesn't exist. That's a 404 So that's what I want. If you start for an author with i d 100 when there's no author with i d 100 or at least it wasn't phoned in the database, Then I want to log and see. It was not phone. So this return would stop the execution right? here so I could just add logging Logging in fort asi longer that log maybe warn Mr C Warne eso you can determine the degree off the, um the intensity are the danger off each lager operation, right? Someone to warn that author with i d Andi, Just use interpolation was not fallen. All right, so they searched on. It was not found. So little is just going to Deeble more than test this endpoint. All right, so swagger is showing us that we have a new endpoints that is off type get when I look, I see that it has a required parameter called I d. Right on dit is returning 200 success. So we'll go back and add more annotations for that. Well, let us just rattled in Horseman. All right, so in Postman, we're going to test this new in point so I can always consult the documentation to see what their question look like. It looked like slash ap slash authors slash on the i d value. Right? So what I'm going to do is say, slash ap slash author slash Once I have no authors in my database, so one should yield four or four on. Actually, I'm going to debug it with you. So what I'm going to do is come back to the controller. We're going to put a break point on. Then we'll step through just to see exactly what happens. It step off the way. So when I goto postman on guy hit, send it. It's my break point. So there we go. So no one were called in the right in point, and that's always a happy moment. If I check, I d. We see that the value one is being passed in on what used F 11 to step through. So it's going to try the operation. Firstly, logs on, then yes, it's going to go into all off that on. Then it's going to try and find, said author. So I'm actually just going to skip this time because it's going to go through some other cause. So I'm just going to use this little play button to skip to the next line on. Then you see, that author is indeed no. So it did not get an author from the database with I D one on, so it will go down into our, um section where it should love with the warning that it was not phoned. Yes, and it will do that on. Then it will return, not phoned on, then pressing if I've continues the execution. So when I look back in post man, you'll see the status for four not phoned being returned. All right, so that is so we can control the expectations on the interactions with their A p. I threw status, scored updates. So just still. Well, I didn't say at at a summer to this one, so we just had a summary on going to say Get on. Author by I d onda parameter parameter name is idea can leave that alone and returns on. Author is required. All right, so no over a p a documentation will have a bit more information on that. No. Another thing that I'm going to do is at these produces response type annotations to the different, um, endpoint. So this endpoint is capable of returning on okay? Or a 500 someone to say underneath to get that it does OK, but it also does the status 500 status. 500 internal server error. Right on that. I'm going to do the same thing for this one, which also does the okay. It also does the internal arrow, but it is also capable off doing a status 404 So it's that does for all four not phoned. Alright, and then we'll take one more look at the documentation just to see what differences those meat. All right, so our documentation is including our summary. When I don't in the get offers, I see that it is not aware that the 200 success or 500 server arrow there quite possible. And if I look in the one with the i d. I see that I could get a success off for four and a 44 has its own payload, which would have seen in the response where it's telling us the type, the title, the status, the true societies, I guess off that is being returned when we call that not phone function on DSO. Our documentation is making representation off the fact that that's what a four or four can have in it, right? So I guess we can fill out those details with our cost, um, content if we need it to the same way we could send over a custom message with our five country, so that's pretty much it for sitting apart, Get and points. Next will be configuring or create in point so that the next time we test to get, then we should be able to validate that data is really being retrieved from the database.
19. Authors: Setup CREATE Endpoint: Welcome back in this. Listen, we're going to be setting up the create endpoint for our authors, FBI controller. So we start this exercise off by writing on a new asynchronous task off type I action result on. Then we're going to call this one. Create on it is going to be expecting a parameter I'm going to see this uses annotation that is from body, right? So that means when the person or the client is making a call to this end points, they're expected to pass in our body with some content. Now, this is where the data transfer objects will definitely come into play because right now we only have author detail, which is accepting idee. First name, last name bio. Andi, I list for books. Essentially, when you're creating an author, one you don't need to provide an i d. On D wouldn't expect them to provide the list off books. Right? So what I'm going to do is I'm going to create a new class, and I'll just use the same author, DT or class, But the author detail class file, rather. But I'm going to create a new class in there somewhere to see public. Plus on. Then I'm going to call this one author. Sorry, author. Create e T o. All right on, then. Inside off this author create GTO. I'm going tohave definitions for those first name, last name on bio. So that's all that I want anybody to be able to provide to me for the creation often. Author. All right, So they expected data once again to create the also would be defined and also create DT Owen. And from here, I can put in, um, certain I know to shun Second, make its required. Um, let me just put that four bullets first name and last name the bio I'll me optional. So after include some libraries to get those annotations. I can also put in different annotations, like for the data type and the max length. And so I won't, you know, enforce all of those. But I'm just making sure that I'm letting them know that at least these two are required on then the bio is this so? All right, So by defining this author create GTO going back to my control, which I left very incomplete, I will know. Say that the parameter that I'm expecting from body should look something like the author create DT. Also, if they don't put anything else, they need to make sure that they have at least first name, last name and bio on that. I'm further enforcing that first name and last name are required. So we went back to the controller. All right, so then we start defining what exactly or create Should do. No, I'm going to make a series of checks off course. First day I'm going to just do my try. Catch on the inside off the catch. I'll just returned. Internal server arrow would in turn on error. Um, a function called Sorry, Andi put my exceptions. I'm just doing that because that's the easiest thing to do on a on to make sure I don't forget it. Right. So I have that. I know what I'm going to do. We see if the object which is Oh, well, sorry I put in the class and by doing put in there the name. Sorry. So from body, I'm expecting on author, object off type author creates detail someone to say if author is no. So that means they tried to submit a request But there was no author data or no expected data provided that I'm just going to return. Ah, but request. That was about a request on your part. All right, on then, there's this object or this property that I can call called Model State, which is basically tracking the validation status off the data. Right. So remember that we just put in some validation to say certain things are required, and so on Model state is basically tracking anything that is happening across the data values. So pretty much is good practice toe, make all the checks before you go on to transform it later. Because the fact is that you want to make sure that by the time you're calling the database toe put something into the database that everything is in order. So I'm checking if it is, Know that I'm telling you that's just about request. I won't go any further. Um, if it was a case where you only wanted authors with you need names are ever record. Should have something unique that you check for uniqueness on. Then you return appropriating. So right now this is only that I'm making on. Then I can't even put in. Ah, love. So just so with these statements, if you have one land, you don't need the parent theses. But once you have more than one, you need parentheses are just copy the log. Uh, well, let me just say on the score. Longer worn love. No, not born on. I'm just going to see that. I'm just going to see that the empty request was submitted, All right. And then off course, I can put in another logger. I start to see off the submission. Attempted author submission attempted. So we know. And then this one would have been an info. All right, so we're informing everybody that somebody attempted to create an author. If the bay load was no, then we're just warning to see Intercoastal submitted, and then we're returning that there was a bad request right on. I can probably put in the model. Stayed. Well, let me nuts complicate this. Any more than authority used to be. So that's just some information. So we can move on with this on then we can say check the model states. Remember that the model here model state is pretty much, um, tired toe Whatever validations would have imposed on our DT. Oh, right. So our DT always saying that these two are required someone to say, If not so. I like to do the bad checks first, right? So always check to see if everything is not in order. And if it is not in order than I don't proceed. If not model states, that is valid. So that means if there's anything ah, boats, the data being submitted that doesn't meets the validation criteria and that we settled then I am going to also return by request. Right? But then I would change the longer miss it slightly to see. Um, you know it. Waas incomplete. Our author data was incomplete. All right. Another cool way to do this would be instead of seeing author every time you just say, let a controller name and their escort that allows you to just get the control and the relative to where the court is being written. So instead, I was trying to say, author, every time, author, every time you could just see the controller name, which is offers and then see the messages, at least in the log, it's easier to tell. Were or which controller that more generic message is associated with our any hole. There are so many ways to do this thing that if I was to try and put all the that things off course, we would never end. So, you know, we can just go ahead and learn and grow as we move along. No, After I've gotten my butt checks out off the way. If it gets beyond these two checks than something must be right, right? So I'm going to say var author or what kind of reuse Author var. Let's see, Record is equal to on then are you know what I'm going to Don't want to say Author D T o. So you know that this is the GTO coming in from the parameter that I'm going to save our author. All right, so I'm just trying to knee my variable so that anybody can look at the court and, you know, easily associate, um, variables with where they belong So far, Author is going to be equal toe my ma per having mopped. Um And then I went to see I want TEM up toe the data class author. This time on, I want him up. Whatever data is coming in through author E T O. On that, I'm wins after include some things I can get the author data class involved on. So what this is doing is the opposite direction, or so I'm getting the detail from the client with the data on. Then I'm going to say OK, my upper. I want you to take whatever data was included here, which would involve the first name, the last name and bio. And then I want you to just mop it over to the data class which has everything else anyway , right? So if there's something missing, it will get insert. It will get inserted later on. Or at least we can control that one. Right? So at minimum, once this is mopped, at least the first name and last name often author should be mopped. If our bio is present that it will be marked if it's not present than it's well, you know, it's no consequence that we didn't make it require No having done the mapping, I am going toe try and save changes. So I'm going to say var is success is equal toe away. It the call to my author. Eople author of Bus story dot Create right on the resulting virus successes that remember that this is going to return a Boolean. What? It's successful or not? What it seemed successfully or not on then the create is expecting an entity off type author, which I just got having done the mapping. So I'm going to pass that in on. Then after doing that, we're going to see if not his success, meaning if that was not a successful operation than I'll probably want to log on DSI. I just love quickly and say author creation, Field on. Then I would call my internal servant girl function right, So I would just return this. So I mean, there are so many ways to do this read on, then provided that everything else is old t. So that means if this was successful, Sorry. So internal air of the message would be I'm sorry. I'm mixing, mixing, getting out of myself. What I'll do here is actually passed in this message as the internal server Arrow rights. Okay, so I will pass an author creation field as the message. So that's what we'll get logged. My bod on. Then the user will just get the something went wrong. Piece contact administrator with a status cooled off 500. So if this was attempted and it was not successful, then they will get 500. So, you know, I'm differentiating between bad requests and 500 because once again, but request means that clients didn't do something right on the 500 means that our side fails. So they did everything right, and he got up to this point, and it failed. So it either field here or teachers unexceptional and field. Either we we need to tell them that something field, which is a 500 arrow. However, at the end, off all off this provided that none off these fire parts get hit or these. If statements get hit, then we can safely assume that the return that we created it successfully so I can return. Uh, starts cooled off. Create Ted, which I believe is a two hole one. Yeah. So 200 is okay. It'll one is an okay, Andi, something right? So created It would be saying, Yemen you created something on everything is all right and so will pass in here And if we're over, we see that it's expecting a string. You're on some object value. So what I can return here would be, ah, you know, create Ted and then would see create on, then passing a new object with the data coming back from author, right? So once we would have created also successfully, this entity will actually automatically update with the new I d. For instance, on whatever did I probably would have sit after the submission, So that's just going to return the details off what was created. And then I can include I longer here, uh, Oliver dot in full to see. Also created successfully. They're created author our Let's just leave that offer creating. All right, so lets us stay this for a spin. We did quite a bit off work and then off course. Want to test each scenario to make sure that they're working as we expect before I move forward, though I did neglect to put on a notation. So let me say this is an http post. All right? So once we do a post respond or post request, they will know that it should hit this function by this action. Rather, I'm also going to let it know the different response types that we produce. So we don't produce. Okay, But we do produce tool one created right, So this one will let you know it was created. It will not do a 404 but it was a bad requests, So stock does for 100 is bad requests. All right, on then. Off course you do. Also let them know when they in turn us arrow occurred. All right, on this thus, but not leave Started to put my summary. So this is the biggest being for most programmers remembering to put the summer so this would be creates on author on then The Param name is author DT. Oh, so I'll just stay here. Well, I can actually leave that alone, and I don't need to specify anything that's being returned. So let us going to debunk more than take it for a spin. All right? So documentation is up and running, we see or post there is an example of what is expected. Right? So remember that we use the DT Oh, we didn't use the full author object. And so the detail that we use was first name, last name. And by those are the only required, um, bits off data that we should passed in. And it's telling us that it should be in the request body. All right, so let us test that with postman. So I went and created a new tub, and then I put in the end points, which is local host school on board slash ap slash authors. But we have, ah, bit afford to do here. So one we're not doing, I get, but we're doing a post. So we have to change this call to post. All right, on then in the body. We need to specify some data, so I'm goingto Well, you have for me it a of your elin coded data. A variety of binary of graph quells que el So I'm going to do rock on. Then I went to change this from text to Jason. All right, so I'm passing in a pillow that looks like this, and this is in a data type are ah, former thing type called Jason. Right. So Jason is like a standard when it comes to the sending and retrieving data, and it is at least rent No on. It is really cool. It seized. Understand? So I'm just going to copy this sample from the documentation on in Postman Paste it on. Then for the first name value I'm going to put let me put my name for the last name value. I'll put my name also on that. I'm going to pass a blank bio. Not expectation. Here is that once I hit send, it's going toe call that end point. So what I'm going to do is go back to over, um cold and I'm going to set a break point on the creates. Right? So once I do that, I'm going to know Hit, send, and it it's our break point. So Well, happy day Right on then. If I hover over the GTO, then I will see that bios blank. But first name and last name are indeed present. All right, so I'm sure if I just continue, then it would be successful. So images press f five and continue through the execution. Andi, check postman to see what the response. Waas and I was wrong. I'm actually getting a 500 in turn on earth. So something went wrong along the way. You know, instead of going through and stepping, I can distract my lock on here in my log I'm seeing what is being said. So it says that the arrow is missing. Mop configuration are unsupported. Mopping. Yes, I completely understand what that is. A boat. So let me just exit b boat moored and fix that. So what happened is that we introduced a new DT Oh, in the form of author create GTO on. I'm trying to mop it. But guess what I didn't do. I didn't tell autumn upper to know a boat that mapping so back in the mops. I need to specify that there is I'm mopping that exists between author and author. Create de deal. All right, so you see Ah, very simple arrow, because off a missing configuration. But it's always good. That's one of the benefits off the logs because, you know, would have spent time Trento, step through a Philippine each land to see where it went wrong and tried to see the exception. But the longer just telling you, this is why it failed. So the user is just seeing that something failed. Please contact the administrator they call you are the love a ticket with your company and then you can go into the log and investigate exactly what happened. All right, so let's try that again. Let's go back into the boat moored on test or a P I again. So I'm going to try and submit the same data with Postman. So this is why postman is so handy because it saves your sessions. It saves your tests and you can always just school back and click. Send on. Then let us see if it goes through. So it it's my break point, and I'm just going to press a fire for it to continue on. Then let me revisit postman on. There we go. So I'm getting back. I start us toward one to see it was successfully created on It is also returning all off the details off the newly created author. So I d This is the i d got, um, the first in the last name. And well, there was no bias. Let me try somebody else. So on a key Ah Evans Andi, She is intelligent. That's our bio on. Then let me click. Send on. I'm just removing the break point so that, you know, we don't have to hitch their every time. And then there is an a K. Evans with her bio. So the thing about the required no would be that if I failed to submit one off these required fields. So let me take over first and first Emma Lawson were acquired. I'm taking the first name on going to set the break point here. Just toe make sure. So this time I want a break point on that I'm going to click send. Well, it didn't even hit the break point. He just told me that it's a 400 bad request on Barroso. Model state errors would be included to say the first name field is required. So that is the power off these responses. So if you really didn't even hit the break point, just know are maybe I mis timed setting a break point and submitting, but it probably hits this one. The model state is not valid. Author data was incomplete on. Then it returned a butter quest telling you the model state on with the one more test where I'm going to call it, but with no data whatsoever. So when I hit, send is just going to give me Oh well, it's giving an unsupported media type. So that's a default response. No, because there is no post ah method in my a p I. That does not take anything in the body. So really and truly it should not have. Well, if if your request does not much anything inside the FBI, then you will get a for on five to see. You know, it's an invited caught. That's just that default response. Ondas a city Erekat honestly tell you, ho, I would simulate this one for checking if it's small, but that's just the way it is, right? So the foreign five would even intercepted before it attempts to call this create. So that's it for setting up our create in point on, we have logging. We have appropriate responses and validation. Um, errors along the way we set up a new detail on when we get back will be setting up the update and point
20. Authors: Setup UPDATE Endpoint: Hey, guys, Welcome back in this lesson. We're going to be setting off the up eight endpoint for our authors, a P I controller. So I'm going to kind off expedite this stone and just copy some of what exists already. Onda just paste. And then we'll be doing edits as we go along. All right, so? So if my indentation went out off work, just fix it, All right? So I just copied in peace that the create, But then I'm going to make a few changes. So this is going to be opiates on author on, then the petition for this is to be http, put All right, So when you talk about puts, that's all you up a bit. I guess it means they're putting in. You did. I don't know why they call it puts, but let's just work with it on Dwell. We can modify the status. Scores later alone's are finished, but this one is going to be up it. And by no, I'm sure you probably realize that it almost does not entirely matter what you call the action because we're not calling the actions by their name in Postman. It's really the method on the parameters that we passed that determine which function should be caught. So if two functions look too much alike, like you may have to create formations in the same a pair control and I think the same parameters. What? They have different names. These are studio may not give you an error, because in tactical, it's correct. But in the way AP eyes work or at least rest, Felipe has work. It would probably cause a problem because the payloads are the data being sent look too much alike. So I can tell which poor star which get function it should call. All right, so the names here really matter less than the fact that you're putting the cart annotation Andi, or line in the car parameters. Unexpected builds. So for our update in points, I'm going toe put in on idee parameters. So the expectations that they're going to call, um, put the endpoint Sorry, the a p i B s euro slash um, the I D. On d. We're expecting our body off data. So a lot of times you see that people use the create detail and it sometimes call it and edit or they call it absurd, which means update on inserting one, because usually the creator and it's look very similar. You don't allow them to edit the same things that you don't allow them to create, right? But then the point is that if we needed to differentiate, like, for instance, one also, if you want that person to be able to edit the bio but not the first name and last name, then we would be able to specify a new detail with all the properties that were expecting Data four and would be accepting. These are for in this case, I'm just going to use the continues in the create because it serves a double purpose. But then the naming can be dangerous because, you know you want to be explicit. But in this situation, I leave it alone. So also create detail and I'm seeing I'm expecting something off author detail. No, you did see in the documentation that it's an author detail. I don't necessarily want to say author d t o to whoever is reading documentations. If I changed that here on, I just say Param name is author, even though it mean miss much and it's going to warn me that Hey, you know, it doesn't auto much, but that is what I want it to say in the documentation. Right? So passing an author on I want first name, last name and on the bio. Alright on then. Once again, if we find this warning annoying, we can just look at the warning court, which is 15 73. Yeah, 15. 73 on. Then we can go ahead on and, um, take it all our suppress it in our properties. No, inside off our action body, we have or usual, try catch. And in our catch, we're going to just return over internal error function. Call exception with the e object. So let's start off with our chicks some with the first check and see if if I d is, that's less than one, meaning that that value doesn't make sense. Or if author bto is equivalent to know right? Then I want to return Bud request. All right. On, then. So bad request. If you look at the overlords, you see that they will allow you to pass in the model state. All right, so that's a mother stating that we talked a boat will also be able to pass in on error so we can pass in a custom, um, object. Or we can look for an appropriate object that gives us all off the arrow points that we want. All right, so I'm returning bad requests. If the payload is no, or this I devalue doesn't make sense. We can also check again to see if the model state docked is valued. So we're checking if it is not valid. So if not more, the state is valid. Then I'm going to return also bad requests. But this time I'm passing in the model state. Right? I'm going to leave the logging for last. I'm just walking through all of the major functions. All right, So, making after making these two checks, I can probably safely assume that everything is OK. Someone to proceed and save our is. Success is equal to await the results off. My author posit Torrey as he calls the updates, but then I made a missing a big step here where I need an object off type author. So we're getting the detail we need to mop. I didn't I miss that step, So that's fine so far. Authors equal to on the score My upper docked mop right? And I'm upping to author on the source is what Avery swimming in through authored e T o. All right, So I check what's bad if anything's about return. We don't want to start to hit the operations with bad data. So we check body. It's our return. Stop the execution quickly if anything is wrong but And if we get this fire, want toe, do the mapping, try and submitted database and then we say, if not, is so excess then we know that we had on internal error as best as we can guess. That's all that only an internal error would cause it to not work on. Then we proceed to say return. So if he gets this fire, then we want to return no contents, right? So no content is Ah, it sounds by, but it's actually a good response Scored good in the sense that no content means that you didn't have any errors But I don't have anything to show it. So 200 is okay on you get back. A result if there is data but in no content is saying? Well, it was okay, but based on the request, that will have anything to show it. But I didn't request anything off me. Right? So that's what no content needs. So, no, I just need to refine this a bit. So the internal error here would be upbeat. Operation son field. All right, on going to start putting in some logging. So understand, Tow bar the logger in full line here on that, I'm going to see author Hope Deeds tempted, um, and then put in i d value being the permits are I d. And then I will just put in my interpretation here. All right, so I did some logging. You can pause the video and right off the logging, if you want to, you know, follow the logging that I have. If you don't, then that's fine. I'm going to also regenerate this summary because the summer is only making representation for the author parameter. But I also put in I decide this region ery that. And so you see Author Onda the detail. So what happens know is that I just noticed that we are definitely going to get an era when we attempt this on. That is because I'm still using the create detail. So what happens with the create detail is that let me just go back. We did not include an I D. Right. So in order to create, we don't need an I D. But in order in tow update, we do need an I d. Because and two different work or needs the i d in the entity. Right to know what entity should target on change their properties off. So, um, I did say we could continue with the create detail, but clearly I was wrong. So let's just create the ability to on the obviate detail is probably going to look more like author details on the Skopje author detail. Well, don't hear based on them, which is called its author off bit DT Oh, but I don't need that list off books. Right. So the updates details and have the i d off the entity being changed. The first and the last name on the bios. Everything there on then I need but my annotations to state what is absolutely required for the updates De too, right? No, we went back to my comptroller one. I'm going to change all the parameter from offer. Created the author update detail Right on. I'm also going to add another check here where I'm going to see while our detective the i d value is less than 10 r. If the the other detail object is no, But I'm going to put in one more statement to say, or if the I d is not equal to author DT owes I devalue. So these two values should not miss much. I can't be passing in the value five here, but passing in data for also with i d six. That doesn't make any sense. Right? So whatever ideas here should much the idea being passed in in the body for the author. All right, so let's put this one to the test, So I'm just going to go ahead. I'm going to devote more. We're going to test with postman. All right, so we're seeing here that we have the endpoint being represented, so it is that it requires a perimeter I d on. We also expect the payload tow. Have I d first name, last name and bio as the properties. We also see the different return types which are goingto refined because they don't have that many returns. Us. You definitely don't have success. 200 or 201. All right, So what lets us validate first before we go on me? Those changes. So I'm going to go into a postman, have a new top. I'm going to change it from the get toh put. All right on, then I'm going to see author with idee one because I know I have an author with i d one, but then I need to make sure I have the payload. So let me test this one first, so I can assure you, this one is just going to give me that for 15 I believe so. I actually got a four or five this time. So seeing method, not a load. All right, so it seemed that I put in something like, I get request, but I'm calling the put because I put expects that there is a parameter as well as body. So four or five. That's an auto response saying that you know your request on the verb Don't much. That's fine. So I go with the body, choose raw go down to J Asan on, then I'm with the pope post in the sample, so have to put idee with the value one on. Then I want to update that, um, author to be Alia on the last name would be Stewart on for the bio. Um, let us say that I'm going toe put in. She is awesome at writing books. All right, that's simple bile. So when I click, send here and I'm going to put our break points inside off visual studio to make sure that we're hitting the right end point. So when I click send, I'm getting a four or five. It's seeing method, not Telesis saying, Oh, I see what the problem is. Okay. Ah, let's go back to visual studio and make a quick call Change somewhat exit debug mode on this court. Change is really just a matter off having the cart on a TV show, right? So what I need to see is that this put while while I have it defined that you know, we want the perimeter here the way you're going to have to pass an apartment or would be first. So what I want is the same kind off. Um, call where they just said slash ap slash authors slash the i d. Right. So without specifying this part to it. So that's all we did for the get I didn't do it for the put. So without doing it for the ports would after passing the i d. Parameter using a different method than in the actual um, you are. L like that. So what I'm going to do here is similar to what we did for the not similar. It replicates what we did for the get Onda lets the put nor that its expecting on I d parameter in the URL. All right, while I'm here, let me just change the status sports. So I'm going to say that it is status to allow four no contents. Whoa! 24 Anakin, dis press control space and it will auto. Complete that for me. All right, so let us try that again on validate over orbits. All right, so let's try this again with postman. So I have the same request here on the FBI authors One on this is the payload. So when I click send, it hits our break points. You know, we know that we're sending the requests properly. All right, So when I hover over idea C I d. One if I hover over author DT over on I Look, I see the data coming in and the ideas much. So once again, we have some validations to say if the ideas don't much right, then returned. But request As far as I'm concerned, they will. Much of this would not get Mets. Nothing is no on i d is. Well, indeed and in fact, not less than one. The model state is valid, I believe, because I feel about all of the required data. So that would not get hit on then the mapping. So if anything would probably get an exception because we missed some validation. And I do think we're going to hit the exception because we didn't have the mapping. All right, so I'm just going to press f five and then we're going to just look in postman for that 500 . There we go. So we did not do the mopping. I don't You need to check the log to see what happened, but I will go back to the mapping file which is in map ings and maps that CS on their we have author created GTOs. I'm just going to duplicate that NC author. Oh, it's DDO, all right, this is just about to do it one more time and then we're home free. All right, so I just submitted the request again and we're getting the response to a four. No content to show that our some updates. Operation was indeed successful, So I'm just going to go back to one off the older requests where I said get all authors and I'm going to send again on then this time because I have at least two authors in the database I'm going to see author with I d one. That's the one I just updated. She's also writing books, say, See no only stuff books So I can control that off course, because if you want the author, I mean not want to return all the books right with just the author. So by modifying the detail and taking on the list of books, I can date that out. All right, where we're seeing the two authors if I go back to the get with the i D removal, got a four or four initially. So I'm just going to click send and get back author with I d one and we see the return. Baylor Stewart. She's also are writing books. Andi. No books yet in the system and we know how to submit on. No, we know how toe update. So the final one would be hotel delete, so stick around, that's
21. Authors: Setup DELETE Endpoint: Hey, guys, Welcome back in this video will be setting up the delete functionality for authors. Controller Onda. Well, already took the liberty off, filling out some off the things before so you can pause the video and replicate what I have there. But I will be continuing. So underneath our delete, what we want to do is accept a permit, er of type I d on. Then proceed to try and delete this record. So let us start off with our bad checks. First, they want to make sure that the I devalue makes sense someone to see if the I d value is less than one, then return by request. All right, then I'm going to go ahead and see if are Well, what I'm going to do know is try and find the record with this. I d someone to save. Our author is equal toe on that. I'm just going to use my author of positive Torrey Docked. Find by I d on that, I'm going to pass in the I D off horses, anything. Someone to allow it. All right, so then no. After atom to retrieve that author, I need to check those this author really exist on? The way to do that is to say, if author is equivalent enough. So something came back, it won't be No. So if it is no, Then I'm just going to return, not phone. So you're trying to delete somebody are some record and it was not phoned in the database, So I'm just returning that that was not phoned. All right, so if it didn't stop there, however, I will continue on. I will see that I want to check the success. Someone to save. Our is suc cess is equal to await. Author, You pull darts the leads on. Then I want to give it the author toe delete then if not his success. All right, so of course we want to make sure that all the avenues are covered, which is there s so many of statements and chicks. So I'm just saying, if that was not successful, that I went to return my internal error on then if after everything else, I'm just going to return no content because I don't have anything to show you at the point when you deleted something. So if we got on a no content response you know that Alicia was successful, All right. And then you just modify this silly if not success than author the needs field. All right, so what I'm going to do know is just add the logging on, then we can test. All right? So I I did some logs, some logging lines. You can pause and take the most if you want to replicate minority and put years in. But now we're just going to test and validate or deletion operation. All right, so we're up in debug mode of a postman. I started a new top. The verb amusing is delete. Right. And you see that I kind of color called the different verbs. I think that's very helpful on. Then I'm going to attempt to delete the author with the I d. One. All right. So let me just click send, and it is telling me no content. So that would suggest that something went right. So we just go back to my get response and it still has some of the old data certainly click Send again on DSO I'm only getting back the author with the i d to on if I get author with idea One which is what we just deleted. It should give me a 404 Not phoned. There we go on. Well, we can still recreate on author if we want. Because I didn't close any off these tubs or for previous requests on then. Obviously, if I had tried toe update on author. That doesn't exist. Let's see what we get here on. That's Ah, 500 in turnout server, Earl. So I don't think that one is very intuitive. So we can double back on clean that up. Because if I tried toe opiates an author that doesn't exist, it shouldn't be telling me an internet. Several areas should be telling me not phoned, Right? So I'm just going to come out off e book Mood on Just made that change. So this video is about deleting, but we just went through all of them out, saw gaps, understood to correct it right now. So, in order to facilitate that, though, I would have to put in an extra car. So what I want to do is do the find. I'm going to just copy all of this right here. So this is where I'm finding the author by I d on. Then. If it's not phoned, I'm going to give the arrow. I didn't have that check in here. I'm on the checking of the I d. Value is valid aan den checking. If the smaller state is valid and anything, anything short off, that would be an internal server, Earl. Right, Which is not necessarily accurate. So instead of telling the user those an internal server arrow, I'm going to do that. Check here where I'm with to try and retrieve that author on. Then I went to check if it was no or not. Right on, then forward. No, I'm seeing that I have a little issue here. So what I'm going to do, you see? All right. So instead, off me using the find by i d I don't see any toe have ah mother function. So what I'll do is inside off my repositories. So this is the why the repository so cools inside off. My author posits very outside off the base formations entirely find. Or rather, I could actually added to the base because it could come in handy with the other ones. I'm going toe do another function here I'm just going to duplicate the create, but I'm going to call. It is exists. So this one is just going to take I'm i d so in idea on going to pass in the idea, and then it's going to tell me yes or no. Does this record exist? Right. So because I defined it in the base, I'm going to have to go back to the concrete class. Updated, implemented, missing function, which is his exists. And extra little. I find it here it is on then in his exists what I'm going to do you say something like return. Um, underscore db dot Um any Is there any a sink? Let me see if there is any a sink. So there's no any a sink. All right. I'm sure there's an any a sink. Um oh, sorry. Bebe Authors, my bar. Not any you sink. There we go. All right. So what I want to do is find out if there is any an urgency, a wheat, andi think in the function on. So I want to find out if there is any author. So I'm saying it's a basically without their stable check. If there is any with the Lambda expressions. So glum expressions. Good to see if there's any record with an I D. That much is I d being passed in, right? So this is just going to return to our flaws, that's all that any does. It says, true or false. So it's either there are, it's not there. So know that I have dis returning to our falls. I'm just save my changes in the controller back inside off the update. What I'm going to do is saying, um his exists so far is exists on I'm going to say instead if I, um author, report check his exists. So after causes exists, then I'm going to see if not, he's exit. So remember, this is a bullion so sure force. If if it is false, then I want to just return, not phoned right on. So I could actually just reuse this in the delete instead off, go ahead and finding the whole file so I'll just check his exists first. Andi, I can remove this, and then I can replace that line where I find the author right above the actual delete someone to retrieve the author here and then carry out the delete, then validated that it was successful or not on Warren accordingly. So that was a little You're factoring, and as you go along, maybe you'll see other gaps. Maybe you'll see all the ways you can make your court a bit more efficient. But that's what development is. You're always going to see things that you can introduce along the way.
22. Review and Add Changes to GitHub: our guy. So we've gotten to the end off this section off. Or course where we just successfully set up or a P I controller for our author manipulations. Right. So let's just review what we did. We set up some data, new data transfer objects we set up mopping for them. We would have injected the dependency for author repository for the longer service on for the mop er off course, you set up the repository toe, interact with our data bees on DSO. We'll be handing all databases related operations through our repository. The longer toe keep logs off every action going on in the in the a p a n points on our mop er toe handle. You know, transferring data between the data transfer object on the actual data class objects we would have successfully implemented functions or endpoints toe. Get all the authors. Teoh, get one Author by i d toe, create a new author toe update on existing author and toe delete on author. We also set up some you know, basic generic stuff so that we don't repeat ourselves all the time on we made use off or logging every step off the week, we also reviewed some debugging techniques on DSO. What we're going to do right now is toe check in our changes to get hope. So we need only right click or solution on, then go to commit. We give our commit message so that is money can pause the video and replicate it if you wish. But I will go ahead and commit all on the sink. You will save all the changes along the way on that will push our new court based off to get help. That's it for this sex on. See you next time.
23. Books: Setup Repository and Service: you guys, welcome back in this lesson, we're going to be sitting up or posit Torrey and service for Cincinnati for our book table . So I have opened the repository base and we use this base when we hunt, figured our author repositories or goingto basically follow suit and start implementing our book repositories. So in my contracts water, I'm going to add a new well, class, but interferes really on. I want to call it iBook repository. All right. No one's again. This is an interface. So I just changed that to interface. Andi, I'm going to make it inherits the repository beast. So we just threaten repository base and the class type in this situation is book on. Then it's going toe. Want me to include a library? And that's included. So that spines remember that this extension interfaces if we need to write custom functionality that is not included in our base than we declare it inside off the iBook repository on, then declare and then concretize it in the and then implemented in the concrete class. Now let us look for our concrete class and we're going to create it in services, so I just go ahead and click. Add at a new class and this one is going to be book repository Our Booker Buster is going to inherit from I book repository on. Then once we implements the interface, we're going to be getting all off the method stops. So the first thing that we need to do is to inject our application db context in tow, our book repository. And I just did it quickly. So that consists off private read only application be the object on, then initializing it in our constructor for or book repository Next up is to implement or save changes. So when I go down to my function, say if I want to make sure what it is a sink on the remember that we have a function called Save changes Andi Well, a variable call changes on we're calling the function save changes a synchronously on. Then we're returning. If there were changes, yes or no? Next we have our creates. So to do our create, I'm going to say ah away. It underscored db dot books that Andi I am spelled awaiting clarity. So and I still have another because I did not put a sink right. So you always remember that awaits and a sink. So underscore db dot books docked on. Then we say Adah, you sink on. Then I passed in entity, and then I ah, wheat or sorry, I return and then awaits the results off the save function. All right, so I'm just going toe copy this part because I know that this is really done in every function. Some adjustment a copy and paste it in all of the applicable functions. Well, really. Update and delete. So we just do that quickly on. Then let me get back to what I'm doing. So in the delete, we want to say underscore d b dot books not remove on. Then we're removing the entity. All right, on, then we return. Now. We'd save on and off course, you need a sink on the function. So let me just go through and put a sing everywhere. Also, just to make sure I don't forget it, right. All right, now we can continue, so no, we want to find all books. Finding all books is fairly straightforward. We just need to say await. Underscore, db dot Books dots to list is sink and that will get all off the books and off course I need to return this. So I need toe return now. I could write it this way. I could write it in one line, sure, but I like to be a bit more consistent. So I think in the author's actually wrote it where I declared a variable. However, just validate that. Yes, I did. I said, Vier variable is equal to that. So I'll do the same thing here, so this could work. But I like to be consistent so my court should be consistent at all times on. So I'm going to save iron books is equal toe the result off that on that I'm returning books. All right. Same for find by ideal. Just copy this really, because it's very similar chord someone to save our book on return book. But then, in this situation I am doing, uh, books dot find a sink and then I'm passing in the I d parameter the I D value and then is exists would be something like that once again. What? I just start this one out manual is on. Save. Ire is exists. Is equal toe a weight on the score. DB docked books dots on. Then I'm going to say if I know it's going to be any easing, all right? And then my lumber expression to see Is there any book with the property? I d. That much Is the i devalue coming in through this function call And then I went to return his exists All right, on, then last But by no means least we have updates were going to say underscore BB dots Books , not it on were fasting in the entity now a common mystic Onda. Well, I'm going to say I run into it. I'm not going to make it sound like they're, you know, other people there, we don't run into it or who run into that I don't. But sometimes it's easy to forget which repository in and a such reference the wrong class . So just be sure that your is in the right class or the right property of the application db context in the right repository. I know that I have set up the repository and the contract. I'm just going to go over to the start up and make sure that representation off the contract and service is me on. So I'm just going to make sure that I have my book repository as well as the concrete class , which is book repository on. Once that is done, we can do a build just to make sure that we didn't introduce anything to break our cord on our buildings. Successful. So, for no, we have set up or repository on service successfully.
24. Books: Setup Controller: Welcome back, guys. And this lesson, we're going to be setting up the FBI controller for our books, so I'm just going to get right to it and click on controllers Click. Add Goto controller on. Then I want an empty AP I controller on. Then we're going to be calling it a book. Books. Sorry. Controls the books controller. Now, remember, for our controller toe have any functionality, or are these interact with our logic? So far, we needed to have. So this means that we need to make sure that we inject our dependence is right. So we need dependence is for the repository on Based on what we saw and authors controller , we actually need dependence is for the logging service and also for mapping so we can follow suit. And I'm actually just want to copy all of this instead of trying to type it old manually. So I'll just copy all of that from the author's controller. It's the first time you're watching this video. You're not so familiar. You can take the time positive video when I'm done caring these errors. I'm just replicate what I have here, but I need to have our presentation off my iBook repository, and I'm going to be calling it on the score. Book repository not author. Repository. Andi, I have my longer service. I need my I'm upper somewhat you be using autumn upper on off course. Name off the control. The constructor needs to be the same as the controllers that exchange that Andi change Oates the references to the author. So that's pretty much all I need to do at least to get up and running because pretty much they're the same at the most basic level. All right, so that's it. So copying and pasting just made a whole minute off typing cut down to less than 30 seconds . So what we just did was to set up private read on the objects off iBook repository. I longer service, and I'm upper on then set up a constructor where we're going to be initializing them. So we accept a permit or per private object that we just declared on. Then we initialize them inside off that constructor. Other things we can go ahead and do would be to include a summary off this const off this controller. So I would just see, um interacts with the books table. All right, Onda, if you want, we can put on those annotations about all of the status schools that can be returned. But we're not sure what they are yet. Someone to leave that alone for No on. Right now, we've done some baseline things. You know, The thing is, as we go along, we mean notice that we need other dependence is because maybe we're going to implement a few book operations that we need the author repository for, right. So the point is that for each dependency that we have, we simply need to make representation of it in the same way that we did for these on. Then we'll have access to all of that functionality inside off the controller, but for no, that's it on. We have set up or controller for the books
25. Books: Setup GET Endpoints: Hey, guys, welcome back in this lesson. We're going to start setting up our get endpoints for our books, someone to start off with my annotation, letting everybody know that this is an http get operation that I'm about to start writing on there now declare that it is public a sink task, returning on my action results. And we're calling this one. Get books on. It takes no parameters because all we're doing is retrieving all the books possible. So off course, this operation is going to be relatively simple. We start off with over, try cats or try top tub on catch on. Well, so far, our authors controller, what we have done was we set up a function that would get called whenever there was an error. So we're going to replicate that. So I'm just going to go over to the author's controller, borrow that bit off court, put it at the last parts off the page, someone supporting this because really and truly, this is the same thing that we're going to be doing across all controllers. It's our standard, right? So I'm really going to just put it in there, Andi. Then I'm going to make sure that I mean that call in the exceptions section. So when I catch, I want to call internal error on, then I want to pass in e. That's message, right? No, There's something else that I wanted with the logging, but I'm going to leave that until last. So let's continue inside the try block. I'm going to save Ire Books is equal toe underscore db Sorry. Not DD, but book repository dot find. All right, so I'm finding all the books on. Then I'm going to return okay with the books object, Right? But of course I need toe do our mapping in between, so I'm just I'm just rushing ahead here. So in between getting the books and returning what I should do, I'm with jiggle the books right there on I should save. Our response is equal to on the score my upper dots, mumps. And then I'm upping my I will mapping two on my list off book B T o rights. Remember our DT always really what we're giving to the user or the caller Rather the client on then I My source is books, so I'm expecting a list off books on. Then I'm mapping it into a mop into book DT. Or And I just include what needs to be included on then that is what I'm sending back with my okay, That response, all right, on final is a synchronous. They see that red line it saying that, you know, I haven't asynchronous function, but I'm not doing anything asynchronous software. So I need to say, Wait right there. All right. I also modified the internal arrow because what I like to do is be consistent. So I'm just going to reference authors control and see one that I passed in the message on the inner exception. So I made sure to pass in that same kind off message former so that my logs across all endpoints look fairly the same. So But in that, some other thing, No, they're all going to a period of the seem. So if this is going to be logging the same thing every time, as in there's a 500 a girl from get books on, there's a 500 are from Aero from get authors by looking at the log, I would never really know which one off them field right unless the message explicitly states that, you know this happened when this type of operation was attempted. I would never really know which action or control of the area is being loved from. So what I want to introduce, right? No, is another function where I'm going to get the controller action on the controller name on that. I'm going to use those toe, determine what are to add to the log string so that we can look at the log and know exactly which controller on action would have triggered that log. So a separatist simple function. I'm just going to say private string on. I'm going to call it Get on Troller Axon names, right? Andi takes no parameters on. Then what I'm going to do is I'm going to save Ire. Controller is equal to controller context. Dots on. I think I may need to include something here somewhere. I'm going to include as I go along because it really does help. I spoke control around actually. So controller context. All right, there we will controller context dot action descriptor not And then you have actually many of controlling names. I'm getting controller. Right. So I get controller name and I'll just duplicate this land. So don't up the type. What out of that again on I'm going to say action name on the the variable is called Action on. Then what I'm going to return is, uh, formatted string. Some just want to use my dollar san quotation marks on. Then I'm passing in the controller variable value on. Then I'm going to say dash oxen, variable value. So what this is going to do is any time it's called, it's going to say OK, what action? What controller on action is making this call on. We can use that information, tow a pen Taurel out so that we can look at the log and know exactly which controller and action, the error or the in for the warning came from. So let me just do that quickly with the get book. So I'm going to say, once get books is called, I'm going to save our Ah, that's a location. So location meaning this is where it is. I'm going to get controller action names and store inside location. Right? So when I returned with the love, I'm going to pre penned any other message with the text coming from location. Right. And then I'm going to say cool on someone to say location. All right, so location is getting the controller. Andi, I spoke controller terribly. Let me just current that quickly. Con stroller, right? Let me just make sure that that this cart across everywhere All right? So I'm getting the controller actual names, storing it in location. That's once it hits to get books on. Then any time we're going to be logging going forward, we're going to prepare end anything. Any message that we're putting with the location is coming from so we can backtrack on do that in the author's controller later on. But right now we're focusing on books. So let me just add some information. Loves our own What is happening when we hit to get books, actually. All right, So I added toe lines off in flow logs right here in line 38 lying 41 on dso What I did, I just got the location like we did for the internet. Arrow on. I just appended it to something to say attempted calls. So instead of trying to write out a sentence like I did for the authors for the Longs for the authors, where I had to see attempted, get all authors and successfully got all authors instead, I'm just saying you call the controller Books and action Get books. Andi. That's an attempt that call on. Then if it was successful, I just say the same location was successful. So to me, that cuts down the amount off detail after putting and no, my love scale more consistent because I'm writing these sentences. A me You write it this way. No. One. Then write it differently in this log file. And so you know it's not consistent across the board. So that is just a little addition toe what we're doing here. Like I said later on, we'll backtrack and just can form. The authors section confirmed the authors controller to be up to this standard, right? So we got all books. Other things that I would want to include would be our response types, which are 205 100 and off course or summary to state get all books. All right, so that's it for the get all or the get books. The next one that I would want is the get book by I D. All right, so I'm going toe go underneath this one. It's still an http, get so I have to repeat that. Except this get is a bit different because it takes a parameter. So please don't forget this part on. Then we see I d on. Then you can further qualify the perimeter data types. I can actually say something like I'd call on int so that the documentation specifically says that it's expecting an interview instead of dressing. It's expecting an idea. So I leave it like that and we'll see if it makes any material difference. When we look at the documentation, I'm just going to copy these response types here and paste actually understand to copy everything in this phone shown on base because two functions are very similar. But ofcourse I'm going to change the name someone to see get book instead off. Get books on, then this is what going to take an int idee parameter. We're already getting the locations. I don't need to do that again. And then I'm trained operation where I can see attempted attempted call for I D on d. I'll just say what I d was being attempted. All right? So I mean, it can get big, but then, I mean, we already know where the attempted call for that idea is. So we know that it's an attempted call for the get book with the I. D. So it's easy to infer that we're trying to get that book with that I direct. Ah, what we do here, I'm just going to change of the choir. So Vier book is equal to book Repository docked find by D On we pass in the I d parameter aan den. The response is going to be a mapping off the book GTO, not a list. So I'm just making some minor tweaks here instead off writing all the court again from scratch on, then successfully got record with I d on then. All right, that is all my logs to be clear. That's all on. Then we returned the response. No one check I'm going to introduce. Here is the check to see if the book result is equivalent and null on. Then if it is, then I'm going toe right. Ah, love on this Someone to love the warning since set off logging inform went to lug warn Onda uh, failed to retrieve record for I. D writes. So I want to say field, toe retrieve. So you see, this is what I'm talking about. I wrote it one way over in. Authors write. I said in authors also with this was not phoned Over here, I'm writing field surgery, so that's I'm seeing. When you write sentences, you tend to get very pointed and then you get more points because you grew in the field and so you're loves will look inconsistent across what your buildings they want them to be consistent on. I'm going to write the format here, and then we're going to buck truck to the author's controller and change all till we do the logging. So feel to retrieve record with I d Andi I de Colon. Right on. Then, off course, we're going to return. I'm not phoned. So we did not find that record That's a 44 and were logging that that retrieval field. All right, so we have our get books on. We have our get book, so I'm just meditate this for a little test runs or with the validate that the longing really makes a difference as well as well, there are no books right now, so we just want to make sure we get about the right response school. So I'm just going to go into debug on test with Postman, All right? I said I was going to tested postman, but I'm just going to use Swagger, so I'm just going to expand this on. Then I'm going to say, try tote and then execute on. Then I'm getting my 200 response. All right, so we can see that we're Well, there are no books in the database. I'm getting the 200 response and let me just try not with the parameter for wealthy get book with the parameter someone to say, Try toads on. Then I put in an I d. Value off one on. Then click executes. Obviously nothing was phone. So we're getting that four or four. So that is expected. But what I really want to pay attention to is the logs on the same block file would have both the author work on the book workers. I'm doing both in the same day. But what happens is that you noticed that when you look at the influx for books, you can see that it's the books, get books, action and attempted cause successful versus that. Want to say that it was attempted for that and failed to retrieve. But that's just a warning because a failure to retrieve a record that doesn't think this is not an arrow, but we just put a warning, just in case. It's a cause for concern, right? So you can see here where it looks a bit more structure because you can tell the controller you can tell the action on. Then we can have standardized messages according to what part off the the function or functionality is being accessed versus hole. We were doing it initially where it was just, you know, free, free for all text. So the last thing I'm going to do for this is at the summary on I'm going to say gets gets a book by I D. On the Haram name I leave that alone and returns are book record on. I don't believe I put the returns on this one at least off books, and that's pretty much it for sitting up the get actions for our book controller. So what I will do is off camera. I will go back to the author's controller and then revise. So we're doing the logging and that we can go through it together and next video, but that's it for now.
26. Books: Setup CREATE Endpoint: you guys welcome back in this lesson, we're going to be setting up to create endpoint for our books. But before I get there, I just want us to review our authors controller and show you some off the modifications. The time, meat. So the last time we discussed making over logging a bit more consistent. So what I did was to introduce function that will return the name off the controller and the name off the action that is currently active are being interacted with on return this component stream off controller dash action needs right on dso. What we're using that to do is pass into our logging so that instead of trains rattled complete sentences or be too detailed, we can have a bit more consistency across all with a bit more simplicity, right? So I'm just pretending the message, each message, with the location being the controller, dash action on the message that should be passed. So I did that in the get authors on. I did it in the get author, and I also made sure to do it across all the internal error. Um, phone showing calls. No, I haven't done it across the others. Because as we go along with the books controller, we will be setting the new standard. And as you said, the new standard in the books control are just backtrack and make sure that the authors controller kind of follow suit. So back in our books controller, I already took the liberty off writing up the actions. They can pause the video and write it Donor can attempted to yourself. So I have a public casing task off action results. It's called Create Onda. We have our parameter which is our from body a notation on we're taking, um on object off type book creates D to know the red line is there because I haven't created the detail so we can do that together. So I'm just going to copy that. Go over toe my book bto file on. Well, I'm just going to copy the book GTO object on base. It's underneath. What? I'm going to call it book create detail on and what we don't need in there would be ideas. I don't need to create the book with the I. D. You be nice if we can create it with the author. So I'm going to take all the object for author detail. But what I really need is author I d on. I'm going to make this one not knowable, but it is very required because I don't want any book in my system that is not associated with an author, right? So I went to me, the also I d required. All right, on all the things that are going to be required include the title. The I don't need the year. That's it. Ice being is required on the summary for summary is not necessarily required. But what I will say is that I'm willing to accept a maximum off 500 characters, some putting on annotation, to see that the string length can be up to 500 off course. If you're going to put on this validation, you need to verify with the data beast because remember, we did this database first. They need to make sure that the validation your enforcing here does not violate the the constraints in the actual data beat. So if the database so said India march are 50 then you want to make sure that your string link is adhering to that. So I think that for summary, I had put environ tire marks, so we will leave it at 500. So even though the databases marks, I am boxing adults at 500 on the client side, right, I am not making image required. And I'm not making the price required either. No, what happens is that if I had included the DT or in the author GTO, object or property or other in the book create detail, then I would have given the person opportunity to fill in some other details that might not necessarily have bean accurate. So once again, the detail helps us still kind off. Come control what? We allowed the clients to enter into our system. Right? So I have Mike book create GTO created on DSO. That air goes away know that it sees that that class exists Now our creation off a book is always going to start off with us getting the location. So we get the location. We know that we know where we are. We know why we're getting location right? Next up is our try catch. So I'm going to try on, then catch the exception. Call it E on. I'm really just going to copy this line because it's there already. All right, so that is taken care off, at least for the air handling off. Any exception, Not going toe add ally in tow. The logger with other line off court that's going to log that create operation was attempted. So I say location, Colon, create attempted right on. Then I'm going to continue where I'm going to say, if the object is no, then I want toe log a warning. So I'm going to love warning to see that in this location and Inter Quest was submitted on returned the batter quest with the model state. My next check is if the model state is violence, Remember, we'll just put in the tower notations toe, validate the data that's coming in. So I want to say, if the model state is not valid, then we want a lager warning to say that the data was incomplete on return about request with the model state. So, as you build out AP, I zero realize that the basic operations will kind off look the same way across the different entities or the different controllers relative to each entity. Off course, If you're doing specialized operations like calculating stuff in between, then it may differ. But essentially, we want to make sure that we're doing the same types of checks along the way because each one can be plagued by these off course on a case by case basis. You may have specific checks specific to the operation being carried out. If we get past these two. If statements than the assumption is that the book object is is in a valid state, so I want to do is insert it so we'll save Our book is equal to on. What I Need to do is map from the d t o Object. So ma per dot map on my moppet mapping toe. The Objects off type book on my source is book E T. O. So I'm no saying Give me what book on book detail having common on create an object off type book on then once I have this object on what to save, our is so sess is equal toe, await a call to my book repository where I'm going to call my create function on past in this book. Then I need to check if it was successful. So if not is success, then what do I want to do? I'm going to call my internal error and say that at this location, the creation field. So that's if it wasn't successful. Otherwise, I'm going to just put one final return on I'm going to return created as well as a payload containing the date that I was just created. So I need to say, Are you you are a first, which would be the same create right on. Then the object would be new on them passing in a book, all right? And that's what was just created So we can see here that well, we filled out all of for worst case in our zalis that are known to us on. We try to log as much as possible. No, I did change the format off the loves a bit. So what I said I would do with the author's control. I'll backtrack. So I want to take this first line and make sure that the first time off my authors control it looks just the same way, right? So location created, attempted on. Then if it is empty that I'm going to say location. So the empty request submitted. That's not so bad. I didn't want to go much change. We love the warning for incomplete data, some just making sure that at the same points off each controller, the logs will the verb it off the logs will be pretty much less. See right that on top of an essay on one side, Andi on day two words on the other side. So consistency once again is key on. Then, finally, I didn't put our longer that's in for logging for Sorry, I'm attack. That's over on a square logger Doctor Logue in four to say that at the location. So we just do that location. Colon on. See, that's the Cree Shun was successful. And then, if you want, you could even include the object there to see that this author was created at that time, right? So that's good for logging. Also, maybe you want to log Ah, a second line to see objects created so I could just pass in a book. Let's see if that works. Maybe maybe we'll show us all the details off the book. Maybe with your show and on object line in the love but we will see so I can attempt that over. And authors also on. Just make sure that I normalize this line also. All right, I know over here would be author, not spook. Or maybe I should hold off on this land until I validated with the book. All right, so now that I'm done with the court for creating letters validates, I'm going into the boat moored. Actually, don't go into debug more just yet. We left off quite a few things. So one I didn't put my verb, which is http post and that's over. The create, right? Also need toe. Well, I don't need to, but it's good to just include these return codes at the same time. So I'm just going to copy existing one. So I know that I'm returning. Not a 200 here, but I start a stool one which is created, right? I'm also doing an internal server arrow on. I'm also doing bad requests, so let me just make sure I have representation off those 400 but requests. All right, Andi, I think that's it on. Maybe while I'm here, I can just put on my summary, but I think I'm done with this function, so create Ah, new are creates. Sorry. A new book, right on git returns. Well, nothing. So our book objects. All right, so, no, we can go to debunk more confidently. So lets us test this in Postman. All right, so I'm in debug mode, have all my documentation, and they're showing me a sample off the payload that needs to be passed over with this sports. I'm just going to copy this sample over toe postman already started up a new tub on. I have the endpoint FBI slash books. I have it in post over. It's a body tools raw on. Then change this to jae sun on, then pieced. So, no, I need to fill this in. So this is my first full on the year that see, the year was 2000 and 10 ice being That's usually like a unique identifying numbers. I'm just putting a random number there. Summary I'm going to leave that blank. Um, the image leaving that blank also, that was not required. So image really would be a path to the image. In case you're wondering on you're probably disappointed that I'm not being it any man. It's really a path to the image. So what I don't want to do is let the AP and do the work off getting the image upload and doing the converse on. Rather, I would prefer that the clients consuming my baby I would have a load some upload to some server, right, cause I'm not going to be storing this image on my server. But you uploaded to your server on. Then you send me the path, all right, But when we're doing, the client will probably be using a CD, and anyway, so we'll upload it to a Cdn service and then the store the path to the image inside off this field, right? So we can go ahead and I'm putting the price to $10 on. Let's leave the author idea at zero. So I know this is going to fail, and that's validate that you will fail because the author, I d. You'll probably give me on ah, 500 errors. So let's try. So when I click send All right. So as I thought we got ah, 500 error on If I take a look in the love file, I will see that it is saying, Oh, my mapping. So I did not mop. My book creates detail. All right, so let me just come out off the boat moored that just spot some fun a while ago and me stop . So this part always gets me. And I'm glad that you're seeing that it gets me because we're all human. So if it gets you to, then don't feel. Anyway, if you didn't get you, then Great. So we just want to make sure that we have our mapping, So whatever whatever mapping were doing in the application, we need to make sure you have a configuration. So let's go through that again. All right, So let's try that again. So I click send, give it some time. All right? So we've got another 500 let's see the reason for this 500 on die. Just reload the love file. So no, we're seeing Ah, nice. Long A nice, long, um, exception message. So we can see here that in four books create, create, attempted and then we see era books create on air occurred while they said that. So long story, short distance, saying that I'm referencing on author That doesn't exist cause I said zero. So when I put this the author too, I believe And I still have my authors request here. So I know that I won author with the i d to So I'm just going to say this book was written by an a k on. Then I'm going to click, send on we get a two a one created at on So we see that the book object came back on disassociated with author too. So the cool thing here is that Well, let me see if it's really going toe work. I think I may need to do something to the repository for this to work. But essentially, when we get on author, they see this list off books. The list off books should follow. So let me get that specific author, which is author too. Andi tick send. All right. So I don't need to modify my repository a bit toe include the list off books, because essentially, what this is saying is that when you get the author, you should also get the list off books that he or she has in their repertoire or they are related toe in the database. So we just created Ah, book that was written by author with I D to Silas. This book should come up under that authors repertoire, but we'll do that later on. That's no worries for no, we're just happy on were satisfied That or book is being created now if I violate the the the validation. So I'm not going to submit a title and I went to try again. Then you see that we're getting the 400 bad request with our model state error. So I think that sums it up for our create operation and just updating the love. So I'm going to introduce you to our little that basically just obviates the love file automatically. So no part plus parcel always ask you or let you know it has changed the light a bit when to introduce it to another tool that just shows you like are running trail off the log fat and it's really cool. I One cool thing about swagger that I may not have mentioned is that if you look down at the schemers where they show you the details, they do give you the rest. Red asterisk beside the ones that to you, the developer would have marked as required. So we said title was required. Ice being is required on author Addie's required. So that means anybody submitting a book could have so omitted on object or a Jason String with only title SBM on daughter Addy and would have matched those and created the book successfully. Right? So that is whole nice and clean Soldier makes the documentation on that sums it up for the creation off.
27. Books: Setup UPDATE Endpoint: Welcome back, guys. In this video, we're going to be exploring setting up our eight functionality for our books. No, I've already gone ahead and done some things and you can pause the video at the opportune time and just copy it off. But I'll be walking you through what I've already done on the first thing that I did was to create an update detail. So the update 82 has tohave the i d. Because we need to track the idea off the record being updated on Gueye Also to call some of the things. So I took out I s bien. So I don't want anybody to come back and change The is being because that's a unique reference number. You put it in, It stays right? Um, it's easier. They removed the book on recreated with a cart ice being than tallow them to change ice being, That's and that's just me. So once again, you form your details based on the business requirements off the application that you're building. So I don't want anybody to come in and change the is being off any books. I haven't included it in the opiate GTO. Andi, I also removed the author, um, property from that update detail. Because I don't want somebody to come along afterwards and change the author off the book just like that. So once again, you're in complete control off what any client is able to do to your data through using the data transfer objects. After creating this data transfer object Once again, you can pause the video and write it off or copied off. We went over to the mapping on. We made sure to create the mapping configuration have been caught in the past where we attempted operation. Just realized we didn't remember to put in the mapping, so I made sure to do it this time on then in the books controller. I already wrote out the actions. I'm just going to walk you through it, but really and truly a lot of it looks just like what we did in the author, right? We have our annotation, http, put on. We take the i d on D, letting everybody know what it produces. So it produces response types. Tool 4 405 100 for internals serving error on. Then I go ahead and define or function as an asynchronous function task. I action results. The name is up a bit on it takes a parameter into, but it's also looking for a payload from the body off type book off the GTO on we call it book GTO. We start off by getting the location, and we know that we do this so that we can keep track off what is, you know, being called in our logging on. Then we try. So let me just skip down to the catch parts where I do the regular return. Internal error. Frankly, this line is the same line in every other actions taken this copy and paste that easily boats for the transaction. We're basically doing the same kinds off checks that we did in the update function for our authors controller, right? So I'm first in logging off course. I changed off the verbiage for the logging, and we're going to backtrack and do the same thing in the author's controller. But let's just work with it. So we have the longer on were logging that the update on update was attempted on record. I d i d onda. We know the location and we check if the idea is less than one or the payload is no or if the I d in the perimeter does not match the i d in the payload then we will say by the request Onda, we will also love the warning That update field with bad data i d colon idea right? We're also going to check if it exists. So we call Booker Posture not is exists passing the i d and then we say If it does not exist, then we are going to love the warning that we feel to retrieve record with the i d. On we return on, not phone Later on, we go on to check the model state to see if it is valid. So of course we have some things that are required in the opiate you most pass in the the title you on. Well, there's nothing else required, Really? So in the update, you could clean out everything else where your most person at least a title for you to proceed on the moving on. Let me just validate. So I think in the Creator. So we needed title on dice being I'm not allowing you to do the ice being. So I'm not going to require the ESPN so all I'm requiring the title because that's all they are allowed to change. So you can't submit an empty title to me or no title at all. All right. Ah, so I'm going to go on and say Vier book. So if he gets this fire, then I'm going to mop the data transfer objects to the data class, which is book on, then collect it and then we await the result off so off submitting that the request to the database if it is not a success than we return Ah, 500 error. And I'm longing that in this place, off the field on let me just qualify that update field for record with ideas. So let me just a pin that for record with I D i d. So that you know, it's more specific where it failed on. Then we log on. This is a warrant. Should be a log in for right. So it's good toe check over your work. So I'm logging in for that. The record with idee that was successfully updated on I'm returning a new content. All right, so once again as I went through, you could have pause a video on Does taken off or, you know, re created in your own project what you need. But I'm going to proceed on. I'm going to go ahead and test this action. Someone's going to debunk moored. I'm Indy. Both mood and I have a postman, someone to open up. A new tab for my new function test on this one is going to be a put on the end points, which is a p I slash books Onda. I'm Obviating book with the I d to I believe that that is the one book maybe that I have in the database. No, What? I'm going to destry it here is so flexible. The validation on data transfer objects makes makes it toe transport data. So I did say that you need the i d. One way or the other, it's going to check against ID right on then. The only thing that is really, really required for an update to be I'm a carted off need to be successful is the title, right? So if I just look in the in the documentation I see here also, that's authors. I mean books in the documentation, I see where this is the entire payload. So this is the entire payload that matters. However, if I only want up there the title than I can just pass in a new title. So this is on obviated title. All right, on So enemy just remove that street comma on based on the validation the idea believe is too on. So I click Send on then it's going to hit our action, go through all the validations on, then return a status tour for no content just to show you that it got the data. It did the validations. It saw that the title which is the only required data bit really based on over data transfer objects validations it's there on. Then it went through with the operation and no, it is updated. So if I go back to my gets, do I have a get Oh, well, I'll just do it from postman, so I just get all books, try toads and then execute. Then you're going to see the one book with the I D to and updated title right on where everything else is. No, because I didn't provide a value. Now, here is where we need to be. Careful, because what happened? Is that where it didn't provide a value? It automatically assumed no on DSO If I submitted no, it would override the value that is there. So author ideas? No, No, because I removed it from the GTO. Andi, I submitted a payload that did not, um, make reference to it. Right. So I'm going to me that adjustment. So I'm going to go back to my DT all on. I'm going to say so. That's why it's always good to just do a little test to see if what happens after you do an operation is desirable, right? So I'm going to go back to my off the detail on I'm going to set the author I d All right, someone to set it as required. So I'm goingto enforced to the clients that they must tell me who the author is. Off course, from the client side, we can kind of control how this data comes across the pipe or make recommendations based on our documentation, but for no, I'm going to say that it is required because I cannot have and no for my author. Well, actually, I can, because I did indicate that author I d could be No. So I guess I need to go back to my business analysts and get it right, but for no, I'll just leave it blank. Leave it Thought on we can proceed. So no, we know that our update operation is working. We kind of standard I some off these logging messages. So I'm just going to backtrack to my authors, um, update function on me, these changes and you see, that's a cool thing. When you have it consistent, you can just copy and peace. You don't have to retyped them, so you type it properly one place on. Then you can just copy and peace across all your other and points on your loves will come out looking clean. Onda Very understandable for anybody who is looking through them now. I did say I would introduce you to a new tool that helps you view your logs in a little more efficient manner. I think it's more efficient results on it's really, um but I'm going toe tell you about its right after I copied this line on the name of it is bare tail, so you can get to their website by going to beer, tail, beer, metal, soft dot com slash beer tail art. And there's a free version, so I'm just going to don't know the free version on. It's really a standalone version for Windows. It's just on executed a file and click it, you run it and then what it allows you to do is select a file. So I'm going toe open on, find my log file, and then once I open it, it's just going to open that file. Show me everything that has been happening in the file. It has an option that's his follow tail. So as a fire gets obviated, the movement will just go on. So what I'm going to do is go back into debug, moored on, going to fire up on a P. I call, and I'm just going to show you how the love file moves in beer tail. All right, so I have beer tail on one side on Die, have postman on another, said, I'm just going to make here till a little smaller on, then just watch whole beer till behaves when I make a few AP I cause I'm just going to make a few calls, Um, a cracked across the board, just clicking and clicking and look at how Bertil moves. So maybe machine is moving a bit slowly, so you know it's not as clean as it should look. But that's essentially what Bertier brings to the table. So it's good for training eras, you know, in real time when you need to see exactly what is happening when it is happening, where it is happening. And then it gives you highlighting so you can actually do something like you can search for the string error. I think I could ignore case, but then I want to highlight, or at least make all era text read. So at that on, then I think, OK, and then you see any line with the word error gets highlighted red, so at least I can see exactly where the errors are. The military is a really cool monitoring tool. Like I said, just know it's lightweight, so you know it's easy for it. Oh, till get assistance with their debugging activities as you develop
28. Books: Setup DELETE Endpoint: Welcome back, guys. Industry. They were going to be setting off the delete endpoint for the books. No, What I'm going to challenge you to do is pause. Then minimize this video on attempts to create this endpoint for yourself. All right, So you already have on a few endpoints that we've created. You already have the authors controller with a delete methods challenging you to the spas video minimize on. Attempted to yourself. I have already done it. So I'm really just going to walk you through it. So you know, after you're done and you probably resumed, right? No. So I'm just going to say we can check over all work together. So if you have anything different than you can funded it against my no problem. So I started off off course with my summary repose. A book by i d. The parameter returns. I left that blank. I put in my appropriate verb on. Did you know that? I expect a permit, er off i d or called idee. Sorry, I put in all of my response cords, but still 104 404 04 and 500 on. Then I went ahead and created my synchronous function off task I actual results called elite with my perimeter in Thai de I declared my location because ofcourse we need this for logging on then my try and caps off course The catch looks the same way It looks in every other action really and truly so that should be the easy aspire to get moving on. I have my longer dot log in for location to say lead attempted on record with idee that all right on dso As I build out these longer messages, I realize that the verb ege is kind off because of standardized the language across all of the kinds of operations. So the lead attempted on record with idee that in the opiates have update attempted on record with I D that on. I think I have something like that on the well this is attempted car, so I should say, get attempted on record with. But the point is that I'm kind of standardizing the verb. It's some kind of putting together like, ah, a template for call. So whenever you feel like you're repeating yourself, you probably are on. There is a principle in programming called dry. Don't repeat yourself. So when you feel that way, I challenge you to create another abstraction off the longer on probably have, like some standardized templates and find a way to dynamically Paschen the specific parts off that log message that should be unique. So this one says, delete attempt at fair delete failed. Um, on then, Well, this one is standard on delete failed. But then if you look in the update, it's the same Burbage I literally just copied and pasted all off these messages from the updates on guy. Put them there and replace the word, albeit with delete on. Then further to that, I did the same thing in the author's controller. Where is the same verb e ege? So you see, I'm just repeating myself. No. So if I have another controller is going to be the same verb it and I would ever beat it myself again. So I challenge you to create another obstruction on the logging on reduced the repetition or the amount of static data that is being repeated across multiple points. Any hole. Let us continue looking through our delete. So delete attempted. We check if the I d is an invalid value on day. If it is, then we say it failed and we returned. But requests if it check if it exists, and if it does not exist, then we log a warning to say we we feel to retrieve that record on. Then we move on to actually get on. I copied and pasted from the author's um, just current this quickly. So you see, behold, your deeds will find the world I copied over from the author delete. So if you talked to thought manually, or you copied it over and change it, so then that's perfect. No problem. Copying and pasting is programmers, best friend. So the book I phoned by, I d using my book repository. Then I checked. If the delete operation was a success, if it was not, then I returned the 500 with the location and the log message on. Then if you've got this fire, then I said, Well, the the record was successful, deleted, and I returned no content. Now I believe I only have one book in the database, but I'm still going to go ahead on, and I'm going toe going to debug more than just test this delete endpoint. So I have up bare tail to the right and postman to the left, and I'm going to create a new book first. So I'm just going to create one with the title. My second book, you can put in anything. I'm also going to change the ISBN, so you probably want to end for some unique That's moving from the database side, though. Where to work Scots have the same. I speak and write so and when you click, send create a new book, all right. And we can look in the love failure we see in four books Create, Create Attempted on God's Creation was successful And if you look at the time stamp, you can see that it took both seven seconds to do that right, which is kind off long. But this is my little machine. It would. It should be fast on a server, any hole. Oh, before I move on, This timestamp stuff is really good because I worked on a project. One time on the clients that was calling a Web service was timing Haute on. They were saying that all of service was at fault. But when we checked the logs on. I was able to see the difference between or the timestamp off when the call was activated versus when we returned data on. They said it would time out after five seconds, and we were turning it within milliseconds. Then we had proved to show them that the FBI was very efficient. They needed to check their system. So this is another, you know, logs on time. Stumps are very, very important. The developers. Anyhow, we just created another book on the I. D is three. So I'm just going to use this newly created book as escape goat. I'm going to create a new request on dime going to just copy the endpoint here. Andi, based on, I'm going to say the in point with the value three on this is a delete operation. So I click. Send Andi I have on error. All right, So I have another incident is highlighting that it was a nurse. So after five seconds off attempting it, we attempted toe the lead to record with 83 then we got some cast. Some cost error are so let us see exactly what would be causing that type cost error. So I want to go back to my delete endpoint and I find by I d on I said the lead book. Ah, Is the typecasting happening? I may have to put a brake points. I'm going to put a break point. I have done parts off the cord on. Then let's go back to Postman on. Then I'm going to send again. It's a wear out or break point on. I would use if 11 to step. So you step in on, we try to find the book, and I'm just want to validate that this is three. All right, on then he moves along. Onda there is the exception. So it is failing to retrieve because it's in that one is a double on one is a decimal. So I think that this might be a problem. Maybe with my data class. Let me check out. All right. So I went back to my database and I'm reviewing the design and I see here where price is off data type money which, if I'm not mistaken, directly translates toe decimal in C sharp. So, in creating my data class, I had defined it to be double and not decimal. So they made that change. So I believe that that is where the era is coming in. So my data class needs to be se decimal and off course, if the data classes decimal than the corresponding details need to also say decimal for price. All right, so let me attempt this again. Alright, Some back with both postman Andi my logging tour. So I'm going to click. Send on. Let's see what happens on. We have success. All right, so we see here, the elite was attempted on It was successful. All right, so that was the problem. So you have to make sure that your data ties for your data classes are the best C sharp. Um, beta types. Too much the corresponding, um SQL server data type. Right. You want toe? Be very, very sure that be much. So with this operation, don't we have tested? Well, we created, tested and no validated or delete operation for our books on dso. That's it.
29. Review and Add Changes to GitHub: Welcome back, guys. In this video, we're just going to, you know, review what we've done in this section off the course on day check in our changes to get up . So what we implemented where the crowd operations are, the crowd functions in over a pair controller for our books on. We had to take in some dependence is initialize them on. Then we were sure to be very strict with or documentation as we went along. We also standardized the log messages so that we could know the location, meaning the controller on action, that the log is being triggered from on. Then we use this standard to apply to our previously created authors controller on we did that through and through implemented are get book or create on update on delete. We also had a little miss up with the delete where the data type miss much, but we caught it, nipped it in the bud, corrected it on No, we have full complaints. Also looked at a new tool called beer tale, which I lows us toe better track or loves. And it comes with little things like highlighting and followed here, which will allow it toe automatically shows what the latest file latest lines in over log file are now just goes off this chapter, we will check in our changes to get top. So I'm just gonna directed the solutions Goto commit on, then type our commit message. All right, so that's my little message to myself to say that I implemented crowd for that before, not from a book ap I controller on standardized log messages. So I'm just going to go ahead and commit all on the sink on push those changes to get up on . That's it. So next time we're going to start looking at new topics like security and authentication for over a P I.
30. Scaffold Identity Tables to Existing Database: Hey, guys, welcome back to the His mission is to start scaffolding the identity tables into our data bees. Now, let me explain. A little scaffolding refers toe the process by which we oxygen. Everything's right on. Then when I said identity tables, what I really meant, where the tables that dot nets core or dotnet, entity, framework or core identity there. So many. So this thing. But they come with some default built in tables that supports user authentication. And that is when we were creating our project and I selected the razor template on, then selected that I wanted authentication with individual cones. It automatically included configurations and the capabilities for that. So some of the configurations really would be found in the start of Nazi s file on defy. Screwed. Don't. I will see here, that's we have the upset up to use authentication and use authorization on in the services section. It went ahead and added default identity for some generic class called Identity User. And then we have some options here where we can see if we want toe include ah require confirmed a cone feature in our sign up process. I'm actually just going to remove this. So what this will do is that kind of two step registration. You know, when somebody registers and have to go into their email for some talkin to confirm its them . We don't need that someone to remove that option on. So what we're left with is just a default identity with that generic class that represents the user class given to us by core identity as well as which database are which DB context . It should draw on the stored identity tables. Now all of that could have been added after the fact, because once again, the startups that CS file is pretty much the same regardless, off the template you choose, it's just that well, we chose a template, got some of it really made removed what we didn't want and we're at the same place anyway. So what we're going to do now is ah, scuffled. The tables that are required for identity user toe have some purpose. We're going toe are degenerate them in tow. Our database that is phone in the application DB context, which is configured using the Default Connection string, which we know is pointing to the database that we have been working on a plan to know. So I'm just going to save the starts of blood. CS file on that. I want to bring your attention over toward Data folder Migrations folder and then this file with all those zeroes. No, this is what you call a migration file into the framework that those what we call migrations where it keeps struck off every change that is made against the database on. Then it will automatically roll of those changes. So it tends to keep, like, a history of all the changes. Now that is usually more useful when you have ah court first approach. In this situation, we don't have a court first approach. We build the database first. So our database exists on what we want to do is modify the database. Not, um, not by going into the database system and adding tables to use for authentication but using unto different work to modify the existing database. So what we will be doing is we'll be looking for a package manager console, so if you don't know where that is, you can go toe. I believe it's in tools on new get package manager and you see their package manager? Consul, once you quit that Ah, console. Looking like a command prompt will come up asking you for some commands. Now, what we'll do is run a command that says up the database. So pretty much off the data means will say, what is the most recent, um, migration that has not been effected on then 10 on Go ahead and effect it. Or rather, the most recent set off migrations, But in this case will have one. So if you want to learn how to develop using the court first approach and migrations, then you can check out my course complete sp dot net core 3.1 on entity framework development in that course ago end to end, building out a database court first on an application to go with it. Cover in our context. No, we have a database already, and we really just want the identity tables to go into that database. So we already have our any Some I agree, son. Andi, I have up my package monitor console, so I'm just going to type the command update dash database and then when I pressed, enter is going to build our projects that might take a while on. Then it will continue, and then it will just say it don't know this is a warning. It's just telling me that I have no type or much in bitter type for the column price in my database. But if you see yellow, you can read the warning. It may be useful. It might not be. Anything off means you're concerned. This is nothing off major concern. If you, however, see reds, then you know we have an error on. You may want to just validate your connection string and make sure that nothing was modified with regards to the migration files. On that, your tables are in topped and off course. If you run into difficulties, you can always contact me Now when I go over to my management studio and check on my database. If you remember, we really only had two tables with authors and books. No, we have quite a few more tables have .net roles where Sorry SP Net Rules and Rule claims and user user claims user log on SB users on all sorts of tables that kind of support that identity functionality that comes built in tow dot net core. So I'm just going to take some time. I look in the ESPN that user stable. I'm just going to bring up the design, and these are the default data points that come with it. So we have the i. D. User name normalize. Use the name email and normalize email. Email confirmed. That's a bit to say yes or no on the option where, we said require confirmation. Sign up that I had removed. What that would have done was look at this bit. So if this bit was saying no, then a person wouldn't be able to log in. But since it's since the disabled that it doesn't really matter, right? So what would have happen is that when you click the link to confirm it, it would have changed. This big toe. Email confirmed, is yes, and then you would be able to log in so all of those little features are built in all right , you haven't is locked 02 can enable two factor authentication. Wonderful, wonderful features old off the box. That's, however, concludes our mission for today. On in the next video, we're going to look at setting up some default users and default rules in our application
31. Seed Test Users and Roles: Hey, guys, welcome back. We just stuff folded our identity tables on know what we're going to do is seed some users and rules. So when we talk about seeding is just about inserting some samples into the database so that, you know, we don't have to go through the money or process off doing them. So we just want some users, because when we're setting up our user authentication, we need to know why have users there already so that we can proceed. So I want to start off by creating a file called Seed Data, and it's just going to hold two functions for us. So I'm just going to put that inside of my data folder. I mean, we could put still the rule time just putting it in the data folder. So I just right click goto I'd go to class on, then I'm calling it seed. It's on, then this is going to be a public static class of static, means that I don't have to create an instance off it every time. I can just cerebral that I can just call the functions that are in there at will. All right, someone toe have two functions I'm goingto have private static Avoid on this one is going to be seed users, and I'm just going to give you the empty shells first. And then I went toe have on Mother one that sees seed rules. I just reuse that. All right seed rules. No CD users is going to take a parameter on. This parameter is going to be user manager. All right, so use their manager is a built in class that gives us functionality toe literally manage. Their fears are for users. You know, we can access certain things certain built in functions, and we'll see as we go along. So, user manager on the default identity classes Identity user. No, the thing is, you can have more than one identity classes. Um, this is I'm not want to go too deep into identity. And the difference is not yet at least. But if you want to get your coat, my other course complete SB dot net core 3.1. Development on DIT will explain all of that to you. So we're using the default identity on going to call this parameter user manager on then for the rules, forms and I'm using Roll Manager. So this is the role twin. So the user manager on, we're using the default identity, which is identity role parents. And I'm calling this one roll manager for short. No. As I'm about to start sitting off the rules, it occurred to me that I did not see a configuration for the rules inside off or started. Let me just go back on. Look on. My suspicion is correct. So what happens is that when you add the default identity, you can also add a rose. I'm just goingto bring the line there. So we add the default identity that I breathe the line that I want to say dots, ad rules. All right. And then I'm telling it that I want the defaults, which is identity rule. All right, on then. Open ankles. Breece. Good. So right here were saying that we want to use the default identity, and we want to use roles in our application, and all of that should be stored on application beauty contest. All right, so that was just a little missing configuration that making sure is there before we proceed . So now we create another function, and I'm going to call it seeds someone to see from public disorders into big public static void on, then seed on. Then seed is going to take two parameters which are pretty much identical to the ones we just set up. So I have a permit. Er called User manager Onda parameter For the rules manager on all of this will make sense enough you when you see that shot full of song call. Right. So that is Well, that is our seed Gaeta skeleton, at least. So after you functions one public to private on what we're going to do inside of the public , one is just called the two private one. So I'm going to start off by seeding the rules on I'm passing into that one. The role manager that gave it through with a phone call on. Then I went to seed the users. All right on this one is taken. The user manager. All right, so when we call see data seed, it will call Ciro's and seed users. So let us start off with the rules. So what we want to do is check if a role exists already on. If it doesn't, then we go ahead and create said roll. No, this is statement is going to prevent us from creating are well every time the application starts because you don't want to create more than one incenses off one particular rule, right? So what I'm going to do is on this statement saying if and then here is where we see the polar off these manager objects on what to say. If rule manager dots on, then I can say roar exists a sink. Right? But then it's it is, um, this is a sink, right? So we have two options I can either see continue on and check on a pungency administrators the rule that we want to check for. On that I could say Dr Results. Right. So what happens is that if you're calling and chasing function on, do you don't have the away to get always said that results? No. Since I have the option off making it a think I'm going to write it out, and then I'm going to try and go back and then convert all of these functions to anything that would be a cool exercise, right? Someone to write it in a non hazing manner first, right? So I'm saying if the rule manager checks for the existence off the administrator role on it does not exist, then I want to declare of our role is equal to new identity role Right on then, inside of this rule, I really just want to say that the name is equal to administrator. Or so I'm just initializing or creating on object for that is our role on. Then I'm going to say, um, bar results. And then here's another situation. Know where I'm forced to use a variable because roll manager not create a sink so that so how to do create a sink and then I'm with the college role. But then I have to say that results in order to get away with it and then real eventually That results doesn't really much right, because I'm not using it anywhere. No. Before I move on, I'm going to convert this easing so it's going toe take quite a bit over factor, because, remember, I can't be calling on a sing function from unknown easing function. So if I change this one to you think than a lot of changes my toughed up in appear. But, hey, that's what we're here for, right? So let's just do that quickly. So to meet, avoid, um, function, you think you have to turn it into a task, right? And then, of course you have. He thinks it's public facing static task. Um, what of the function name is on then? You're seeing here That it saying that you have a task, but everything else is not a synchronous someone to remove the doctor results. And then I'm going to see if not away it. All right. Looking good. So far. So if not await because remember, this is anything. So that means I can do the same thing. Don't here, Instead of seeing vier result, I can just say away it on then take off the dots. Results. All right, so that looks a bit cleaner. Obits more. It's in kernels in totality. Right on then. Off course. Made the phone. Sean called secede rules. We need a way it here. When? If we're are waiting up here, that means I need to change this into a task or so on distance. Lee is sink. All right, so we just converted a nun asynchronous function into an asynchronous on, so I just brought the line so it doesn't go off screen here, right? So, no, everything here is asynchronous. I'll just do that with this Also, I leave the static, the static doesn't go. I just put in the keyword a sink and change void to task. All right. And then off course. If it's a task, then I await the results off the phone. Sean Car? No. Um, before I move on with seed users, I'm going to create two rules here, so I have an administrator role. But then this is a book store. So it's an online bookstore. We have administrators who should be able to go in and do I current operations on the books and authors on May be customers who might be able to log in and probably, you know, by a book off argument. See? So I want another one that says cost owner. All right, so this role exists. A sink is. They're saying, if this role in him doesn't exist, are rather this check using. If this role name doesn't exist, then, um, create an identity role. Andi will create an object and then create the record in the detail. Bees. All right, So no. When recede rolls, it will try to create these two roles on the on each time it runs. But of course, if it's there already, it will not do anything right, which is exactly what we want. So we've done. The seed arose. So let's focus on the user's no Noto create the users. I'm going to start off with a similar if statements when we're to say if user manager So that's no, we're going to look at some of the poets of the user manager dot Get users. Well, I don't need the users in row. I can go find by name, right? So what I don't want to do so I can find my email. I confined by idee I confined by logging on I can find by name all right, and all off them off are asynchronous something, if not away it find by name user money did not find by name a sink on. Let's just say I have ah, user. Um then name here would be the user name so we can go find my name or we can go find by email Remedios email So I want to say, if not, use it on merger that find by email and I'm going to have a default add mean at That's a bookstore. Not come That is our default email address, right? Oh, sorry, I got carried away. So this is not checking if it exists. This is trying to find somebody so an object. So it's expecting to return something. So what I want to do is check if it's no my back. So it's not a not it's not a bully. And to say if not phoned it is seeing awaits the results of the function. Andi, it's either finds a tire doesn't and if it does find it, then it won't be no. So if it is no, then you want to create a user on. Then I went to create a user off type identity user. Since that is our defaults user that we're using on, then we need to give that user and user name Andi on e meal. At a minimum, we need these Sanderson to call the using him admin. I'm going to send the email to be the same email that I just checked. So if I did find by name I could have said at me, and if I did find by EMI elected us, it's so there's so many ways to do this thing that there's no right or I'm just bringing our own The world's assure that there many possibilities, right? So I'm just seeing Vier user create this user object that is on. Then we're going to say away its user manager docks creates here sing And then I want to create this user with the password, Right? So if you look at this function, the function definitions are the overlords. You see that you have the identity, use their objects and you can also pass in a string password. So the password is kind of strict Someone just ap at science S s W O R D you want so he can change the pastor policy if you wanted to be simpler, but I'm going to leave it cause that looks like a nice, decent policy where you have to have a symbol. I have to have a number on that capital letter on it must meet a minimum life. All right, so that's a nice, secure way toe. Enforce security on your users. No, I'm going to assign. So this is going to return a value, actually. Right. So what I'm going to do to save our results is equal toe. I wait, That phone call? No. When I get the result, I'm going to see if results docked on. Then I will get a flag to see it was successful are nuts. So if it was successful than I want to say, user manager, that's odd to roll. All right, so I can know having created a user add toe role. So I want to say I want to add user toe the role at administrator. So no, you see why we see the rules before we cede users? Because by the time you get here, that rule most exists for this step to be successful, and this is a thing. So wait on, then. There we go. So we just did that with the admin user? No, If I wanted a sample customer, um, I'm just going toe do the same thing here. Just going to take this statement on. I'm going to say customer, that may be gmail dot com. All right, on. I'm going toe ad costumer one something you probably could have written like a nice before loop. And you put that in a Tuscan captain. Eight on a number each time. Now I can warn you that it is very strict. So if you see customer twice well, I mean, it is checking to see if customers so it can't have the to customers with the same email after strike. So we see the admin here. Then I'm creating customer one at gmail dot com. Use the name customer one at gmail dot com. Same password. I used to see imposter it. I have no problem with that. But then the rule will be customer because that is the other rule with that mane and way of customer, right, So we have our first customer, and then I'm just going to see another one. And then this customer is going to be customer. Tour that customer tool at gmail dot com. User name is costumer, too. On the email is customer toe at genia dot com. On. Once again, this rule is customers. Everybody's going to have the same passer, so it will be easy for us toe logging as anybody at any point. So once again. These are the samples so that when I going to debunk more the next time, they will be created automatically. All right, so no, we've done the heavy lifting. We just need to let the startup Nazi s know that it needs to run this application are Sorry this scored when the application starts. Right? So in the conficker, my thought right, I'm just going to put in underneath the chorus policy. That's a good spot. I was going to put in the formation. Call toe. See data dot seed. Right on. I believe seed is a sink, But before we wonder if it is a sink or not Well, a bigger problem. We need to include user manager and road manager. So what happens that were intending to pass in these objects? But they're not coming in. They don't exist in the scope of configure. So I need to add them toe the conficker scope are the Permata list so that they come from. So I'm just going to break the line so that I don't go to fire to the right on. Then I'm going to see user manager on past in Identity user on. We're calling this one user manager on. Then we're going to do the same thing with the rule of manager. I didn t rule about that here or aan den. This one is rule monitor. So no, we have our use. A manager and roll manager objects coming in on then. So you see, if I put on a weight, everything that's going to mess up everything because I can't say our weight without on a sink, so that could be a problem, right? So that is one of those things when it comes to asynchronous programming that, you know, we need to be careful. So instead of putting their weight in front, I'm just going to see a doctor weight on the end. So that's that's another little worker owned. So where there's a will, there's a way. So let's execute and see if our data gets put into our database. All right, so I executed and I'm getting this error, and I think that this is due to a spelling error. If you look at the whole administrator is written, that is entirely wrong. So let me just go back and correct it, so you probably if you're a better speller than I do. I, um you didn't get that era, so let me just go back and make sure that Iraq had Meanness Street or and not at minimum, whatever that was. So that's sorry. That's again. All right, so this time I got as far as loading the documentation. So I'm going to go back to my database, look inside off my SP in its user stable, select up 1000 and there I have my three users. So that's what ah user record will look like. And identity, right? The idea is not autumn incriminating is like what we set up its ah guo i d. Value. We have the user name on that's normalized the email that's normalized. So normalization is like they just capitalize everything and do a dirt much so that casing is irrelevant on day. Give us a password hash so all of those things are built in. You don't have to spend time hashing password um, toe put into the system. It does it for you gives your security and conference system Onda. We did disable the need for certain features, but yeah, that's what that means. Our users were created and if I go over to rules than rules would have had to be created for the users to be created. And there we have Administrator Onda, our conquering to stomp on the respective ID's. So we just put in some sample users and rose into our application. Andi, when we come back, we'll be setting up the user controller that will be handling the actual signing and signed out on authentication stuff for us.
32. Setup Users Controller: Hey, guys, in this lesson will be setting up a user's controller to handle some authentication operations. So I already started adding the controller. I went to controllers, right click, click. Add went to controller and I will be scaffolding on empty AP I controllers. I just clicked that click add give it a name, someone to name its users controller and then go ahead and click at again. And now we have our users controller. So, as is customary, what we'll do is set up or, you know, dependence is first on formal, So I want to dependencies. I want a dependency for the signing manager on one for the user manager have included those , and that's what they look like. So you can just write them off on Guy. Just include the missing library. So we have private read on the side and manager for identity user on user manager for Identity User. Also so the toff them work very well together, Aziz, much as they may seem similar, but one manages the user operations one handle standing in sanding roads and authentication stuff. All right, so we'll set up our constructor on well past in our dependence is. So I'll just did these on past a 1,000,000. Then off course we do our initialization. Xas usual. All right, so we have a signing manager and a user manager, like I just said. So what are the things that we want to do in our users control? I think the media thing would be toe handler. Log in. Right. So we have what we call data on notations on DWI would have been looking at them from previous controllers. So in this situation, we want a handle authorizations, Meaning, who can access a certain in point. We have bitter and notations that have, like, a low anonymous where we can restrict by role or we can just say authorized, meaning somebody has to be authorized. So if we say allow anonymous, that means that you don't need authorization even if the entire control is unauthorized. So if I said authorized for the entire controller, that means every endpoint inside off here would need authentication. Ah, Low Anonymous would override that right now. I don't have any purpose for that. So I'm just going to alot anonymous. Andi, I'm going to make on http post in point on this end point is going to be a public a sink tusk. Make sure you get my spilling right. Task off. I action results on this one. This endpoint is going to be log in so long in will be taking I use the objects I'm going to put in my from body. So that means we need to go and create an object that will handle this. So I'm going to say user DT, or that is the data type that we need to create and its user details. So let me just go and create that class a same tanks, and they just complete this and then go over to my details folder on quick ad Andi, create a new class and we're coming user E t. Or creates on, then use a need to or want to keep it simple. I really for no at least really just need a string user name Onda Stream password. Right. That's all I really require. Um, we can beef it up a little later on, but right. Know, just to get the authentication, we just want to use the name and password. Um, we can probably I mean, we can do a number of things, but let's just keep it simple. Renno. Sorry. So we're going toe. Just include the missing library so that we have used detail on We're accepting that right on off course. We're going to put in our documentation or summary comments to say, um, user lugging endpoints. It's anybody really. Documentation knows that they need to pass in that user long in endpoints know what we'll be doing here is we'll be seeing that we want to result someone to save I result is equal to on. Then I'm going to see a way it the result off the signing manager who is going to try a password sign in a synchronously, right? So then, no, I can see. So if you look at the the documentation for that function, you see that it means the user object. And it also needs password on so on so low I have toe Well, that is one off the overlords. Another overlord would see that he just wants to string user name and the password and these other two bulletins. Those have to be there so we can pass falls and falls. But the point is that one overlord would want and ah, whole identity user object on password on the other. One would want just using him and password. So since that's all we defined in this and I really not want to go through creating the autumn upper from identity user to this and that, I'm not going to go through that. All I'm going to do is just use the easier overload. On day I went to say, Well, var user name is equal to So I like toe take my results off objects and them inter variables first, somewhere to see use the name is equal to detail. Use the name on a password. So remember control de duplicates the line just in case you're wondering how I got that done so quickly. So user name and password. And so that's what I'm going to pass into the signing. So I'm passing the user name passing in the past. Word on, then I'll just say, Falls on falls satisfied. Other to Julian's, right? So it's going to attempt on authentication. So this handles that goes into the database, sees the user name, attaches the pastor it makes so much on DSI is what he needs to see. No, we need to say if the results right is let's see. So Mr Stopping that's not equal. So no rights, if result is not equal to no meaning. He got something back right then for No, What I will do is I'll just see Okay. Are Let's make it a bit interesting. Sorry. Return. Okay, so let's make it a bit more interesting. Where I'm going to save our user is equal toe. We tend that I'm going to use the user manager toe, retrieve that, um, user seconds they find by name. All right. So if I'm asking for using him, right, so they see say it's fine by name. He wants to use the names I can find my name on, gets the user by the user name being used on. Then I went to just return user the user object with the okey response on. Then if that doesn't happen or it doesn't go into that if statement, I'm just going to return what we call, uh, on unauthorized right. Unauthorized means that you're not a load beyond this point. Let's see if there's an overload that includes data so I can pass in the objects of any Just say, use that GTO is unauthorized. All right, Off course. You know that we set up our logging as we go along. So about backtrack and do all of that at a later date, right? No, I'm just more concerned about setting up the logging. All right, so let us take this for a spin. Someone to just goingto Oh, where the above mode post money in the meanwhile. All right, So I'm just browsing through the documentation of bitten we see here, FBI slash users or user logging endpoint on it requires a user name on password on that should be in their quest body. So let's construct that together. So I'm just going to bring up a new tab on The cool thing about postmen is that it keeps a history. So if you're signed in with your you know, your personal account, he keeps a history off every single request you've ever since I could scroll for days because I have done quite a bit off FBI testing using this tool. So let us get in tow our tests where I go to post on, then I'm just going to borrow the address from one of my previous ones because we're using the same loca host port address on. Then it's a P I users. There is no no value after the slash. But then the body needs to look something like this. So I'm just going to copy the sample on. Then we go toe raw, choose Jason based on. Then let us try. So I said admin. Andi the passer this p that sai s w o r d one. So let us see if this one works. So I click send. All right, we're in business. So we see here that this person's information came, but now obviously wouldn't necessarily want to return the entire payload because here you're exposing the password hush on as much as it's not very decipherable, it's still a password hashes still information that you don't want going. All right. So you could create, like another, um, bto. Like a view user detail where you're really just returning. Maybe the user i d the user name the email on any other bit off information that you know would be sensible to display in a response about a user. All right, so that works Andi. If you're thinking that maybe you want to include, like first name, last name and other bits off data in the identity, then that is totally possible. And once again, I go through that in mild. Of course, complete is speed, not Net 3.1 core Andi entity, the framework development. So you can go through that course to get a better understanding off the identity and how we can be extended. Either way, we can validate here that the sign in pretty much work. So let's try with customer one. So we tried that with, um, the admin. Let's try with customer one. And then we see here the same for customer one. So let's try with some random value, something that is not accurate. So some wrong use the name and then we see we're getting We're getting a tool for no content. I didn't expect to get that. So let's go and debug a bit and see why we got that. So I'm just going to put my break point here after we would have gotten the results on, then click Send on. Then it hits. Our break points are good. So then results has field. All right, on then. I'm just going to step through because I want to see exactly why it goes to a tool for But then ah, OK, I see what the problem is. No. So alright, I get this snow. So what happened is that I said if result is not equal no, which is not accurate, I should be checking if results succeeded are not so Let me stop and then you fix that. So what happened is that it's still went to the okay, But then this was no So the okay returned at two or four with no content instead off a 200 with content, right? So that was the default behavior off the okay. And that's honestly the first time I'm seeing that. So let us do this together. So instead of seeing result, not know, let's a result succeeded. So if result not X succeeded then we want to return okay on, then it should end up there if it didn't succeed. So let's try that again. All right, so let's try that again in course to man and I click. Send on. There we go. So for a one on authorize, that's better. So it did not succeed. So went under for one authorized unauthorized Sorry on it Sent back the user, um, information from the attempt. So we see here that some authentication is working, or at least we can authenticate and verify that the users exist in our and points. No, What I'm going to do is just fix the logging in this in point. I really don't like having the in point without having logging. You know, we're sitting a standard, so I'm just going to take some time. Andi, borrow some off the the cord from one off the previous controllers. All right, so I set up this country to look more like the others that we have so far where I included the longer service initialized it on, guy, put in the locations are put in my functions to get a control and action name as well as internal arrow on. Then I wrapped the entire operation in a try catch. So I just put try, are owned. Everything that we did before on the catch would return the Internet era function call on guy was so putting logging to say that it was ah, logging attempt from user on. You could even put in. Well, we already have time stamps in the log, so that's fine on. Then we said if it was successful than we say, use the name successfully authenticated on if it was not successful than user name, not authenticated. So that's the logging that I put in tow. Um, the users controller. You might have a different idea. That's fine. I would love to hear how you think I could enhance that, but that's abyss, um, a baseline for US toe launch from. So we just finished up looking at how we go about authenticating users in our application. On the next, we'll be looking at setting up our Jason Webb tokens will also be looking at authorization at the controller and action level.
33. Setup JSON Web Tokens (JWT) Authentication: Hey, guys, welcome back and this. Listen, we're going to start sitting up or Jason Webb Wilkins Now Jason Webb Tokens have been during that expression around a lot, so let me just give you, Ah, snapshot off what they are. They are basically a string that has encoded information about a user pretty much that's that's it in a natural on real. Eventually, it's used when sending FBI calls its usedto a company and epoch also that the receiving the server that is receiving the A P I call can assess it to see if this token is valid. If the information in this talk and or this string has information that can validate that, this is going from a legitimate source. So the whole point of Jason Webb tokens as it relates the user authentication is that when we want to secure an A p I based on the user that is calling it, we can use Jason Webb tokens to say that when you make a call toe, you know, authenticate yourself, I'm going to give you a token. And every time you make any other cards or somewhere that you need to be authenticated, you can just show me this token on. I'll give you passage. We can set experience Shin dates on these tokens so that if I've been using a token all day on expiry ation time is said to maybe one day are maybe three hours. That means on the third hour or the 4th 0 R one minute after the third over Seems to give me this token. If I try to use this token again, I am no unauthorized, and I need toe authenticate again to get a new tokens. So that's the whole point off. Jason Webb tokens. So once again, a user is going to make do some operation that is going to trigger over FBI on. We're expecting to see that this call to the A P A. Has a token. If it doesn't, then we're going to tell this person that need toe authenticate themselves. They're not authorized. If we they do authenticate, we're going to give them a token with an experience shin date on, then as long as they're using this token, they can use our a p i n point. So usually the client will store this token until it we tell it. It's expressed, and it will try to get a new one. So that's all that Or relationship works around nowhere. Building the A P. This is the back in on. Later on, we'll build a client's toe much what we have put into our FBI. All right, so that's enough chatter. And in off theory, let's get into some off the practical. So in this same users controller that we just constructed, I'm going to put in another private function. So I'm going to say private and then making this one seeing on it's going to be a task that will return us string on. Then I want to call this one generates Jason we're talking on. Then I'm going to tell you that it must take a parameter off type identity user. All right, on, then, What I'm going to do is so it will return a string, but I'm going toe put the function cause somewhere appear so I just read the form some call while I'm at it. So after we phoned the user, So we got the user object. What I'm going to do here, you save our to can string. So this dysfunction is generating that Jason Webb Token and returning that string, right? Someone to say token string is equal to await On this phone call on we're passing in that user object rights so that user information will go in. No, let us flesh out this generate. Jason, we're talking. So there are a few things that I'm going to be done here. Um, on some of these things involve configurations that are not here, so I'm just want to see return a blank string for No, I just stopped. He's the the anxieties for dysfunction on. Then what we want to do with our Jason. What talking is we want to give it a key, so want to give it some value that is always going to be used. Like what we call assaults when you're generating a password. So in the app settings, not Jason underneath alone hosts understand to press comma on. Then I'm going to create a new conflict section. I'm going to call it G w t. All right. And then I say colon and then open up a new pair of curly braces on. Then we have. So you see that this Well, this is a Jason file So if we've been writing Jason or looking and Jason for a while, No. So it's the same kind of formats. Sochi Colon on the value on. Then we have another one that we're going to call Issuer on a cool on Andi value. Right? So I will include documentation on all of these requirements for JWT. Um, what Jason Webb tokens to be set up in dot net core. Some of these things you have to read and understand, and you may know, memorize top, but at least you have some guidance. All right, so for the key, I'm going to use ah, static strings. I'm going to also include this static string on is just ah generated. Do I devalue? Um, So the thing is, you don't want to use a key. That is to Schardt. I think when you use a key that is to Schardt, it will give you on air saying that the key is not secure enough, so to speak. So go. It is a perfect kind of value to use because one it's not something that somebody can just look at your court and memorize the key on. It's not something you can memorize either, But it is, You know, it's unique enough, and it is long enough to meet the security requirements, so I would have face that it are included. It with The resource is for this video. Say can reuse it. Or I can just find somebody can even probably go into the database and copy one of those user ID's and use their That's fine. And then, for issuer, I will just write test dot com. So for no, like over just developing we can use to stop calm when we deploy will probably want to change that like a more sensible domain, right? So this is who is issuing that? JWT? Pretty much so. All of that information is used when generating this talk and string. No. Now we're done with the up settings that Jason we need to g o on get a library. Someone directly go to manage to get packages on, then under Bro's were just going to search for JWT beer. So when we do that, we should see Microsoft DOT is being a core authentication. JWT beer. All right, so we can go ahead with that and once you have that include, well I tried it with the include pre release that I really didn't work for me. Um, it men our for your based on the version off dot net core cause I think that went up by some increments. So we can antic include pre release and just get the stable version. All right, so let's just get that stable. So I'm just on ticking. Include pre release. And I'm getting this stable version on I'm including it in my project, agreeing to anything. And then once it is finished downloading, we need to head over to our start up, not CS file on. Start setting up some configurations. Eso start off dot CS on. We go over to our conficker Services section on then right above the slugger gin configuration Filing with start writing services dot Add authentication. Sorry. That's a comma Authentication. Andi inside off the parent this season. What to say? JWT Beerer defaults, right. Docked authentication. Skeel, go to the next line, then I'm going to say dot odd jwt beer and then we're going toe fresh out some options, understand? To see or on dinar little lamb, the expression looking arrow and then to curly braces and a semi colon. So I'm just closing that. All right, Now and then I want to break the line here. And they were going to start writing in some options, someone to say or not. Token validation parameters are and know we're going to be seeing, um, defining some parameters by which we will obviously validate whatever talking is coming in so talking, it's going to be equal to new toe new token validation parameters. And we're initializing a new objects. And I think this is saying that I need to include something. So I included it on. Let me just put a cynical and at the end, off that brace. Alright, So first option is validate issuer on that one is true. Want to make sure that the issuer is violated? Next is validate audience, and that's also true. Then we validate the lifetime, so want to make sure that it's, you know, valid for the period that we said it should be voted for. We want to validate the issue are signing key. Then we get to the point where we say, Okay, who is the valid issuer? So I'm going to say a violent issuer is Whoever I said it is according to my, um, configuration and upsetting something. Get the configuration for JWT with the value issuer, our value office you're on. Remember that we said this year to be test up calm, right? So I mean, at this point, it's fairly inconsequential. When you go public, though, it will play a bigger part. And then the next one is valid audience and that's will also be the value off the issuer. Nor the last line is the issue or signing key. All right, and then that no is going to say what was the key. And I want to in court it. So I think I need to include something foreign cording here. So it is saying that the signing key will be, um, symmetric security key, often in corded ID version off whatever value we put out the key. So remember that the longer the key, the better. I'm sure there's a length limit, but I I'm for a commending that you use a good value right there. All right, so that sums up O r con figuration for our We're talking at least right here. I know if I missed anything, you will definitely come on later on. So let's proceed with this. Andi, you can, you know, take some time. Look at it. Um, Andi, once again, the further reading Well, kind off guide us to what each of these configurations are. Options are which ones you could actually live without on. Do you know why they're necessary? No. Moving on. We're going to go back to our users. Controller Goto our function where we generate these token strings on. Then my first line is going to say, Well, I think I need to include some conflicts, so I need to inject dependency for the configuration file. So I'm just going to see private I con figuration off course. It should be read only and then after include something here. All right, well, I think I just included the wrong the wrong conferees. Let me undo, and then let me try that again. So it's not the autumn upper configuration that we want. The one this one, the Microsoft Extension's configuration. There we go on. Then I'm just going to plug it in as a dependency and initialize it on DSO No, we have access to the Khan feeds. So about two or function toe generate the Jason Key. So I'm going to start off with a variable called security Key on then this is going to be equal to a new symmetric security key. You see, if I think after type of toads on, then I think I have to include something. So Elton enter on, then. I just include that library accordingly. So new is new symmetric security key on. Then this is actually going to look just like this land in start ups. So I'm actually just going to copy this so I don't have to type it all loads on them. Wouldn't just pieced. It's here. So that's our new security key. Um, and then off course, this would no be instead off the hard word configuration. I have the dependency for configuration. So this would be underscore conflict. All right, on then I needing include the missing before encoding. All right, that's it. So the symmetry symmetric security key makes we have our credentials, and that's equal toe new signing, signing credentials. All right, on, then, this is going to have the security key that we just created on. Then I'm going to say we're using a security Calgary them or off all the security algorithms I'm using the each mock shot. 256 All right, so we're seeing that we're generating the security key using that key on. Then we want the credentials toe. Have some Hush, right. So we're hushing that right there. Next, I'm going toe do what we call creams. So you would have seen a table called Cleans. And the claim is really simple. Claim is saying that what is your information? Who are you claiming to be? Did explain that in the early parts about what the JWT has in its data. So we can we have the opportunity to actually creates the creams that we want to include in this stream. So I'm going to create a list I want to say Vier claims is equal toe a new list off type, clean cause claim is ah, a natural built in data type. All right, Andi do need to include some system that security that claims library just put a cynical and there on that, I'm going to say give me a nuclear bomb. All right, on then. I'm going to see J w t registered O. C register claim names. So the Gentleman T library gives us all off the the potential claims that we can make inside off a talking. All right, So when we get the register, claim names, I can say dot and then you'll see them looking kind off obscure, but and some of the makes sense against the family Name given name. Gender studies are all of the bits of information that you can include in the token, so that when somebody gets this token after user has authenticated that talk and tells them all of this information. So it's actually a nice, more secure and hushed way off providing information back to the claims, right? So the first when I want is sub Andi. I'm going to say I want SoBe have the value off the user sermon, but I would posit an identity user user dot email. So So it is going toe holds the user's email. All right, next on. But that's just a new claims. Instead of writing toe a lot again, there's going to duplicate that line on. Then the next one would be g a t. I. All right on then, for this one, I'm going to give them. Ah, kind of static, but well generated good values. A new good on. Then I'm going to put it to string to appease all the data types required. S a nuclear must have the type on the value, right on value must be a string. So we have to get the good on. Then give it the history. Next I'm going to have a mother claims. So this one is going to be new team. And then the reason typing this in order not duplicating that this one is going to be a claim types. All right, so that's the least off clean types. And this is going to be named identity fire. So I think I need to include something here. So I just go out and enter Onda. That's all us. It's claimed types, not creams types, right. Claim tag Spelling is important, guys. All right, so and then I went to see a user. That's I d. All right, so that is the identifier for the user. So after that, I have built up all off my list off, cleans on, then I'm also going to get the rules, so I want the rules that this user has so virals. So the thing is that I use I cannot multiple roles even though we have some users and ultimately will be assigning every user toe only one roll the realities that every, um, user based authentication system Um hello, Zito or should be designed to facilitate more than one rule. So I'm just going to get all the rules anyway, so I can just say user manager not get rules is sink on. Then I just gets the rules associated with your user. All right, so I have a few claims on then. What I want to do is at the fact that the user is a part off this rule and whatever, so that we can help with our authorization. All right, then I'm going to do this line off court court, where and when to say claims dots. I need to add the rules through the list. Off cleans with that kind of editing, there's after work. A little magic, I want to say add range on. Then I'm going to see rules dot select. All right. So the cool thing about link is that on the flak and select from it on, then create. And I'm just going to say our Lambda What? I'm creating a new generic object off type cream or Well, I guess it's not generic. If it's off that claim on, then I'm going to say that I'm creating a new claim for each rule that is going to come out off this. Andi, I want claim Identity dots. Default rule. All right, so default rule claim type. That's cream type I want on. Then the value, of course, is going to be our not onda. Well, actually not are not Sorry. Just are so are passing in the value of our All right, so I was actually a street. All right, so it's actually a list of ST So it's when we get, sir. Yes. So, uh, that would have been getting objects, but we're actually just getting the rule names here, so I'm getting the rule names, which is just a list off strings on. Then I'm just saying that for each string coming back, we're creating that clean. Alright on, then Semi colon. No. After doing all off that we finally build our token somewhat to save our talking is equality. New JWT security toe can. All right on, then. I'm getting con fig on. We're looking for the issuer, someone to say J W t call on issuer. All right, Onda. So if you look at the the overlords for this function, it will take quite a few, um, parameters. So we're going to be filling in tow with this one, the fourth parameter, which is going to take quite a few values. So the first thing is the issuer. Then we need the audience, which we're going to you reuse issuer. Then we need to include the claim, so we'll just fill it out as we go. So I went out the issuer twice. So, Issuer, I understand the brake line. Coma issuer on. I just noticed that voter, not Vier. Sorry. All right, let me just break line so that everything is clear and not jumbled. Right? Koran. So issuer, issuer. And then the list off the claims. All right, on then, for every other value I'm went toe have well, the date if not before, I'm goingto have no. Then the next parameter will be the I think it's the expiry time someone to say expires. Onda Colon Andi, I'm going to set the expiry Asian time for this token to be, Let's see, two hours. So I mean, it's so off course you want to be practical with the expiration because if it expires every two hours, that means this use only to authenticate every two hours. Some people put it to one day. I'm sure you notice that some websites will keep your turn signed in for eternity and somewhere sand you would like as soon as he closed Ambrose and you really Broza and tried to go back up the sand back in, right. So I guess maybe they're using gentility and some very short time so we can say add minutes and seconds. Um, for testing purposes, I'm just going to say add minutes on a wood to say five, but it's it will expire five minutes after it has been issued, and I'm doing it this way so that we can test it totaled within the lifetime off off one of these lessons, right? So the next thing I have is signing credentials on, remember that we just created credentials. So we're just going to pass the credentials value right there as assigning credentials on then that completes our talk and generation on before a continent. See here that I have some Oh, I think I may have included a library that I didn't have to say. If you see red lines like I have here, then I don't need Microsoft. That identity, that's Jason. What tokens. So that's what I don't need, right? So once again, if you're getting the red lines like I am for the General C E jwt Sorry, registered claim names. He can just remove that using ad. It's the model dots, Jason, with tokens, all right on that should fix that error on. Then, after we've constructed our token, then we can return a more sensible value in the form off. New JWT security token handler on, then dots. And then you see right, So can on. Then we just passed off the talking. All right, so that's just going to return the stream the token as a string. So once we've gotten this token string, I'm going to include it with the response. Remember that were responding with the maybe the entire user objects, which I'm not going to do that right? No. Instead, what? I'm going to do is just return the tokens. I'm just going to see a return. Andi, I want to give it done. Actually able someone to create a generic, um, objects or token is equality. So can string. All right. So that means once a person authenticates, the response will be okay, and they will get back token. Colon took and string in the form of Jason. So then my clients should consume that. Store it on. Then for the lifetime off the token, it will hold the users information. So let's just test and see what one off those tokens will look like. All right, So I have postman up with on off my previous requests on. We know that that went off into case will limit. Try admin on, then send and then Voila. So that is what our talk instrument looks like. All right, So this token stream once again embodies all of the things that we had put in. We put in some claims for the email. The user i d generic good value were put in. If they're part off, our rule are not or which rules they're all apart off. Who is he suing? Who is um, the user, all sorts of stuff. The expiry time. So in five minutes, it would expire. So I put it to five minutes. We're not going to test that expression because you won't see it, right? No. But what we will do in the next video is we will go back on, start sitting up some authorizations on, saw the existing in points, and it will see how it works.
34. Setup Controller and Action Authorizations: you guys in this video, we're going to be setting up authorizations on our different endpoints in our authors controller on. We'll be validating or talkin functionality at the same time. So what I'm going to do is I'm going to pick a few endpoints that should have authorization on, then maybe harden want some based on the rules on. Then I lost some to be anonymous just so we can see the difference or the impact that having the beer talk and string in our requests will have. So what I'm going to do here, I'm going to say that's to get authors. I'm going to leave that alone. Some the squint support issue t get. And I'm also going to just alot anonymous. All right? That means anybody should be able to make a request on get the authors, however, in order to and I believe this one as a low anonymous. Also So these store are low anonymous. However, in order to create, I'm going to restrict Ah, I'm going toe are better. Yes. Let me. All right. Yeah. I'm sorry. I'm just I'm just doing this as I go out. So what don't want to do here is authorize someone to authorize creating on. Author. I'm trying to be as realistic as possible on. Then I'm going to say all right, someone to authorize this one. And I want to specify the rules. So I can't say author as open and close brace on the only rules that I want so I can see rules is equal to notice it seeing rules. So you have one string, but you can come on separate all of the rules that are alone, right? So if you have maybe, like, we have two rolls of custom and web administrators. So here I'm saying that the only rule authorized to hit this endpoint is an administrator on then what I'm going to do. So that's four create. And then what I'm going to do is for the update. I'm going toe authorize both. All right. So I'm seeing either Allchin on then for delete on this. This is kind of against the norm. I'm with yellow. The only customers to delete authors are it That's kind off against the norm, but lets us justice it out and see how it works out for us. All right, so I went into debug mode and I have a postman and then we're going to test also off these endpoints. So I'm going to try with the gets the first get where I should be able to get all authors send the request. Andi, I got all authors, so I actually created another one in the past, but yes, So I got all authors. We have two authors and in the same way that I didn't specify any authorization on top off the get by i d. We get the author with the I D to No, I specified. That's and I'll just go back and make sure that create, let me find create So create requires an administrator. So let's see what happens when I attempt the create. So I have got a Bunton. That's my author that I'm trying to create and you see here I'm getting a 401 on authorized because I just said that that somebody has to be authorized in order to get past that's point right? So I'm just going to go back to my, um, authentication and instead of authenticating with the user and went to try customer one, so I'm not going to be admitted with use customer one send on. Then I retrieved the talkin right. So in order to use this talk and after take the value and the value is everything that's inside the quotation marks, not the quotation marks. So I have as far as the configurations go, this token is valid for five minutes I'm going to go back to my request. The authors Right on. Then I'm going to include this in the parameters for my request. So I go to authorizations. Right? So you have part. I'm sorry. Not problems but authorizations, even though adding it here will end up as a prime minister. Adult. But it's easier here, so I goto authorization on. Then I choose bearer token on then the value of Putin's. They can see here that Adebayor talking in there from one of my previous activities and putting in this new token on then I can click send So what happens that it includes this token in the request on noticed? This is no seeing four or three forbidden. So we are for a one on authoress which means that you are not authenticated. You cannot interact with versus four or three which really means that, um, you know, they're almost used interchangeably, but four or three means that you might be authenticated, but you're not authorized. Right? So that's the difference between fourth round for one. So it sees the bearer token. But then the clean information in the bearer token didn't tell it that it's an administrator, which is correct because we just loved in as customer. So let me try again with admission, and I'm going to get that value. So what I'm going to do is I'm going to write down this talk in value. So the first talk and that I got from the customer, I just made note of it because remember, it was a five minute expiry Asian time, right? So I'm going to reuse it on a legitimate customer, um, operation. And then we see if it works, I'm sure five minutes would have the love spread that time. Anyhow, this is an admin Tokens. Let me get this admin talkin. All right, I notice there's no information here that tells if it's an admin talking our customer talking. It's just a token right now. I want to include this one with the request on, then click Send. Andi lets us see what happens on getting a for bidden limit. Go back and see something. Ah, here's why spelling matters are left open. I had many straight or so let me get out off debug mode current that's spilling at ministry tour on Let's try that again. All right, so we're back in debug mode and let me try that again. Andi, I send with the token on. We're getting back off four or three. So I think I might have to change some configuration with the claims. Um, so when they get out off the boat moored and then just to make sure that authorization works without do is remove the rules part on, go back into debug more than test the same token just with the author s. So that means it doesn't matter which user as as a token is present with, um, that's not expired, it should work. And then that will confirm if it's, ah, claim related issue. So if I try it again to create this new author, there we go. So it works. So it is something with the claims on the rules. All right, so if I take all the authorization, it's there. Say no off and then try to call that in point again. Then we get that for one unauthorized. But the moment I put in the bearer token on, it's a valid talking. It will work. So let's just go back. Get out of depo Mood on review O R. Claims six on in or users controller. All right, so what I'm going to do here is set fabric points on my land 82 after I get the rules just to make sure that the rules are coming back properly. So I went to going to debunk more than two a log in attempts with Postman for the admin click send on. Then I said the break points and when it hits said break points, we look and we see no Rose coming back. So that's the problem, right? So there's Norrell coming back for the admin user, and I think I know why. Um so if you remember when we were creating the user in the previous video at misspelled administrator or so what happened is that it didn't attempt to create the user again, and as a result, it didn't associate the user with the rule, So I'm going to do that manually. Andi. I just go into the database so you can go into log into your SQL Server. I still have mine from previous examples on There's a table here that says SP Net user rules, right? So if I go to any top 200 it will allow me to just enter the user i d and the associated role I d. So if I go into rules and I just wreck, click at the top 200 again and then I see that administrator rule as an I d. Right. So just copy that I d on. Then I'll put it as a rule, i d. And then I want the user role for the users. So I think of users open. Somewhere on there is the admin user. I decide this copy that value on put it as the user I d press aboard, own on it will committed to the database. So, no, I have associate ID my admin user with the rules. So that's what I was seeing that you know, I could have the user idea in another role. Ideas that administrator could be both sorry. This admin user could be both administrator and customer if I wanted it designed that way. Any hole, No, that's We know that no rule is coming back and that is a part of a problem. It wasn't included in the claim, so let's try that again. So I'm going toe use postman, do another log in attempts to get a new token. And then I looked back in the rules and we see No, that our role is coming back. All right, so you probably didn't have that that, er that I was having because you spelt correctly from the get go. So that's fine. Ciders pushed through and validates that it's working. So now we're getting back. The claim on this token looks much bigger. This string looks much bigger than it looked before. So the claim, the talkin sorry, their roles weren't being included in the talkin string. So let me go back to my creation on Put in My New Bear, a string which is bigger. So I'll always know that somewhere information is in it on. I'll change the author information. Let me try Hilton Burton. All right, on, then. Let me send a little See weapons on. There we go. So we see that the rule actually played a huge part in knowing whether or not this user is author as security. All the action, right? So when the role was not in the in the token, the claim couldn't verify. Right? So, no, we can see that it is working. Well, years was probably working already, so I'm just catching up. If yours was working before mind, then you're under attract. Congratulations. So, no, we can go ahead and test with the other endpoints and other tokens. So that was the Oh, what? I really did not finish it up. So let me. I just realized I didn't really validate it. So let me put back the part that says that the rules equal toe administrator matrices Bill administrator properly on. Let me try that again. So Noah Puente validates that it's working. Now, another author. This one is going to be my fuel. Uh, Johnson. All right, on. Then I click. Send Andi. It's working. All right. So no. Our claim off being on administrators included in the bearer token. So when it hits the authorized authorized only the administrator to get by. So no, I'm going to try one. So we see that the worst of the administrator. So I'm pretty sure is going to work with the update just the same way I'm going to try one with the administrator. Transit. Carry out that delete when only customers are users in the customer role. Arlo to do that. So let me just validate that also. So let me just find the put on then. I'm going to modify and say, All right, I just modify author toe, have this information certainly. Just modify this request a bit on. Then put in my author Azi shown Bira talking with the administrators. Token on, then send on it rejected me saying that I'm forbidden. So let me log in as customer this time and just retrieve a customer token. All right, on then. Let me just get this string on. I believe that we were in deletes was it? I think we're no word supposed leading, right? I think I was modified to put but actually should be deleting. So let me try and delete. As the customers are authorized with my Barrett took and put in the customer token on deleting also with the I d to All right, That's when I would have been anything but we You can test it if you want, but I'm pretty sure it's going to work with either Use a token but are so let me just under this first, let me try again with the admin tokens. So this is the admin token string. Let me send on. I'm forbidden so the admin cannot delete. Let me try again with the customer token Onda We see two or four no content because the delete was successful so and I don't get again, they get its public allowing anonymous no author with idee 23456 and seven However are there on. So that is how you use JWT talkin stir, You know, see if guard your in points on make sure that whoever is interacting with them has the authority to do so
35. Review and Add Changes to GitHub: Hey, guys, welcome back in this video, we're just going to be reviewing what we did in this section and checking or changes in to get up. So what we did was to implement our Jason Webb tokens authentication, and we did out using a combination off core identity and some built in libraries from dot net core for JWT authentication. So we made a few changes to a few files. We created a new controller called Users Controller with a log in action. Added some logging, um, toe, you know, love the actions. What's happening? Wherever off course, every actual, every action should meet a certain standard on. So we made sure that it was well documented. Onda logging was in place and air handling. We also created dysfunction to generate the Web token, which pulled on information from quite a few places, namely, our conflict file, which host AKI Onda. We generated some claims and we added the rules. So the claims right and we'll discuss that, you know, claims are basically bits off information that describe who you are and what you're allowed to do. So all of that information was included in one I'm going to say simple string, but one long hush off a string that contained all of that information. I also realized that by adding the authorized notations to certain actions we could control who could interact with the endpoint. So we allowed anonymous on some. But then we tend the grip where we said only the administrator can create on. Then we said only the customer could update on. Only the customer could delete. So in your in plain view, I'm actually just going toe remove all of these. Actually, I'm going to I'm going toe. Only authorize administrator. So Administrator is going to be the only person who can delete. I'm going to a lonely administrators toe update someone to remove the customer from their on going toe alot on the administrators to create. But then I'm going toe all only authenticated customers to be able to view someone to put the same authorize role, but well, customers, onda and administrators, so both customers and administrators can get the values someone to put that on the get with a value on the generic overall get so only authenticated person should be ableto interact with anything inside off the, um, enter controller so by just adding one global authorizing me is that even if I I don't know , the end point and I neglect putting on the rules. All right. So, actually, since I only have two worlds, this is really not necessary ratified three year olds and it would be necessary if I wanted to prevent a certain rule from doing it. So just by seeing authorized on the whole controller, I don't have to see authorized here on I really don't have to say author is here again, right? Because then whoever is going to be interacting with anything instead of the controller most be authenticated on. Then it becomes more strict where we say only author, as administrators can do certain things afterwards. So that is so you can go about adding security, toe your endpoints. All right, so I did that for authors, and I'm going to just do it for books, the beer before I check in, some would authorize this entire controller rights and then include what I need to include on. Then I'm dispensing a copy the line where authorized for only administrators so that I don't have to type it all out again on someone's author as only an administrator to create a new book. Only an administrator can. Can I get a book on Dolan? Administrator can delete a book. All right. But then, as far as the control is concerned, only authorized persons can access anything inside off the controller. Before all of this was possible, however, we did the scaffolding activity where we executed our command, which was update database, which ruled out, um, new tables into our existing database on I'll just bring up the database management system to show you that we got rules our user rules. So these stop six or seven tables were all generated by record on 1/4 identities engine on . They are all in developed in helping us to authenticate on manage or users and rules. We also added, ah few lines to our start up where we told our start off that we are going to be using JWT beer tokens on This is the kind of information that we want included are validator. You know, these are just some options. It's all off. This court will be. I need to get all right. No. On blast woman and no muse lease were also added a C data class where we created some sample users from the get cool. So spelling is important because I ran into trouble because I spelt administrator wrong at one point. So this step didn't get run as it should have been. So I'm going to check in. No on. I'm going to just right click click comets on. We write our message, which makes it, you know, as clear as possible to whoever is going to be looking at our code on. Then I just commit all on the sink on. Then once that is done, you can always go to get home and validate that you were sore. School is no baited and as always, I would include the source code for this section in the resource is below.
36. Create and Understand Blazor Project Structure: Hey, guys, in this new section, we're going to start building all the you white, our company over FBI on our technology. Off choice is Microsoft's Web assembly based technology called Blazer. No Blazer is fairly new, and it's built on top off the dot net core. Andi. Summaries of principles are in there, but it is a great new technology that allows you to kind off, not need to go to react or angular in order to get that lightweight. JavaScript based U Y on it is still very dot net, So we still get to court C sharp while enjoying the benefits of having a very reactive user interface to go over fire to get this project started. What we're going to do is in our existing project, we're just going toe. Um, well, I'm just going to collapse the bookstore ap I project and create a new project inside off the solution so you can have multiple projects in one solution, and I just right click the solution. Click add click New project on then from the list off project templates. You should see blazer. If you don't see blazer, really, you can just type and search for blazer. And if, after all that you still don't see, then you can also go ahead and install more tools and features. Or you may need to don't load the binaries, which are actually pockets with the dot net core 3.1 sdk. So I fear this far into the product. I really don't that you won't be seeing it, so I'll just continue. If you don't see three Children, me and we can work on it together. Someone to select blazer up as my projects templates and then I'm going to give it a name. I'm going to call it Bookstore Dashi Y No, just the point of that. Sometimes when people are making projects that they know well, they're making, they're going to be building an application that they know we'll have multiple projects. Sometimes what they do is they create the solution, give it a generic name on then the projects are more specific. So here you can see, I kind of brought that principle where I created the initial project with one name. And so the solution on the first project got that name. But then I'm introducing another project in tow, a solution called bookstore Dash FBI So it can When? I because I really like that I can see where merely to confusions. I just went through that. Just know. So you can appreciate that. That is why the solution on one off the products of the same name. But obviously it could have been refined a bit more. Right, So just continue. I have a new project bookstore dash, you I and then I go ahead and click creates. I know they're going to ask me which version or which features. Sorry, I want to include So I don't want any authentication building. Um, I'll leave on everything else and I'll just go ahead and click. Create all rights are new. Project is here on. You can see the green plus because, well, it's new, So it's not in ghetto as yet, So when you just look at this for the structure, I'm sure you're going to have other toe these a moment. Andi. Yes, you are right. It looks just like our razor pages project that we started off with that we slowly transformed into the a pair project on. Notwithstanding that it has some common files that are phoned in every dot net core project template that we've been looking at up to. No. All right, So you have your standard start up, That's yes. And this is take a look at that where the start off functions are pretty much the same way of or start up web. Or will we have or constructor we have or configuration a Web or configure services? All right, configure services. And we have configure Alright on. Then you can see know that different middle wares have been added. So in this situation we have services that arteries of pages and at a server side blazer Right on, then don't. Here. You see that you have, Ah, a few different options. What? The point is that dotnet core provides a basis on then, based on what you want, old often application, you can go ahead and add the required services on get them bootstrapped into the start off the application. So not records like a blank canvas. And based on what you put in your startup that says you're forming an identity off your application and its overall behavior and capabilities so you can take some time and look at the different ones and probably compare it with the start of that CS from our a p. I projects just to see the different ones at least not the ones that we built in, but the different functions that are being initialized. So here, inside off the use endpoints have mob controllers on. I believe that's a change that we made on. Then over here it's really mop blazer, hope on mop father pit. So you see, it's like differences, but then everything else proceeding that is the same The same issue tps three direction. We remove static faster, more a p I. But routing is there. And if you look, you see use rotating on the https three direction we put in these on We're using these because we have in our authentication and authorization once again the same dot net core just different behaviors based on what you initialize. No moving on from that we still have the program that CS which does pretty much the same thing we still have our upsetting is that Jason which out of the box looks pretty much the same way We have shared so shared on defence style. Can the files you notice that they have different extensions. So if you're usedto NBC, then you have CS that dot CS html on def. You have razor than you're going to see docked sensational with a court behind file nowhere . Looking at blazer on the extension is not Reser. So that might look oh to you because, you know, you have razor pages. You would have thought Tereza Peaches would have that extension, but they don't. So blazer pages have read batteries as the extension. I'm just going to take some time and go through each file just to show you what the facts are therefore out of the box. So have up No reason. This has some basic configurations telling us, you know, the, um, like some raw voting for errors there. All right, You don't have to change anything on this unless you really want to change something. You can go to imports, and that's no has, like a global Duric tree for all of the libraries that will be used in your different, um, views. So as we go along and we start putting in new name spaces and new libraries and functions and classes when you know would do the using statement in each court file in a dot CS file . If we just put it inside off the import start razor, it will be made globally accessible to every other, um Riza ph in the project. So that's what the imports fight is for. If I go into shared, you see that you have the main loads you have the nav menu on. You can see that their basic issue of files with hints off c sharp. So you always see C sharp chord with an at sign. Right? So here you see that sign cord on. Then this is literally just see sharp board. All of that is the same c sharp that we've been writing upon to know. And that's what makes please are so great you don't have to mix and much with too much javascript. No, not that JavaScript is bad. But at least when they recording on one stock, it's easier to identify where things might go wrong. Because all the court kind of looks very similar across the board. Right. So this is our enough menu on Well, you can see here we have three, um, out of the box links right now. I'm going to spend much time there. We also have pages, so pages would be where our custom pages will go. So, as always, have the index speech, which is just saying hello world on something else. You'll also notice that in addition to our regular HTML tiles, you see some custom tags that are, um, basically talks to give us razor components in the project. Right? You'll see in fetch data, you'll say a bit more C sharp going on. So firstly defined the page on, then you give it the address. I'm saying that this is a page on the addresses slash fetch data. Since I want to get there, that's what I should type right on. Then you'll see a using statement here. So, like I said, you can include the using statement on the page itself, or you could put it in imports and it would be globally accessible. Um, and then you see, inject here. So we've been doing quite a bit off dependency injection upon to know this is dependency injection in the Blazer view. So when we design auto repositories and our custom services, we'll just need to say inject, call the service by its name. And then we can start using it just the same way that we're to initialize it in our controllers and then start using it. All right, on the issue. Militiamen. No, you see at sign at, Come on, your statements. Where it seeing if this bearable is no. Then just show this text. Otherwise generate the table on the stable is going toe have roles being generated for each item inside off this list. Right? So forecasts appears a list on forecasts exists because in the cord, it was declared on then on initialized a sink. So they have a built in initialized function where they say, when the pages initialized. I wanted to go on, go fill forecasts with something. So we're forecast service that get forecast a sink. I miss taking apartments off date time? No. All right, so pretty much when we start building it out, this is what is going to look like when we want to get stuff. We're going to have our service injected, and we're going to say service our report dot whichever function it is on, then it's going to retrieve it, put it in the list, and then we load accordingly. Right? Um and then So these are the sample pages. As soon run the application. Assure you what the samples are A boat. I just wanted to have ah, look and feel off the different chord elements in data. So we get a folder called Data and Data, as we know represents. You know, the whatever data will be passing through our models off the actual data tables. Right. So this data, it's used loosely. We can change it to models Onda as we go along with fine on appropriate name or the appropriate things to store under data, considering that this is a blazer up that is reading from an FBI. So that means this blazer up is not going to directly interact with our database is the only thing you will know about a data source is the fact that we told it or will be telling it. Get your information from the A P I or please information collected in the form in the hands off the AP and let the FBI do the wrist. Right? So that is why we are building this decoupled solution where the AP handles all off the brokerage with the database on, then any other client application doesn't have to store its own date. I can just use the FBI to carry out whatever operations so that this place up could have easily been an angular up I react up of you, Jase up or even a mobile up. It doesn't really matter. You can just sit on top off and talk to the FBI. So moving on, I'll just take a quick look inside off the water. So we have weather forecasts and you see, here we have the dates, the temperature C temperature f on summer on, def. You back in the fetch data file, you'll see that that's what was being printed. Were forecast that dates the string temperatures C and F on the summary. Right? So that means this is the model off the data that is being represented inside off this right on, then the service is pretty much what we've been building in our repository where it's calling. So this is just an itch initialized or getting filling up a list off summaries on, then this is no going to say generate a random list off forecasts. That's always seem so. Give me a random list. Off type weather forecasts, which is the data class he just looked at on fill the properties with some random values on . Then that is what is being returned. So basically, this is being returned in tow. This call our this variable on then. So it saying initially clearly won't have any data, but once it has data, please populates the table on. There is really nothing else in this in this project that I need to look at. W w Route has been ecstatic. Fire so bootstrap and iconic, um, funds on the right number one to run this application so we can see. So right now it's saying Boots, bookstore, dash a p a. That is Armenian project. Right? So if I want to switch the mean project, I can always right click the project that I want on. Say, set, start off project or sit as start of project. Or I can use this drop down appear and just change it to the one that I intend to be. It's what Once it's the start of project, it will always be in bolt on. Then I'm going to run this application so we can preview it. All right, So this is our boat off the box, please. Air application against he gives us. Ah, nice looking you. I right out of the box, Onda. We have three pages, so we have home we have counter on were fetched leaders. I'm goingto start off with French data because I really didn't look at counter. So I'm going to do, fetch date, and then we'll analyze contra together. So when I do fetch data, you see, it just loads it up. So I was hoping you would take a bit longer. Say, would get to see the loading that went to see if I can refresh the entire project. So remember that this is ah, a single ph application. So want to hit? Re fresh is literally going toe. Um, refresh the entire application. Not necessarily just the peach. All right, so when I click, fetch later. Okay. Well, it's loading too quickly for you to actually see the Lord income up on. It's really cool. So while it's getting the data, you can display something, and it will automatically with very little effort. You saw that all it needed was an statements. Any hole Let's go to counter. So counter has a button that says Quick Me on when I click, it is just going to increment on as many times as I click. It will just keep on incremental. So let us look at the core base for that. So the court base for this file is simply elegant. Firstly, we start off with the page and the address slash culture. That's where you get to it from the base URL, right? So each page quote unquote, is really a component that so they termed them. It's it's a component, and that component can have an address or it can be a partial components. Know what is happening is that you see a variable here called current cones, right? So once again, want to see the outside? You know that that c sharp inside off the HTML are in the razor view, right? Or raise their syntax. However you want to term, it's then we have our button, which is ah, classic button with some, um, boots shop classes on. Then you notice they have an at sign before on click. So we all know that JavaScript gives us these pick events are these events that can go on different elements. All I did was take off that side. And this looks like how it would look if it was JavaScript. Writes Owen. Click on. Then you just see open and close brace parentheses. Sorry on, then. It would just know that. Okay, It should look for some JavaScript function called increment. Count on. Then it would call the JavaScript here, though in Blazer, we don't need javascript Accomplish that. We can just put the outside to say, OK, this is going to be a c sharp. And if you hover over it, you'll notice that it's an event called boxes, a specialized type off event that we're specifying here and then You know, what is that? This is no highlighted. So it's going to say increments content. So it's expecting that the court section is going toe have some function called increments count. Oh, my defaults. We would have already initialized are variable. Corrine. Count on, then. You see here that it has the function increment coat? No, just think about it. Each time you click this all it's doing is doing a current count plus plus, but what you're not seeing his core that says, OK, no, that this value has changed. Go back on the update. The value here, as long as the value changes anywhere it changes inside of the court based anywhere it's being represented. It will also change. And that's what makes plays are so easy to use and so easy to create. A very responsive I'm not responsive in terms off re sizing but responsive in terms off the user experience altogether, User interferes on application. So that's a quick under to tour off her quick and dirty tore off blazer. What I'm going to do know is modify our many options because remember that we're going to be dealing with books and authors, and we'll also need some capabilities. Toe log in. I'm the register. Some want to goto our enough menu on I'm going to change or solve these links. So this one says, home I leave home alone, changed counter to see authors on our tears fetch related to save books. So off course, if I change those, I'll also need to change the trip. So there are no the waitresses just counter. It says just feet fetch data, so I just tell the truth to see authors and out of this one to see it books. So that means I need to components, um, one for authors, One for books. But then I did say that we're going to have some register and lugging features. So what I'm going to do is just create two more menu items on the This one is going to be so sorry. All right, let me take the salt. Um, I'm going to explain what that novel ing thing means I'll just take it holds for no. So we're home on then Let's say I have long in Andi. I also have a register, all right? And then I would probably want to change. Apply these icons around, know that they have the default icons. This one is list rich, dishonest. Plus, this one is home. I'm not so familiar with this library. Four icons, but I'm going to just go on a leap of faith here. And what I did was removed What came after the dashed. So I dash, I just removed, like, say, the plus on the news control space. And then because the script files, their visual studio is giving me the list off all the potential icons that I have. So let's say I want to use for long in, uh, I don't want to use of the time just looking at icon. So I find some good icons on. Don't make suggestions off course. Your idea might be different from mine, So I'm going to use a blow for the logging on. Let me see if they have a book. They have a book for register. All right, that works for me, All right? And then all I leave the close on the list. Ridge, Let's just take a look at that quickly. All right? So when this new page lords, you see, it comes up. So I think these many items are looking or the logging interests there are both highlights just like home, because the home link is supposed to have that highlighting. And right now these are pointing to anything. So they all look just like the home. Whereas I gave these addresses. So that's why you see these planets so later on that will look differently. Um, when I click one off these that I created the you see Sorry, There is nothing at the strip address because it's pointing to some resource that I have not yet created. So we'll do that later on. But for now, that's it for our introductions. A blazer. When we come back, we'll start setting up our based repository on clients so that we can start communicating with our FBI.
37. Setup HTTP Client And Service Repositories: Welcome back, guys. In this video, we're going to start doing some baseline configurations in our Blazer project name. They were going to be setting up the based repository some static endpoints on just doing some overall project settings so that we don't have to revisit these things. Oh, I already went ahead and created some folders. I have a contracts folder. I also have a service folder and our static folders. So we're going to start putting some files in them on. I'm going to start off with the contracts folder so the contracts folder is going toe have on interface file. So the strike click add on Anderson to create a class. But then it's going to be an interface, and the name is going to be I based repository. I click Add on then, as usual, which is from being a class to an interface, you're probably wondering, OK, but didn't we just do with this with the AP? Why am I going to do that again? So what we're going to be doing is setting off some standard functionality for blazer or are you up to interact with the A P I? So we already know that there are certain things that we set up on 10 points to do on those would be the current operations we create. We updates we delete on we read, right, So we have all in points to do those things. So basically, I'm just setting up some base functions that will act as proxies to talk to the A P s. So we don't have toe right those requests every single time, right? So I'm going toe, have a task that's going toe Say get right. So I have a task off type t on Then we already discussed. So I'm going to do the same kind of generic. Um there, Buster here, where I'm going to say t on were see call on class. All right, so we will see all that work Sultan in a later part. But the first function is task t on. We're getting on. Then I'm going to pass in the URL, as in the end points that I intend to get data from on the I d. So this one is for the single, um object or a single record retrieval. The next one, we have another. Get on, then this. Get is also a task, but this one is returning on. I list off type tea right on the same name gets But then this is just an overload where it's taking a string parameter which is just the URL Next up we have o r creates. So this time this one is going to be Ah bullion. So have task bull and create on We're passing in the URL on our object on then basically delete on update to look the same way with an exception for update where opiates is going tohave at third. You are certain permits or sorry for the I. D. Well, actually, we don't even need that, to be honest. So I want you to just going to take that because I really don't need that third, um, parameter so create update and delete. Look virtually the same way, all right? Oh, but deletes Takes the idea instead of the object tried to create and off the passing the object. But the lead is just taking the idea. No. After implementing the repository, I'm going toe implement the service. I'm going to call this one. Well, I called a full of service, but where is going to use the same name, and I'm going to call it base repository. All right, then. This is going to be the direct costs from our ideas. Repository. So, this one, the definition is goingto look a bit differently because then I'm going to CVS repository off Time t this time, Colon. I piece. So, no, I'm inheriting from over. Um, interferes off tap t. So the thing is, know that we're making this, um, repository obits dynamic where I don't tough toe recreate function on deck and the spots in the class on this base functionality will be done again. Sort of a class that by passing. So we didn't do this extra step in our previous repository, So we did it that way, and then I'm just showing them or generic obstruction that can be doing so I can see where t full on class. All right, on then. I have toe as usual implements the repository or the interferes. Sorry. So, no, we get our creative lead, get get on opiates from shines. No, To get this open running, I need tohave. My privates read only property and it's going to be off type I h T T p client factory. All right, so this is going to be our clan factor. That's when the handle all of our connections to the FBI and the U earlier request and I'm calling the object client. Andi, you know, you just go ahead and include any library that is going to tell you need to have on then as its customer, we have our construct. Er so this constructor just taking this is a parameter, and we're just doing our injection according the rights. So I'm just going to initialize it too. The incoming client object. So let us write our create court together. So some off the court and we're going to write is going toe repeat itself across the other . So after I write it one time, really just going to copy and paste and engine some essentials on we can move through this relatively quickly, So I'm going to start off by saying viral quest. All right, so I request is basically when or you way or or user clicks something on R u y on that something would be the author speech. So we're going to send a request to the FBI, right? So I'm building the request. I'm saying Vira quest is equal to new http request message right on, then to form this message. And if I just look at the overlords for this function, I see that they have the http method comma the request, Earl. Right. So I'm going to say it's TTP method dots. And then I have accessed all off the methods that would have built in our A p. I signed Love Post writes Remember, create uses the method post on that. This is where documentation comes into play. Because then the documentation would have told the developer off the U Y for informed you, the developer of the U A building on top of an existing FBI. What method to use when creating south, seeing, creating creation in points using get already Onda. We've seen them with post. So you can very based on design on then the next parameter would be the u R l, which is the girl coming in through the function call. All right, After that, we see if the object that was fasting is no. All right, then we don't want to do anything on notice. This is ah, task returning our bulls, so I just return falls. Meaning this was a failed attempt are invalid atoms. All right, Next. If that passes the test, I'm going to go ahead and see request dots content. So much. Build the content for the request and I went to see is equality new string content on the inside of the stream content. We need to convert to Jason. So I'm going to say Jason convert. All right on. I believe I need to include a library for this. Just included quickly on that is new turn soft. So I need a library called Newton Soft Jason, which I don't think is part off the package by default so I could have gone to new get, But right here, they're saying, Well, you can just find and install the latest version. So this will automatically go to new get let new getting started for me on. There you go. It's spending the latest version so you can give it some time, and then once it's done, you see that color changes, right? So, Jason, convert dot on then I want to serialize the object on. Then I'm going to pass in seats asking for object value or B J. So BJ represents the data that came or the payload that needs to be posted right next. We're going to save our client is equal to my http client object, which is underscore clients that creates clients. So I'm creating our clans on. Then I'm going to say http response message response is equal to await on. Then I went to see the clients the client object that we just created. I want to say that I want you toe send the message. A synchronously I sent this request is synchronously. So then what's going to do is going to go on. Then send the request on, then return it here. No use a strongly typed, um, you know, use fire here because this mean the result of this there. It's gotta quit. Very. So you want to be very, very all right here. As opposed to just seeing vier for builders, right? Some seeing I want on issue TP response. Miss it and we can no see once I get the response, I can check. Sorry. Someone to say if response dots status for and if I just look at this the response I can see all that comes back with a response. I get his status. Score is success that are scored. Um, you get about the start of school that were already reviewed. Set. The schools can be 224 etcetera, etcetera. So, based on the status school, that is in the documentation, the one that's being returned. You want to check? Is it that one that you got back? So in this case, you know that with create based on our knowledge of the A p I that we just build our have been building building. Sorry. Um, we should get back at two or four. So if response start that status scored is equivalent to Andi, I think I can say system that net that started scored that on that. I'm just going to look for create Ted. All right, So if you want to temper, put this into using space, so if it is equal to created, then you can return true, or let me see. Just return. True. All right, on, then. Otherwise, we can just return falls. So if all else fails, we just returned falls. Now. Some red lines here on that is because I didn't implement them as a sink or implement the function as a sink. There we go. So just remember to put the A sink because it's not thereby defaults, all right? No, pretty much, at least for no, this is what all of our requests will find. A look like the request on then the response. Um, you know whether it was a good response, our body response. Essentially, that's going to be the core base. So what's really happening here is that when from the clients the person clicks create, I need to make sure our the person's creating a record and they click Submit. I need to write code from my clients to see that when the person click, submit on on this form for authors for argument. See, I want to make sure passing the authors and points the information being submitted antes being used here, so it's very generic, so the same code base is going to you use for author for books on. If you introduce other tables on the line, it's just tea. So that's that generic and obstruct. We offer presenting any class type. So then it's going to say I'm winter create a request. And I know this is a create, so it's posed on. Then I wanted to try and create against this girl on. Then, you know, we just your cursor checked on. Then I want the content off the request to be the content off the object coming in on then No, we're going to pass it on, wait for the response and then parse The response to see is that the response that means it was successful, if not been returned follows meaning the operation was not successful. All right, no power update is going to look fairly similar to this. Or let me just go down the line. So let's look at the delete. So the leads. As I said, a lot of the court will be reused but then deleted start off different. So delete is only getting on I d and the girl. So I'm first going to check if the I d make sense. So if the idea is less than one right, then return falls. Meaning that operation that attempted on operation field. Let me just put in the casing from no one. So that's you don't have any errors coming up along the way. All right, so the idea is is equal in tow. Are sorry. Less than one, then that's false. That's a Philistines. Then I can just copy this line where I build the requests. I'm just want to copy that. So I'm going to save I request. But then this time it's a delete. So the FCT method is the needs, and then we're passing in the u R l plus the i d. All right, so remember that are you? Earl needs to be in the http method off delete, but then it takes the u r l slash the i d. Number. So that's all we're doing here. We're just seeing send the response or service in the request with the method, The leads to the earl passing in the ideas up as part of the string. Right. Then we do the same thing pretty much where we build our clients on. Then we wait for the response. I'm just going to copy those two lines instead of taking them all over based on. Then we check if the starters scored. So basically, all off that is almost the same. Except oh, are startle school that we're checking for after delete is not created. But it is a tool for I believe it. Waas, which is no content, right? So we're checking if we get a no content response, then we know that it was successful, Andi. Otherwise we just returned for us because it was a failure. But you see everything after the if statement, pretty much the same. Except fine tuning these two so positive you here and try and fill out the rest on. Then when you replay, we'll go through it together. All right, so let's go through the get together. So the request looks fairly the same. Except the method is Get on. We're passing in the URL close the i d. We build our clients, we get our SINDOOR request. Get the response on, then I'm checking. If the status code is okay, then the content. So I want to contents remember that it gets means that I want to get back some information , so I know need the content, right? So far, content is equal to on. Then I'm just going to say response that content read a string Easy. Some, you know? Okay, if you didn't get this far and it didn't, you know, figure what goes inside of the statement. Considering that it's not a bully and that's being returned, then that's fine. I mean, as long as you got the 1st 3 lines properly here on the right track. So after we really dust re a think, then we return the converted. The serialized object on basic. Alicia's going to mop it against whatever data class tea is at the time. Onda. We have content right on. Then otherwise were just returning notes. So that means nothing came back moving on to the other gets whoever getting the list, Um, the first reliance for me and fairly the same, except no idea in the URL parts. This time on, then it's pretty much the same thing. I'm just going to check and make sure I got on OK, response the content. We read it as string and then we return a Jason converted PC, relies least off type T. All right, so those two, um, you can dispose the video on take off those few lines that you may not have had no problem moving on to the update. The update. It looks fairly similar toe they create. Accept the request that content pirates is going to be a bit different on golf course. I want to change, including here. System that text right, though that inclusion. So this is what I hope data look like. We just break the line because that's wearing off the screen on, then the method that we're using its put. So there's a difference city input on patch we developed using put. But there's also a method called Patch on both of these 100 up days. The difference, however, is that the put will it's like a hybrid. The boat will say, Well, whatever info you sent over, I'm going toe use it to replace the record that is there so similar to one we're testing or update and I had a fully populated record. But then I only put back some information, right? Literally. It's put back the some information and anything I didn't put it. Thus defaulted the values. So the put will replace the info that's there with the new information, whereas the patch will actually map what needs to be replaced on, then just replace that. But everything else remains intact, so that's the difference between a put on the patch. The put will also create the record if it's not there. So if I said I wanted to update author with I d 100 there's no also with idea 100 then it will put a new also with the information accordingly. So moving on that is our base configuration for our well based repository or just the point of that. This is just another overload of the string content where you can be a bit more explicit with the including on the media attack being sent over. Um, but it's the same function that's being used in our create. All right, so in our creates, I just didn't use that overload, so you can try it with and without and let me know how it works out. But that's the court. So that's it for setting off the base repository. The next thing I'm going to do is set up some static values that we're going to be using through our development. So I'm just going to right click static on with the ad class on Number is going to call it in points so and points all right on this is just one technique off setting off these static endpoints. Some people them in the configuration. But the reality is that many times when you watched you tours on hold to call and FBI you see them type of the baby girl each time and then put on the wrist off the the URL. No. What happens is that if that base you are ill or not, don't mean your changes. Then if you had it 50 times in your corner, went up to change it 50 times, What we're about to do is set it one time so that if we have to change, it will change it in one place, and it's well, it's just changed. I'm creating a static class public static class in points on Then I'm going to create aesthetic parameter are sorry property so static on, then this is going to be a string, and I'm going to call this property base. U R l all right. And then I'm just going to initialize it. So this base Ural will be the u R l for our a p I. No, this girl, obviously since everything is local, is going to be the girl that we've been using inside off Postman. And whenever we go into deep boat moored that your latte has been coming up in the browser for the bookstore FBI, that's what we're going to use. The point is that if I publish that FBI tomorrow, that base you are it is not going to change because I don't want to work on local those I want to work over the Internet are on whatever hosted address its broadcasts from. So I can just meet the change one time here on then every time I pass and you are really will already be sick. So to retrieve this quickly, I'm just going to go back to my ap I project Andi. I can look quite easily inside off the properties, these properties, you can just drop it. Don't bring up lawn settings that j son on. Then what happens is that you see two addresses. You see the application your and SSL port. So I want the application Your with the SSL port sign. Ally, are you know, http? Well, it should be a core issue. T p s colon slash Plus, another easy way would probably be to just go into postman and retrieve from there. So I could really do that on its http s local host, Colon 44382 Right, So that is going to be our beasts. Endpoints, RBs, euro. So I just put that in there, Another sport on a trailing slash, Um because then I'm going to just upend things to it. So the next one is going to be another property, and it's going to be static on a string on then. This time I have authors in points. All right, so pretty much all the endpoints that then went toe have I can just put here and I just build the string one time on It's going to be ah, on inter Polish interpolated string featuring the base URL right on. Then after that, the keyword FBI remember they have the beast a pre issue oral slash ap A So the slash. I don't have us last year before a pair because already put the slash inside off base. You are all right. So it's base your ill, which has its slash e p a slash on then authors and then understand to duplicate that line and do the same thing for books on. I'll just pretend those slash is also on the end. All right, so this is going to be books and points. All right? So when we build out other endpoints, um, it will be the same dynamic. We just coming to this file and Aditya a static resource, I would just use it anywhere we want. Now we're almost done. I'm just going toe guided through two checks. I'm just going to do a quick build, make sure I didn't break anything. And no, when we do builds, you're going to see two succeeded because we have to project. So it's always good when you see all projects were successfully built, known, failed. Um, So the next thing I want to do is make sure that one there won't be a neural cash it. So I had an experience one time where when I went into the depot, more trench around the two projects at the same time, they were both fighting for the sea import, and so one wouldn't work so and easy to check. This is just the goto lawn settings for both. So we have a blonde settings for our ap already. We see, that s airport. Is that number on? Then I can do the same thing in the Blazer project. Go to properties, check lawn settings. And you see, it's a different numbers. I'm just scatting you toe. Make sure that they're different numbers. If, for whatever reason they end up being the same number, You can always just change one digit sake and just take off under detentions at the six or whatever the case may be. All right, So the next thing is toe enable the double execution. So what has to happen? No. When you're running the clients being the blazer application, the you I application, you obviously have to have the a p I running in the background in order to actually carry out your operations. Right. So I will need toe alot that when I press the start, so you have to waste. It is you can put one as the start of project, And then, while it is running on your indie boat, Moody can always right click on the next project and you see debug on NBC's You go to start a new instance that would actually allow you to have two projects in Bebel moored simultaneously. Right? But I'm going to eliminate that manual. Step on. What I'm going to do is go to the solution Boats of properties on, then under start a project, you see, Single start off project, which is what we have. No, but you see multiple start of project on then. The cool thing about this is that you can change the order that a more startup in So the one at the top will start first. And that's what we wanted on the FBI. Open learning, and then the you I can come in because of the a P I the wise useless. Right? So what I can do here is see action and then click it and then say start on then for this one, they can start without debugging, but advantages being in debug mode with both off them is that if I try something in the client and it doesn't work, I can be both through the other project within the lifetime off that debugging session. Right? So that's one of the cool features. So when I do that and click OK, all right. And I'm just going to show you know that it is multiple. Start a project and I just click. Start on, then What you see is an instance car project coming up. All right. So notice I have two browsers and you'll see the two, um, ports running. So you say bookstore You I come up on Dwell. The FBI's taking a bit longer to come up with. The point is that I'm running both projects simultaneously. All right, So the glorious sight of soccer you, I means that our APIS project is running. So here is the FBI project. Are here's evidence off the A P I project, um, in debug mode on here's evidence off the you I section in debug mode. So once again, you need to have the two of them running because you can test the u. Y. If the FBI is not running at the time, you can. Also, if i the settings where it says launch bro's er so you can see on the FBI. Don't launch pros are because, well, you probably don't need the bro's or at that point, because they're just testing the you I. So you don't need soccer in the background every time so you can actually go to the lawn settings for the AP. I on change that toe falls on, then that would only launch the bro's or for the one that has it. That's true. All right, so that's it for this configuration exercise. Next stop will implement some user authentication baseline configurations. We will have to make some changes to our FBI. So that will be at its activity. That would have us bouncing between the two projects. Make sure everything is open running. Andi, that should be fun.
38. Setup User Registration (API): Hey, guys, in this video, we're going to be doing some prep work for our client and our registration functionality. So I'm bringing up over up, just as a reminder of where we are and what we want to do is make sure that or register function works. So remember the last time we left off the home, the log in under wrister all looked alike. So what? That it was go ahead and add links to them. The same we'd weeded for offers and books. Had a sport log in for the path for the logging. Blink on register. Accordingly, I noticed they look more normal. No, and a whole. What we want to do is that when we click register, it navigates toe some page that allows the user to register with just an email on a password on. Then that will be central with the A P I on. Then this new user would be ready stirred in our system. So we will be making some changes to the A P. I will be evolving it a bit. We have good amount off work, don't already, but we need a register endpoint and I'm going to add some validation toe our data transfer object waiting for user information on. We'll just be doing some other things in between to make sure that our clients gen handle talking to the registration in point and actually have a user registered through over front facing application. So over to my bookstore application bookstore, FBI project Where can the user DT Oh, and I'm just going to add some validations here, so I'm going to make everybody know that this is required, meaning Do not submit a request without the user name. All right, I'm also going to change this from using him toe email address on. I know that that's going to cause some ripple effects, but the reality is that we're going to be using the email address as the user name anyway, so it doesn't really matter. You may not want to change this the email address, but I'm going to do that nonetheless, can also add a data, a notation here that's his email address and force that you're getting an email. Idris, in that field I'm also went to put are required here for our password on. We can also do something like specifying the string length so I can see, um, guitar notation string length on. Then I can further qualify this by giving a maximum Lynn. So let's say the moxie Mamma Lynn's that we want for the password would be maybe 50 characters. I can give the arrow message saucy error message is equal to and then I see your bus. Word is limited. So let's say 15 fifties a strict diet. So 15 we don't anybody tapping in more than 15 characters of the passer. I mean, this is up to you off course, but I'm just doing this, for example, sick on. Then I can say it must be Let's see 15 characters is the mark of the many bumbling length is equal toe six right? So I can say your password is limited to on Then I can impose placeholders to see it must be so. We can use placeholders, sir, but I believe the 1st 1 is for the display name on then. So this zero did the display name one would be the mud slings on Day two would be the minimum lens. So if you wanted it to be dynamic instead off you typing in the number here and then having to change it. You can do something like one is limited toe well, too, to one characters to say the pastor, New Putin is limited to two being minimum length right 6 to 15 characters. So if you change the numbers here for the minimum length of Marx length, then you would automatically just format the string accordingly. So that's just some validation that we're adding, um, were required with the string link that I can. I guess I can add a data type here to see data type on. Then I have to qualify it with the genome data type docks on. There's one for password, so there's one for email address also, so you can do humility. Slightly circle do data type dots, email address. Either one works. Not have my user data transfer objects kind off modified. I'm going to go back to my users controller on This is the control that we're using for, ah, authentication related things. So right now, so there's that error because they changed it from user name to email address. So no problem. I'll just change that thought on. I'm sure if it's anywhere else, it will pop up. But what I want to do here is create another endpoint for registrations, right? No way of logging. But I want another in point for registrations. Understand? Toe, do that one above the log in and I'm going to say public piecing task off the fire option results on. Then we do it and call it register. No, you might remember on I want this from body also. So I'm expected the same user detail coming in through the register. Like I said, I'm not going to agitate the process. So if it is that you have more data points, that you would want the user to register with me the first name, last name and other things they would have another detail for just the registration process so that you you are expecting more from the body than the few parameters here. Or you could just extend user detail. But once again, the details kindof can be very specifically or context. In this context, I'm only asking interests with the user name and password. On the same thing will be the logging. So that's just the based reason for me using user GTO, the two places another thing is that I'm about to meet this opposed. So I actually want this to be http post. No. What happens is that as we've been seeing the name off, the function has almost no beer ing in. How the controllers going to wrote the request, the control is just can't request and seeing if it's posed that I'm looking for the post, right? What happens is that because both off these are post. Even though the function names are different, it's going to lead to some form of conflict. So there is ah, feature here that I can use where I can specify the roads so I can just to see where we specify road up here. So this is the road, and it's seeing a p. I slash on the controlling him. I can, by extension, right above the controller, see roads on, then specify that I want this one to be called logging and then specify wrote appear again on DSA. Say that I want this one to be called register. All right, so that means the documentation no is going to have to distinguished, um routes for our long in control of both off them being post So pointed. No, we've done one function per type. No, I'm having to functions are to end points of the same tank. So the best way to distinguish them it's actually give them different names. So we know that this is the log in one. So the person if they want to log in the call ap slash users slash log in on the same for register on their past appropriate data accordingly. So even if the data is different, it doesn't matter as long as they puts the courage route. All right, So I just put in some Cody can pass here and Kopytoff But it's the regular core that we've been putting in. All controllers, you know, actions. We have the getting off the location and that I'm despising or the user name and password from the data transfer objects data coming in on dime. Also checking for the the errors, right? I can actually go ahead and use some off the data. That's 30 years from the country. Well, actually, I want to check some stuff for, So if it gets this fire, we can assume that it's valid because our put validations inside off our user details and nothing should be coming over empty. Uhm, I'm getting this fire. No. Another thing that I would want to do is use the call The user manager. So I'm going to first to create a new user. So new user is equal to a new identity. Use their serve identity user is our base. Use a class given to us by identity. So I think I'll have toe wait a bit. I din t t Teoh my spelling. There we go. Identity user. So we're going to build a new object off type identity user, which allows us to set the email like I said, um, well, I call it used the name here, so it doesn't really matter. User name. All right, so I'm setting the email is using him. I'm also going to set the user name as the user name as they email. Sorry, which I'm starting in my variable using him. I said I can get confusing butts. I'm sure you can appreciate it. The fact is that the email address is the same as using him. So we're just stirring the email address in both the email on the user name Space aan den. Really entry. That's all the data that we're collecting. So you see, have other data points on you can actually extend it toe, have more if you need toe, so that's fine. You can always check out my course in complete speed on a tree, but one development and you'll see how we can extend that into the user. But we can move on here on then. Our save our results is equal to Andi. Let me just see what Pero this is first. Sorry about that. I had the word new instead of fire my But so far results is equal to a weight on. Then I'm going to call on the user manager and so remember, we'll add user manager already injected. All right, so at the user manager, someone to call the user manager on. Then it's going to expose a Fortunati called Create a Sink, which allows us to pass in an identity user some with the parson may newly created at into user object. Andi, I can also pass in the past word. So when I do this, it will actually handle the parsing for me. So the pastor would've come over as the plain text that the person tapped into the text box . But then this function is going toe handled the insertion on the piracy on everything. For me, we did something like this and worse, eating the users earlier? No. After that I went to see if not results docked Succeeded eso I'm checking. Did this operation fail? I'm going to see Firstly, I went to love an arrow to say that the user registration attempt feel right. But I also want to love The reasons for are the potential reasons for the failures. Now instead of the result, um, objects, there is, ah, least off eros someone to say something like for each Andi, I can save ire assay error in results docked and you see the list errors or I knew I innumerable. It's a collection off Eros. So if there more than one errors, they will all be there on. Then I'm going to log a line per error, someone to say longer, not love her on then the location. And then I'm just gon cutting eating No, the error dot court and the air description. So inside off the error, the innumerable off errors inside off each air object to get a court on the description as to why there is an error. All right, so I'm just logging all of those on. Then I can do our return internal error, But at this point, I don't think I need to love anything else. Or maybe what I can do is instead of flogging this pair here, I can love all off the era's pertaining to the failure on. Then just return in turnout error with that log message on. Then call it a day. Sutherland's end up repeating court and I'm making the best use off. What are we have in place, right? So once again, if it was not successful, we're getting all the errors and were logging each one in its own line. I'm just tickled empty spaces on. Then I'm just returning an internal or with a blanket statement to say this user name registration attempt field right also probably should include a lot of land to see user registration attempted. So let me just put that in quickly. Stems all right for user name. All right. Good. So that's it for the logging. So I'm not done. Gets one more thing is I'm only checking if it was bad. So this is still here Because I need toe have a final return. So the final return will be on. Okay. So I can return. Okay on then. Andi, I'm just going to put in a new generic objects. I can see new Andi This new object just don't have a result that succeeded, which at that point should be true. Because if it was far as it would have been caught up in this Onda we can want So another thing you mean want to look into doing is for the internal aero. For this control, Lee can probably expanded a bit that when you're returning the 500 you probably include some errors are reasons for the arrow so that whoever is calling the A p I can, you know, get some feedback, castaway the attempt field. So I went into debug mode and I have here the window for the FBI. So if you still have the motive project start up. You can just focus on the FBI window where you can change it for no and change back later on. But I'm just focusing on whole day endpoints look, so know that because I did the route you see that under the user sex and you you have both posts and you have a ps slash user slash register on gps slash user slash log in. If your document feels the Lord, that means you probably did not put on the route and you have ah, conflicts. Slager is not loading. Then that is a tell that you have a conflict. Because swagger itself is having, ah, hard time deciphering which wrote is which, because you didn't specify, right? So let's just test this endpoint quickly on you See here where it automatically feels in what is expected. It's his email address is expected in the payload. And that's an example on password string. All right, so I'm just going to use the trade told feature here, so yes, we know postman on. I'm going to show you how to test with sluggers. They can see you try it out on. Then you can put in user as example dot com. I'll use that on. I'm going to put in. I want to leave streams. So remember that we put in some validation where the password most needs certain certain length, so let's try that execute. All right, So we got back our error on we see here where? Okay, it's just giving us the 500 on this. Just giving us that generic a remission. So, like I said, you probably want to give a bit more detail in that. However, if your documentation is solid, whoever is developing on top off the 80 I should be able toe look and see exactly what is expected. So here we're seeing, we need I use a DT o object so guarded totally that it's expecting the user details object on then. The further detail is that the user detail object has in the fanatic most beard string email on password, with the validation of putting where possibly between 15 and six characters long, right? So the developer consuming your a p I has an equal responsibility to go through the documentation and court accordingly. So let us try it out again just to finalize this somewhat usar leave for P at SWR the one on try that again on. Then when we look, we see that we're getting back or 200 andare successful message. All right, if I take a look at the log file, then we'll just see that we have the first infill audible, the attempt, and then we have all off the errors. The password requires this the pastor at that on everything that was wrong with the password and then the ultimate thing that says it field. All right, So the logging works and it looks what? Like what We expect? No going back to our project. I'm going to make ah few modifications to what we have in our Blazer so far. So I'm going toe one, create a new folder, and I'm going to call it models from the simply click add new folder on I'm calling it models. All right, on, then. The first thing that I'm putting in this folder is a new class that I'm going to call response model. No. If it's one thing we've seen is that every response basically has something to say. Whether it was successful, this could be the cord or it could be a flag. So what I'm going to do is say something like, I want a property which is going to be off type bull on. This one is going to be success. So this is going to store where the car was successful or not on. Then I'm going tohave another property of type string. This one is going to be for maybe error. All right, on then, I have one more property. Andi, this one is going to be for contents, right? So you'll always be getting responses with either an error message are content or something , but we will always be able to determine the success. So this is going to be a more generic class type that we're going toe retrofit are based repository responses. So right, no are based repository. Every time we call an end point, it's really just turning a true or false right. But in the case off like that, talking when I'm going to be using this base say this is what we're going to use, which is create though it may seem, um, weird. But let's not get our wires crossed when we're calling a post we're going to use creates. So we have the option to have a a generic post function that will just call. But then we already we will basically just be repeating this cord inside of that generic post. I don't want to have to functions with that. So what I'll be doing is using the response model, changing these old from bullion in tow. Request types, right? Sorry response model return types on. Then when we evaluate what we get back, then we can formulate more detailed response than just true or falls. So we will do that when we get back and we start setting up over registration functionality for our blaze application. But then we'll be retrofitting over based reports, story responses with or knew response model.
39. Setup User Registration Form: Hey, guys, welcome back. And we're in part to offsetting off the registration functionality for our bookstore application. No, we just set up the A P I toe have our registration and point, and no will be setting off the blazer side of things toe. Have a registration form on be able to communicate with the A P I. So this adventure starts off in my static endpoints file. Where are adding a new endpoint just for registration, So it's going to be register in point on. Then it's going to be based euro slash monsieur a p i slash use air slash register. So remember that that was the way that we formatted our uhm en pointe for registration in or users controller on just as a fresher school back. We did say the route is always going to be a PS slash controller on. Then we can specify another route on top off the actually for one. So it's a p I slash users slash register. All right, so that is over static endpoint for a destruction. The next thing I'm going to do is set up Ah, models folder in our you wise. So, you know, on the A P. I said where, but we'll call data transfer objects were on the user interface idea what you call view models because their views on then you have models off the data that should be represented on the views are view. Model meets that credit to your right. Sorry. I wonder if I click class I should have said new folder and then in the folder. So we're going directly create any photo call models and then in this folder we goto ad and then class and then I'm going to call this user model. All right, but then inside off user model, I'm going toe have two models, so yes, I know unnamed that user model. I'm going to leave that blank. The file name will be used a model, but really I want tohave longing model on. I'm also going toe have register models. I just put long and model their from no boats. I'll have register for it. Just there are limits the registration model. All right. No registration model is goingto be a sick Ali have the fields that we need for registration which you know are using human password on all the validations that the user interface will need to adhere to. So I'm actually just going to go over to use their need to you, because we did. All of that user needs you. We have the email address. We have the password, some discipline to copy all of this. And then I went to come over to our user model on understand paste all of that in there and then include any missing libraries. All right on, then, for the password, I'm actually going toe Do ah, comparison. Validate also for the password. So I added the additional field, which I'm calling confirm password on. I'm just going to put a display name here for email address. So the display name basically says what Hadi wants to be displayed on the screen. What is the name off the field when it's displayed to the user? So it's email addresses nor space. All right, so these that the annotations play a nice part in hold, a user interface is structured. Any hole. Let me just walk you through. So we know about required the data type here is password. And we put in our validation for the past where it takes that goes in and then don't. Here I have another data type password. This one is confirmed. Password on this one is seeing compared the value off this field with that view. So it's just a nice comparison that will put in because when the person is registering, want email address and then to compare the two passers, making sure that they're much. Now, after we've set up our model, we need the actual page that's going to apply toe. So to create a new page or new component, we need to go over to our pages folder. Andi. So we can put everything at the root because as far as it is concerned, once the page name is there and it is registered toe have the name and we saw something letter with index, where with the at sign page slash that those means home. Or if you look at weather forecast, ones that were there, the fetch data under counter, you know, seeing slash Fitch Gate and Slash counter so we could put it at the root. But I don't like all off the pages, you know, just sitting there and rules. I'm actually what's going to create another folder inside off pages. This time on, I'm going to call it users because I want only user related pages inside off this folder, not a cell phone, and it's a really player part. As long as the part is, they're so let me show you what I mean. So we're going to add a new blazer components directly. The folder Goto add on. You can choose new item again to his class, but we want to goto web, and we want a razor component on. Then this one is going to be register right. Please use capital are because if use a common are it will give you a problem. I used to come in and got a problem. I don't know if it was me or future universal, but that's just my recommendation. Use capital letters when you are creating your reserve components. All right, so this one is register. We click. Add Onda. After adding this speech, I'm just going toe put the no annotation at the top to let it know its roots, so it's root is at slash register, right. So even though it's in a sub folder, once you put um on each ref to go to register like we did in the Nuff bar in enough menu. He will look for that component and find it's I'm just want to quickly design or the registration form. It won't have any form sanity, because you need to create on authorization service before we can make it tick. But let's deal with the designs. I'm just removing that. I leave the court here, and then I'm going to use some would strap four, um, classes. The style. So boots up four comes built in tow blazer. Um, if you want include others. You can always right click Gautam Believe Manage or no other our client side library. And then that will bring up a dialog box that I lose the search for another, um, clients I library, like maybe want material or something like that on. Then you can just install it, and it would put it inside off the water retarded location you have there, right? So if you're you want to use something that's not bull shop were at the head. I'm using bootstrap. If you're not so familiar with bootstrap, you can always go to get bootstrap dot com on the latest is 4.4 on day have excellent documentation. So everything that I'm about to do, you can find somewhere here on the side. So the component that I'm about to use toe help style my pages, the card. So I'm looking for a card, and this is basically simply that we're using, right? So when we have one card, it will give it a national border, right? And then you can see how the different cards can look. So let me just start off with this one, and I can just copy, because when you were typing HTML anyway on, I'm just going to pace that. So that's why I'm starting off of a diff with the class card on then inside off the card, I want a car title and so much adjusting to C H. Maybe three, three, not 13 on give it a class off card dash title right on. Then I went to see her. Just, uh, no. All right. No, inside off the body were going toe have the farm. So blazer gives us some components. Some, you know, special tags. So we always aberrational. But then they have sometimes that we can use So when it comes the forms. If you just open the town and start writing the word form, you started seeing some different components that they give you old off the box to help with forms. So one they have is edit form their bitter notations while the data input types on these can provide some special binding toe the model that is in use. Right? So I haven't gotten to the model part yet, but just work with me. So I'm going to start upon edit form on you open and close that on then inside off the edit forms attribute list. You have model. So model means what data classes this form binding to on. We know that we created the register model for this purpose writes I'm just going to say register model. That is what? Your banding toe Right on. Then you have some action. Second, say on on in a new invalid, Submit versus on. Submit versus on valid submit so you can choose to do something If if somebody submits invalid data Ah, you can choose to do something when the person something it's all together without, you know, enforcing validations, or you can just say when a valid submission is done. Then I will do this on the validation of courses relative to the validations that were all lined inside off the model being used. Which would be in our case, the father email address is required on that. Passwords? Most much. All right, so on valid submit. What do I want to do? I can call a function here. Seconds A handle registration. All right, So it's been toe. Know you're going to see Red Lines because it's your maker. Representation off two things that do not exist just yet. But we'll get around to that. No problem. So in the farm, what I want to include will be data annotations, validator on validation. Summary. All right, So these two components will sit down and watch and make sure that all the validations being outlined are being met. No. I'm going to start building onto the farm. So if I mean, I know you should know how farm works, but if you want to know how bootstrap forms can look, you can always go back to the documentation, look at forms and then you see ho to invoke bootstrap forms to get them to look nice and sleep on interactive like this. Right? So you have your form talk, however headed form that we don't need that. But then each control would go inside off. Ah, form group with a label on the input. Andi. Well, if you want to have something there, Right. So the sense is that we need a form group on each input. Should have the class form control. Everything else is within or control. Um, so let's go back on. Let us create our first input for our email. So I have formed group. I have the label for email on Di Di. So those too much on the labels is email address on. Then you see that I have my class form control. But then I have something here that's gonna standing goto than outside binds dash value equal. So it is saying here on notice this is input text, right? So if you want text input, idiocy, input, text. Um, what this is saying is if well, when the form is being submitted, or data whenever it's has interpret data, what part off the model should I bind to? Right So we would be binding toe registration model dot email, cause that's a feel that we have that much is the email address. All right, so I'm just going to replicate this for all, and then I'll create a model, and then you see hold of mind values. So right now we have a bunch of errors, and we have the validation message for meaning Whatever feel that put in here, it's going toe print this message, that error message that would come up in the event that validation is not mates. All right, so, no, I have my three fuse out for email address for password and have confirmed passwords. You can pause a video. Take that off. What really entry can just copy and paste the email. One understands the respective I ds. All right, Um, off course. It's never going tohave to feels of the same idea on the same page. It's understand. To change one to confirm password right on. Make sure that you specify the type equal sponsors. So you can specify type equals email address here, but we already have the validation running to enforce that it must be anemia. Lecherous. All right, so that would be kind off you know, double work, but in make sure you put type equals spots word because, um, you don't want it to be typing out in plain text right now. The most important thing that goes on any form is our submit buttons. I just have a button type equal. Submit class on, then inside off that apple bt nbt and dash primary each and dash block. So once again, you can always review bootstrap documentation to see the different buttons they have on what they would look at it. So this is a primary button bt and dash primary right that called gives you this blue button. So whichever color it is you want, you can include it on. You can scroll down and see the other properties. So know that we've done the design part off the form we need toe. Start writing some of the court. So we see all these red lions here. We have some errors. So right now what we need to do is specify what registration model is on. Registration model is a class that we have in the near space bookstore. You, I not model. So the thing is that we can actually put using statements inside off our components right here. Because I need to tell you that I'm using this library for some stuff. Right on. Then inside off my cord. My core block. I can start writing court. So the first thing I need to do is create I'm on object off. Well, type registration modern on because I called it model. I need to meet the name here. So let me just explain that quickly. So I'm going to see private registers on water on. Then I have to call it the same name or whatever near my colleges. Whatever name I have to put up here and then after initialize, it is equal to a new instance off predeceased on model. So to make things simpler, Could have called this just model all right? Or whatever I wanted toe. And then I would just have to make sure that I say model equals the name off the object. All right. I mean, see, that red line is gone because no, the component knows that that exists also for our bindings. I need to know, Say the model docks on, then put in the appropriate field. Some binding in protects the model. That email address passwords, a mother, that password. Andi, confirm posture to monitor that. Confirm password. All right, Looking good for our validation message. We have to do something a bit more fancy. When I went to see at Scient to involve summaries accord on, then put it in a brace on that inside off. These races are inside of the parentheses have another pair of parent disease which is like indicator, like a pseudo function or one line function. But then I went to reference sad my lambda looking arrow. And then I say model dart email address. All right, on DSO I'm going to do that for all the others. So the validation message for password we'll be ready. Teoh model not password on the same four. Confirm password relative to confirm password. Next up, we need toe. Um, it will create this function right 100 registration. So no. Inside off the court the same way we needed to create our model. I need to see a private You sing the US aan den handle and then once I create that look at hold, that red line goes away. All right. Perfect soar continuing. Here we need to know what we're going to do when somebody registers. And what we're going to do is, you know, actually called a P I and do all sorts offensive. So we need to actually build function it, and I'm not going to do it here. Instead, I'm going to create a service that is going to handle all off our authentication beast operations. So as this customary, we're going to go to contracts, click add ons, create a new class or interferes whichever one and we're calling this one. I authentication repository that on then inside off this, I would just make sure it's seeing interferes and the class inside off. This we need toe have, ah, function that is going toe be with registration. So this one is going to be a task off tie Bull on. It is going to be called register when to take registration model ons user as the parameters. Right. So that's our contract on. Then I'm going to implement it, someone to go down to service right click, create a new class call this one authentication repository click. Add on, then we do some inheritance. I'm not going to use the baster posture for the user related operations. Because, as you can Well, let's just backtrack a bit. But the base repositories were designed to deal with specific classes Right on Then. I have user model and and I have register model, so I would have to creates disparate classes are a lot of fun sickness. Maybe use autumn upper over here toe and so on. So I'm just trying to keep it simple on I'm just creating another positive, very called author. Depositary. Just for authentication beings things where it doesn't have to get to the stage off crows, operations and hold. Let me go ahead and implement my my interface. So include any missing libraries into implement, interferes. And then we're going to write our core that is going to talk toe over FBI, someone to start off by injecting my http client in tow. This arm, this class. Sorry. So into the service. So I m GDP kind factory on. In case you don't remember any off this, we did that when we were doing the based repository. When you just go back over on, you would see that we actually addicted that seem object, right? Or that seem, um fuck turd. All right, so enough off that. So let's move on. So now we need to initialize. It's a much adjustment. Quickly. Board this. All right. Said one thing. I went over there, remember? I did. It's over there on. So we just need the constructor for our past story said exchange the name copy and paste a change in him. So I'm injecting the client into our repository. The court here is going to actually look quite similar toe say the posting core that we had just removed that where some posting court in our based repository. Alright. Or create. So we're nowhere doing opposed. Based on the instructions on DSO. A lot of the things will look similar, but let's just start them all together. So the first thing we want is our quest off type post on the URL that will be passing in is in points dot to register in points. And remember, we just created that when we started off with the beast Ural for registration left off that trailing slash Sanders put it better safe than sorry. All right, so vai request. All right, so we created our requests. Then we're going to fill it with the content, which is going to be our serialized version off the user model that's coming in on off course. We go ahead and include anything that is missing. All right, so, so far, most of it looks like copying and pasting from the create for the beast repository Beiring . The the actual parameters going in, right? It's the same court. So we serialize it to Jason. Then I use my client library toe, create on http client itself on, then I'm going to send up Ah, request. Some just want to see http. Response message Response is equal toe there waiting off this and this is our weight. So after me, this is think on, then. So in the creator in the factor that we created the based repository, what we did was we checked for a specific response called at each point. Right? So the thing is, I can actually just say something like return because I'm returning a bullion. I can just see return response dot is success status school because you know that their status boards that signify success so we can just return that So it's either true our fathers with successful are nuts because our A P I for registration is not returning any other valuable data. That's we need to complete the registration or anything. We just need to know what's it's successful or not. So know that I set up my service for authentication or my repositories for authentication have to go over to startle dot CS and make representation off these rights. So inside of configure services, I need toe say services thoughts ad H D T B clients have to make sure that I do that all right, because, you know, we're using the issue dp clients on that. I'm also going toe add transient my eye authentication repository and authentication or posters so that we can inject this service where we need it. So know that we've done that and you can just make sure you have these lines before you continue. Now that we've injected on, created are off repository injected it into our start up now back in or is a component, we can inject it into the component itself. So well, I'm going to make reference to the contract, So I have to using the library contracts on then I can inject. I authentication repository on that. I'm just going to call the object off re pool. So right there is our dependency injection directly into our blazer component, right? No, we can start writing some court handled the registrations. I'm going to say for the vire response. All right is equal to on. I just await the result off our off re pull docked on. Then we have register. And then where we were registering Well, we're just during a new user in the form of registration model which is coming in through our object called model on. Then I do a semi colon. Alright, then I can take an action if the response is good, are not so I can say if response cause then response series returning a bullion. We did say that we need a bullion on second, see if response then I want to navigate away, so to navigate away, we need another injection and that's in the form of the navigation manager. So I'm just going to go back to the top and then I'm going to say inject now the gear son manager I know just into call. It's love mine. All right, so then don't here. If the response is successful that I'm going to say I love manager object dots navigates to on then. Well, if the person just registered, we can probably navigates to the log in page. All right, but there's no longing page. It's Soto prevent in areas I just navigate to nothing. Alright, Aren't the home rather else on then else would mean if the response came back as far as it failed. Um, what I'm going to do is create a section where I'm going to display an error message so I can come back. Appear to the card. May be right on the register. No, on. Then. Do something like an alert give. So boots have gives us alerts so classy, quasi alert on. Then I can see alert Dash jer. So that gives me, like a red, um, give or area. And then inside of that, I can have a p tug, which is something like something went wrong with the registry son attempt. All right, but then I don't want this to be displayed all the time. All rights are really doing so What I'm going to do is create another variable on DSI bullion is field. He waas falls on, then some setting. This, though, falls first because once a page loads whatever value is in there, it's going toe parts that value. So I wanted to be false first. But then, if the response if not responsive response if it's true, then we never get away. Else I want to say he's field is equal toe true. All right, and then up top. I can put on your statement right here in the HTML. I can just say that sign. If sorry, let me just try that again. I can see that sign if is field, then display the dues. All right, So what this will do is evaluate the value off the variable and then display the diva accordingly. Right? So? Well, this is Give me an era. Let me see what this areas are both saying it doesn't exist up my body. Ah, sorry. So this needs to be declared outside off the on handle registers. I'm declaring it global to the entire view, right? So then we change its state once we try toe handle the registration. So if this lake feels, then we showed that something is wrong. with the with the registry, son. All right, so let's test the salt. I'm going to go back to my users control and put a break point on the register just to make sure that we're hitting the correct place on. Then I'm going to just go into debug mode. All right, so we're in our application. I go to register if I try to submit the same time, will tell me that the password and confirmed pastors don't much, and that's because it's kind of auto feeling. Some tests, um, date also, you see, it's it's working the validations work. I can't move forward until everything is meant, right? So what I'm going to do know is actually ready to somebody on. I'm using a default passer that's be at Sina sensibly worthy one on. Let's try to submit that on. I'm getting an error. So let me see what this errors all our boats. So, to see the era, we can go into the consoles. I'm just going to right click, inspect element. Go over to the console tub on, let me see some nor connection could be made. Oh, I'm sorry. I know what's wrong. So I I actually only have it in one start off project more so let me just start that. So I need to go back to my solution. Right? Click goes of properties and make sure that we're on multiple start of project with the FBI starting in debug mode before the u I Onda we click OK and and that's tried it again. Alright, let's try that again. So register and I already have a test user with that. So I'm going to say daily a wanat bookstore dot com Andi same password and then submits on then it It's our break point. So that means that we successfully just connected from our you i over to our a p I right. So you saw that when the AP I project wasn't running the you. I couldn't do anything because it needed to connect over to the next website. So even though we're on the same machine, even though we're using the same Web server, you can see that they're broadcasting from different addresses on the principle remains of seeing. It's the same thing you would do if you wanted to talkto another FBI hosted on a website halfway across the world once they have a u r L you can use the same techniques Http, client the post to get whatever method it is and connect across. Now. That being said, I'm just going to verify that the data is being sent over and you see here the user detail , even though we sent over the register or registration model, you are with email password and confirm password. We're really only getting the email address and password. That's all that really matters, right? So I can express at five. I'm pretty sure it will go through on then. Let's see what the you I does. All right. Andy navigated back to home, which is what we asked it to do rights. We said, If it is successful, then go back home. So that's what it did? No, of course I want to modify this a bit so that when the person gets registered, they probably go to the logging. So, no, we're going to work on logging functionality to make sure that when daylight comes back and she wants, a lot of us can click against you. Caesar form puts in our data, and then we change the authentication state off our up while getting the talkin and parsing everything along the way. All right, so stay tuned. We have another impact activity coming up when we talk of the logging.
40. Setup User Login - Extend Blazor Authentication Provider: Hey, guys, welcome back. We're going to be tackling over user log in functional it. Right now, I have quite a bit to do someone to move along, and at any point, you can always pause the video on, try and catch up with what I'm doing. But I'll be I'll try to be as clear as possible in explaining what's happening. So I'm starting off with our in points, and the first thing that I d necessary is to make sure that we haven't in point for registrations. For long inserts. I'm going to call this one logging in point, and it's going to have the base, your old slash It was busy. Oral FBI slash users slash logging with the trailing slash. Next, I'm going to go over to models, and I'm going to create inside off the user model file details in or logging model class. So we had registration model. It's going to look the same way pretty much. We just don't have to confirm passwords, understand toe copy, email address and password on put inside off loving, because that's all we really need for somebody to be able to log in to the application right if you want, you can probably dick off the string length parameter cause you don't want to give them any clues that you know would be happier. You don't want to get any indication. Sorry that maybe the password needs to be shorter than that. Another model I created is the token response. So you could actually even put that inside off user model. But I put it in its own place because all it is is a class. That skull token responds with a field called talking because remember that when we call the FBI were getting back a string for at least response is talking. The key is talking on the value. So we want tohave fi too much the key so that we can store the value when we d serialize it in the in. The FBI called, but we'll see that later on. So just go ahead and create that token response inside off models Now moving along, we're going to go over to our contract for the I authentication repository. And in here I'm going to introduce two new functions one called log in on one called Model One called Logo. So they're both taking one is a bull and one is a task. So when is returning a bull on one is just that us on? Then we off course have logging model as the perimeter for our log in function. And if we put it in the contract, then we must put it in the repository. So you can see that visual studio letting us know that we have errors. And I just hide this because sometimes it cause us to panic beforehand. Alright on, then. Understand to go ahead on implements. All right, so I just remove some extra core that I had there, so I don't have to worry about it because we're going to be retyping it. I typed it up just to make sure I got it right before I came to teach a lesson that for butter movie. So it's fine. I removed it. You don't have to pay much attention to it. No, but right now we just make sure that you implemented logging on law goat and no little focus our efforts on our log in function. It's so let me just remove this exception thrown on pretty much. We're going to be copying what we have here in the request in the register. Um, request. Right. So where Just went to copy? We're all off this court, actually, Andi. Yeah. So we copy this onto put it in, log in, and they were going to make a few changes because, well, we're doing logging side on either register in point. I need the log in in points. Right. So in points that logging in points, we already have the cart model for the user. So we are serializing the card object. We create the client on then http responsible. So we need this to be a sing who's me that is seen quickly on then all of these errors with away so pretty much. We're doing the same thing we're seeing. Try and log in, um, pass again. Whatever is coming over and we will be creating the forms off course, so the form will feed the data. Here. We pass it over in the same post method. But we're calling this endpoint onda. We check if we get back. I response scored are not a success court or not. But then there's a little bit more to it than just sticking. If it's ah successful. Responsible? Because remember that when it's a long in, we're getting about the token on. We need the token, and we need toe store the token so that we can carry out operations, throw the application right. Someone toe have to add a few more lines off cord. Where instead of those returning, is success bored? I'm going to check if response is not success. Good. All right, then I want to return falls. All right, so I just killed the operation right here. If it wasn't a success scored like we know it should be. Then we just kill the operation. But then we can move on Onda attempts toe, get the data from the response because, remember, the response is going to have the response board as well as a token stream. So if you want some refresher on hole will be getting about the data like I shouldn't be d serializing the data to go to the base repository on, look at one or forget operations. Right? You see here where we get the response for generous one. Sure, but then we get the content, read us string, and then we d c realize it toe on object off type T t here being the abstract object that the abstract. Um, why the generic repositories designed toe handle What? In our case, you know, we're getting back a talk and response, right? So I can actually just borrow this stuff this these two lines off cored, and I'm going to just refract to them instead of typing them from scratch. Right? So here I'm seeing get the content on that is going to be awaiting the content coming back in the response object. And then he set off return. I want to see Vier. Talkin is equal to Jason. Dot GC relies the object in tow. Our class that we created talk and response, right? Surma bore getting buck the token key on the contents. I'm seeing whatever the key is much it back to the fields here. So that's really what we're doing in the based repository, in case that wasn't really explained earlier or you do really understand area. So that's why we have to be untrue. We're passing the current model or the car. It's class. All right, So when we move along into getting the authors and so on and books, you'll understand that's a bit more, but for no, Let this pre like a little orientation as to what is happening inside off that, um, operation. Right? So we're d serializing, whatever object to spend about through the Jason in tow, a class with matching fields. All right? And then once we've gotten that, they left a few more things we need to do. We need to store the token somewhere on. Then we need to change the authentication states off the application on. Then after we don't all off that I were satisfied, then we can just return True, cause it's a bullion so true would mean that everything was successful. So I just returned true toe end it. So based on those comments that I just made, we have a few things that we need to get. We need toe, get a library that allows us to store the talkin. All right, so we'll be using loca storage for that. So we'll have to go into new get and get a library. That's a lot of Steve's local storage. On another thing that we need to use our to do is override the default authentication provider for blazer. So that we can let it do exactly what we want. All right, so let's start off with getting that library. So going into new get in our bookstore, you I application or project. Rather, I'm going to look for this library, a really cool library and rapper um called Blizzard storage. So I just goto Breaux's local asserts a blazer dot local storage. And then you can go ahead and don't know that. So this will allow you toe use the local storage in a browser to start authentication. Talking. No, that is a balance between usability and security because there are security concerns about that. But then, for this project, at least it's giving us a taste off what some people do, what is being done. More advanced, it needs can be employed. But I don't want to agitate the process. Right. So we're getting the library blizzard that storage on, then we need to initialize it in our start off that CS. And to do this, we're going to go down to configure services on dawned Ernie's Service side blazer. I'm just going to put services docked. Add Blezard loca storage. So this is no giving us access into the library blizzard storage through the dependency container or other IOC containers. So back in the repository, I can no go ahead and inject a new service so I can say private read only. And then I went to call I local storage service and calling it on. I'm calling the object local storage. So if you need to include a library, go ahead and do so on that would bring in the using blazer dot local storage on then off course. We need to inject it. Andi initialized and then know that we have it. We can use it. So what are we going to use it to do when we get the token? Alright, so we just got to Tokyo and it's no inside off this string. Call Vier token. I know need toe storage. So I'm going to say a weight on the score. Local storage on. Then what local storage allows me to do is clear are the local storage Um see if a particular values there. But what I'm interested in doing is sitting on items I'm going to see if set item facing and then this is going to ask before our key Onda a value. All right, so the key I'm going to put as talking nice and simple or no, let me. They have been more official, obviously off talking on. Then I'm with the past in to Ken. So which is my object? But the field is that talkin right? So the feel that when it got d c relies it got dieser allies into the field token. That's where the value is. So I'm setting up a new item in local search called off token on I'm saying talking that talking. All right, so when we log in on everything is successful that we get the token, it will store this in local storage, which is in a browser. And when we're testing, you'll see that first time exactly what that means. All right, So the next thing that we want to do is change off State off the up for authentication state off the up, which I mentioned will need are still write some custom court and over at the provider that's already built in. So I'm going to go ahead and create a new folder on I'm going to call it providers All right providers, and then inside off providers. We're going to create a new file. So at a new class. And I'm with the called a P I authentication state provider that's a mouthful, but a P I authentication state provider and then we click. Add on, then this authentications. Well, this FBI authentication said provider is really going to inherit some just going to put in an inheritance colon on its inheriting from authentication state provider. So you can just copy and paste that and take off the A p I on. Then this is going to require me toe include a library. And once that is done, it will know require me toe provide implements the abstract class, which means that I have to provide an override forward authentications they provide a class or functions are get authentication State he sink are so pretty much what this authentications they provided does out of the box is is the person authorized or not? Are authenticated, are nuts. And then, based on the difference authorities that we set up around the application, it will be saying yes or no. Can they do this? Can they do that all right, or should they see this should they see that it's all up to build. So we'll be handling it all we want. No, The reason we're overriding it, though, is that we want to change the behavior based on the fact that we're using token. So want to see if there's a token presenting local storage and that something is that this person is authorised are authenticated already, right. So if I'm going to have to be looking in local storage, that means I need the at the dependency toe. Check local stories. I'm going to have to inject into this one local stores the same way we did it in the off the authorization one just know. All right. Or authentication Repository on. Then I'm going to have to sit up my constructors of SETI or our top tub. Alright, authentication state provider on. Then I put in my parameter for I local storage on. Then I initialize inside off the constructor. All right, so now inside off this function I can do some things, but then let me just say this. I'm going to have to put the try catch, right? So what happened? Is that the first time I did this? I spent time wondering why it wouldn't work. I was getting something about rendering and some clash with local start. So based on the fact off whole Blazer lords, it needs everything to Lord. First on, I think that there was some miss much are some, um, mishandling off the lower times between the local storage checks on the actual server cord . So I was getting an error, right? So the try catch is just to make sure that it doesn't crash her win when everything doesn't Lord at the same time. Right? So the first thing I'm going to do is try and get the token that is in local stores. So to get the token, I'm going to have a very called save token ongoing await loca storage that get itim a sink . And it's going to say I'm getting us string right on. Then the name off the value are the key for what I want is off tokens. Remember? We just set it when the person loves him. A key called off token should be created. So that means any time we want to retrieve it will be using this function. Get item. And this is giving me an Arab posits needs to be a sink. All right, on then. Whenever we get it, it will be saved. Are stored in saved token. Alright, No, When I do get this token, I want to check some things inside of the token. And I'm I'm going to bring up some old tokens and show you what I mean by check some things . So here are some example tokens, right? Thes air tokens that I kind off Pete seemed from previous tests. This makes no sense to me looking at it. It makes no sense to you on this year a computer who is able to decode it. Alright. But then the point is that all off them, they were awesome for three different users are at least maybe some four the same user, but in different situations. But the header information is the same. All right? No. Between the full stops, you have the 1st 4 stop. I am the last full stop, right? Use of them is kind of dealing into that way. All right, We have what we call the payloads. If I just double click in that section between the food stops, we have that as the payloads. That payload contains all the information that would have set up in the jail ability. The issuer, that expiry date. Who? All those claims? Our number one rebuilt our tokens. We put in a bunch off claims. All of those bits off information are are stored and accessible inside off the payload. Now using No, but plus plus, I can simply go to plug ins, go to mom. Tools on base 64 d Chord on, then. This looks a bit better where you see sub with the value U c j t I. You see Name identifier. You see the role, right? Um, the expert expiry date or at least some kind of value. That represents an expiry date on the ISS. Your which was local host Loca hose. Right? Andi can look on. Do you see that? All of them sold Be a 64. Decoding is kind of mathematical. So this one would feel because there's Ahmad for month that needs to happen then received this one will work basics before. All right, So whenever you get that arrow, you mean Neto and one are two equal sense. I think this one requires to equal signs. Um, Andi, I don't I don't know that I just This was trial and error, right? So the months the mod for must be either two or three. So if it's neither, I don't think it will work. If it's still, it needs one equal side, it's it's do it needs to equal scientific Street needs one, something like that. But the point is that this one was an admitted right sort of claims, and all of that information is coming over inside off the tokens. So we need to be ableto Paris these tokens to make decisions when we're getting the authentication state. All right? No, The first decision that I want to make after trying to retrieve this token is if there is even a token. So if I'm going to just use my string library and see is no or white space. So if is no or white space save toe can save token, right? So there's nothing inside. I didn't retrieve anything. I looked for it and I didn't get anything back Then I need to return a new authentication state, Get my spinning right, you authentication state right on. Then the authentication stayed throws on principles. So that means that when a principle is present, that means that I use there is present. So if I just pass in a new claims principle, all right clears principle on then and the claims principle can have blank. Or you can initialize it with a cleans identity, right? So I'm going to pass in a blank identity because I wanted to be extremely clear that there is nobody here. Everything here is empty, nobody is presence or the authentication state is that there is nobody. That's pretty much what that is saying. So this is still in the application of the blaze application that nobody is president. Nobody's home. So you need not do anything. Just pretend like nobody's loved being right. So moving along, though, we can go on to get the content. So I don't show you all the content off the they talk in that is necessary right on. One thing we want to do is also check the expiry, So if the token is expired, then we want to say that nobody's loved and I will also want to remove it. So if it's there but it expired, want to remove it from there on, we want to change the authentication. States do not authenticate it. So in order to Paris the token I had funder acting on some court writing court to do that whole parsing. And that's I know about the equal sign and the basics before and so on. But there is a library that this president that can help us through that. So instead of putting you through all of that cord, we're just going to go over to new get again. Did I cause you get I did So let me just launched you get quickly and I'm going to be searching for Let me see if I can just search for Tolkien's dot jwt. I hope I see the library. There we go. So system that identity, not model. That's tokens that J lo beauty. So just go ahead and install that library, and then we can go back to Well, we need to go to start off that CS on. Let's start off that Sears know that we want toe have access toe that library inside off the dependency containers, right? So I'm going to add a scoped instance so I can just do that underneath the GDP client on with other schools. Instance off the J Liberty talking hundreds. So that's going to require me to put in my using statement. All right, so this will allow me to use this anywhere once I inject it in someone tohave toe injected into the state provider also, but I won't have to repeat the court a lot. So are continuously create objects. Let me just hurry up and do a private read. Only Andi include the JWT security handler. We're calling it on the score token, handler. So you see, there are times when you will have to do the contract on the service to get it into the the dependency container, and then there tends any kind of a single instance, and it will work just the same, right? So off course, after putting in the object, you need to initialize it. So I just put it there on. Then we initialize token handler, So talking 100. All right, so now that we have this token handler object, any time we want to do something talking related inside off this, I can just call on it. So what I want to do know is read the contents on what? To have our toe can content equal to on going to see underscore Token Handler docks on then from here, it's Oh, say, can you read it? We want to create You want to create a jade ability? You have a bunch of options. So the one I want his read jwt talking on, then have the passing the same token unit. So that phone, son. So this gives us an object called JWT security token. So from this object, I can say, What is the expiry value? All right, so far expiry. It will know parse or give me. Let me just make sure you get my Yeah, just checking the spelling so it will parse that value in tow. The data type I want. So if I say not valid to does that this one off those claims that was sent over we see that it has a date time. It will give me a date. Time gets the big time value. So then if I say valid toe is equal to expiry, then I can check if the date time no or expiring is less than the big time. No. So remember that expiry time was something that we had city, that's it. Whether we added five minutes are added five days, whatever the expiry time is, I am going to get it in the daytime value and I'm with complete with no on. If no has a greater value than what the expiry time was then. I also want to say that nobody is authenticated because whatever talking is there is no longer value. But in addition to that, I'm also going to want to remove it from storage. So then I can see a weight on the score, local storage dot and then you can see removes I am a sink. All right on. Then it will ask me for the key and the key is off talkin. So if the token is expired, remove it. That's pretty much what we're doing, right? So before I I didn't do this and the token was there, the person was loving because while talking was present, so we were turning unauthenticated state for the person. But they weren't everything that they clicked on. There were, they weren't able to get in. Everything was freezing up. And when we went in and investigated we saw that we're getting about the 401 Because the token was experiencing a P. I was rejecting the token, but we didn't have the facility in the application toe, you know, love the person out if the token is invalid. Right? So what happened is that once once application lords, it cause dysfunction, and then it does these checks that we're putting in on. Then if the token was there but it expired, we remove it. And then we love whoever was logged in long memos. Nobody is logged in at that point. All right, so we're forced. The users have toe re authenticate. If the token expires on in the same way, if there's no token, while they just have to log in if they want to care of the necessary operations Right now, the next thing that I want to do is get the claims from the token. Because I'm not just going to put to get cleans from so ken on, then build authenticated user object on, then return, Authenticated, authenticated. First are objects, right? So that those are the things that we want to do. But then the thing is that to get the claims from to talk, and that's something that I'm going to want to do on multiple occasions. So I'm just going to create on function for that separate. Oh, by the way, let me before I move on for the catch. I don't want to throw because then that would crash the program. So if if anything on the program would crash, let's just say we returned the authentication states being nothing, right? So don't crash the program just like everybody else, right? So let me move on. So I was saying that I need a function or I want a function that is going to just get all the claims from the token, right? Cause that's something I'm going to be using more often. And it's also going to serve a double purpose, offsetting a pop articular claim that we didn't have before. So lets us create that functions I'm going to save private on. I'm going to use a list, a list off claim. All right, so the type clean So I want a list off clears, and I want to call it So Empire screams on what I'm passing. It is this object, which is our talk and content. All right, so it's data type is J W T security toe can. That's the data type off that object were passing in and then to get the claims. It's really simple. So I'm going to explain why I'm going through the bother off having ah whole, um, function for it when it's really simple. Someone to save iron claims is equal to token contents. Remember, token content, that object hoses, everything that we need to know about our token, all right, but then I can see it docked on there. We have a field called claims, which is giving us the list off tokens all in the beta type claim on its on innumerable Well, it's giving us an innumerable off claims, right? But I do want a least because I'm going to modify it a bit than I can't modify the innumerable the same where can modify released right? So I'm getting it to list. But then I'm going to say claims that ad on I'm adding a brand new claim. All right, Onda, this claim is going toe. Have the claims type dot name on Dover. When we log in, I will explain you see exactly how all of this comes in. So clean types. Sorry. Not clear Stipe or clean types that name on the value that this name is when tohave is talking content. Got subject. All right. So subject would be what we saw. A sub in the decoded one. So sub that's email. So I'm saying that the principal user are the claim. One of the claims that this user, when it gets built, should have is the name being equals whatever with Passover as the subject. All right, which is the email letter started, longing name or whatever ridges on Then we can no return clears. So there is not parse. The to list is that I needed to do this line, and I can't do that on innumerable. So know that we have, ah, function toe, get the claims. Meaning any time we get clears and we call this function, we're getting all the claims. I came in as well as the addition off name being while the water was in subject. All right, so, no, I can build the user, so I'm actually just going to merge these two into one, right? So we just merge them all right. Someone to build the user object or I'm going to save our user is equal. So you claims principles. So pretty much everything that we had appear, right? So, actually, just going to copy this incident off, retyping it some. The seeing of our use is equal to a new claims principle. However, we're actually going toe have, ah claims identity with a value. So the claims identities that have these claims Sorry is going to have Paris claims. All right, you know what? Let me make this a bit cleaner. So let me say fire claims is equal. Toe the function. Call toe fire screams our passing in the token content. All right. And then once you get the claims in this variable, then we're goingto say that the claims identity has these claims on any fighters. Do. Come on, look at the constructor. You see that? We're asking It's asking for the collection off claims on then I can say the key. That associates are the authentication time, which in this case was JWT. All right, so we have that user on, then the next Lyon says that we return the authenticated users. So we're going to return everything that we have here. That whole return statement is applicable, but instead off a blank I at blank claims principle and identity. I'm going to return user because it's the same claims principle with an identity with claims this time on. So I'm just returning that object inside off the authentication states. So this is all saying that Get the token. If there is no time talking, nobody's loving. If there is a token yet expiration date, if it's expired, then remove the token. Nobody's loved in. If none of these get hit, that means you want to get the claims. Get the user, build a user. Andi, say that somebody is lovely. That's pretty much all that. All that you see. Aren't you ever done quite a bit off, put upon to know. But we have a little bit more, and then we can pause and move on to the other activities, right? So next I'm going to say, log in. So I'm going to create my own function inside off this authentication state provider when we to see public facing task, love the yeah, all right on. Then when we call log in. All right, What I want to do is get the same token, right? So remember that we have the log in function in the repository. Right? So I did say I wanted to change the state off the up to do that, I need to call something inside off a p. I stayed provider, but I can't just call the get authenticated. See, that is getting I need to set the authentication state manually. So I'm creating ah, function call logged in or long in whatever it is you want to call it. But this function is goingto be what we call at the end off all of this a p I call and Paris ing and so on on. Then I was changing the state. So let's build it together. So when I say logged in, the first thing I want is the same token. So we'll be retrieving that from local storage, right? All right, because we just set it, all right. We just set it in local storage. So what? I'm changed in the authentication state on. I mean, arguably, I could have just passed over the token, but that's fine. I mean, just to make sure we're consistent If we set it here over here, I'm going to get it from the local storage. I'm also going to want to parse the claim, so I need to get the content on. Then I went to do pretty much the same thing that I did up top, where I'm going to parse the claims right on. Then once I have the claims, I'm going toe build my user. So So this is gets remembered. This is get. So if I close the browser on, then I go back into application. What this is doing is that when the application knows it cause to get which is going to check for the same token and then remind the application off who is loved in, that's what's it's happening. Over here is where I am longing the person in South ability users. So when you log in, this is what's going to get called and build your user for the first time. All right on then, after I have built the user so pretty much all these lines off court kind of look like a pop of boats with fewer checks in between. After that, I'm going to save our off state on. Then I went to say task from results. New authentication states so pretty much it's the same function call. But I'm just checking what off authentications that is after I parcel that information on then based on what I get back from this function call, I'll know, notify the application off the state change. So then, you know, if you put the statements if the person's loved and then show this otherwise so that all of those actions will be taken out once we put in once you notify off the state change all right? No, our next one would be law goat, and then we can call it will not really called Rafto implemented in the the repository also publishes Put Lagos since we're here So long notes is basically just changing the state toe . If there was nobody there pretty much right, So So I'm basically just building a blank claims principal and I'm going to do that on Call it nobody. So nobody's home right on then. These last two lines pretty much are still applicable side of copy and paste those. But instead of passing in user, which obviously doesn't exist here, I'm passing up nobody. So then we're notifying off this. Then we're no different application of the state. Change that? No. There's a blank principle on no identity, no claims currently available. So long the person holds. All right, so we're done with the state provider. Let's go back to our positivity and then just finish off this activity. So you see, it was quite a bit off work. And then when we get back with before crossing on the interface, right, So after this and I want to change the state off the up, that means I need the authentication state provider. It So no, we have to go back on, inject that dependency. So I'm going to go there on then say that I want a new object, read only authentication state provider and initialized that off course in or constructor. So we have authentications, the provider and our object on. Then what happens is that we need to call Ah, authentication states provider toe actually do the log in right? So authentications, they provider dots. But then when I do, the doctor noticed that I'm only getting well. An event about the state changed, But I'm also only getting the get authentication status Sink right. Some went after kind off, do an override slash typecast were beside it. I'm going to have to let it know that it is really the A P I authentication stay provider, which is my override, which has the custom options. Right. Um, well, then all I need to wrap these in a breeze so that it sees does one big object. So this is the type casting on, then. I'm just seeing this all of this type cast an object. All right, then I see dots on. Then I see logged in, right? So I can just say love being semi colon. All right. And it's a synchronous after how it. And then we're good to go and just make sure that's a SIM card. Good. So this snow will say that after sitting the local storage, then in the user All right, Another thing that you're probably going to end up doing is sitting the defaults requested of So remember that every time we call the a p I, he needs to have the default request header. So we have the default request. Fedders. So clients that before questioners kind being R I s GDP clients that descending r p a communications, not authorization. Right? So we needed that authorization header limit desperate. Klein is equal toe a new incense off authentication hitter value on then the header. The type was Beerer. So he needs a possible a beer token and then the value. Togo is talking that talking. All right, on there we go. And that's pretty much it for over logging. So we I mean, we can when we come back to tested to see if everything works as expected. But then we just finish up for the logo. So for love boats, the first thing I'm going to do when somebody wants to love Otis, remove them the item from local storage. I mean that they think on then I'm know, going toe love the person oats. All right, so then it's just the same function Call, except I'm seeing log boat instead. Off logged in, right. So the person's clicked Lago tar indicated that they want toe love Also we removed token on , then go ahead and long the moats. So this was quite a bit off work. So see you in the next video where we finish up
41. Setup User Login - Part 2: Hey, guys, Welcome back. We're in part to offset up our log log in functionality. And we did quite a bit off work in the previous video and we have quite a bit of work to do in this one. But let's just school right into it on. Let's get started at the start of that CS file. So in this file, I need to add to school in the senses one for our over at provider. So we just created the FBI authentication state provider. So I need to add scooped for that on then. After that, I have a bit more complicated line to right where I went to see services that at school tin in the original authentications they provider on, Then we amusing p for short can be providers. I guess you can look at piers, start for providers, and then we're seeing get required service. So you just add those two lines at school ap i authentications. They provider Onda had skulked off. Indications did provider on. Then we go ahead and put in the option p to get required service on that custom class. All right. No one is getting toe a bit more fun. All right. So little school were toe over pages and we're going to start creating over logging pages. So I'm going to go toe. Add on. I'm going to add a new item, andare components or raise a components of Goto. Weber is a component, and it's going to be called Log in that razor. So I go ahead and add that on once it's created the first line off boredom, when the change is the page, so we're going to let it know its path to be slash logging. I'm also go ahead, going to go ahead on inject um, the authentication repository Onder, the nav aviation manager on I'm calling the object Navigation of manager. I find it easier to see. Right. So now, manager, what we see here, where I'm getting the red lines cause I need to include some literature, friends and the register. We actually put in the using statement manually. All right, so let me just copy the southern went to need them later on. You see how you can do it without needing to put the using statements every time. But for now, let's just work with it. All right? So no I have everything there on, then I'm just going to set up this form to just at my registration form. So I'm actually just going to come here on copy everything, even the cord. I'm just going to copy all of it because it's going to be fairly similar. So I don't want to spend time retyping stuff that's already kind of have. I'm with the pace, and then we just go through and fine tune the differences right? So instead of seeing register, no, it's going to see a log in. All right. It's something went wrong with the logging attempt. Um, this is going to be handled logging instead off handle registration on. Then the next change I'm going to make is I don't need the confirm password field on. Then the button is not going to say, submit what's going to see a logging on over register. It should really see register. So me, just what I can't me that change again. Me that change if you want. Sure. All right, so then moving on hand Logging obviously does not exist. Someone to change over the task toe handle log in. My model is not registration model this time, but it is logging model. So I'm just going to change the model reference toe logging model being equal to a new instance off logging model on. Then all the few should not back sessions, have any problems with the Villagers and password mapping back Andi in writing this scored , I realized that I really don't need this field and I'm going to show you why I don't need this field. So we're going to use the response which is a bully in any way to determine if we should show the era are not track. So I have the love and model handle handle. Logging virus ponds is equal to the Ofri poor docked log in Right now we're passing over a model. So remember, the log in is no going to say and let me just go back to the service quickly so we can refresh our memories when we call. The logging function is going to get the data, send it up in the request assess. If it was true or false right on, then we're going to do all of these wonderful things to log in the person afterwards, right? So because I'm getting back our bullion here I can say if response then love manager. This is enough Manager, which means that if their response storms like that's true, if I get true, they navigate to the home right in the same way. In register I had went back at gone boxer and put slash log in right So instead, off navigating home, I said. Now we get to slash logging after your register which to me is more logical. So what I'm saying here is that if the response is a positive one, then go ahead on debt. Navigates home. By that time, longing would ever really change the state on everything off the user on. Then I can see um else Well, then I actually don't need this else. So if response then never get away, right? But then what I can change appears that I can see if not response. So let me let me just get them. I thought so. Make sure I'm not miscarry or something. If not response, Then display this which means responses after the falls for this to be displayed. But it's not declared anywhere, so I'm going to declare privates. Boolean called response on it's going to be what the true initially right then. So if it's equal to true and the page loads, then this won't evaluate the trousseau on See that error message? Who are then? I'm saying that the response, which initially has a value of true, is going toe away to the results off the logging. So if long and returns true, that means this didn't change. And this is still true by the time it gets here and we never get away. If the log in field this is no false, so this didn't happen on this state will change, right? So that's all. Dynamic Blazer makes this thing. Once the state change, once the value changes anywhere they have an if statement or something based on the value, it will automatically react. All right, so that just got contents into fire, fewer lines off court on. I can just go back over to register and re factor it in the same way. All right, So I came over here and made the same changes. I declared bull response. And remember, if you feel to put on public or private on the on the object that you're declaring it will automatically become private, right? So we were there away, the response off the registration attempt. And if it is successful that we never get to log in Ondo, otherwise it will display or error message. Say, see that I did. I repeated this letter on you see whole we can make it Ah, bit more dynamic. So I don't have to repeat this all the time. So that is for our logging attempt. Let's make some other interferes changes while we're here. Let's go over to over up dot Razor. This is what you're up that razor should look like. So we want tohave rotor. And we would have changed this section to say author, as road View on would've wrapped the lay old view inside off cascading authentication states. So these will be responsible for allowing it to enforce authorizations across the different razor components that were you building. So after you're finished with those modifications, we can go over to our menu. And if you remember, we had set up some links, um, logging and register. It's under both wire to go where they're supposed to go. But the reality is that nobody really wants to see logging and register. Other times you're loving, you probably want to see a 16. Seeing you are loved being on a logo button. And if you're not not being, then you want to see the log in and register. So we're going to modify our menu to display the different items based on the person's off the indication status. All right, so what I'm going to start by I'm going to start by removing these two while I'm cutting, not deleting, going to cut them because I'm going to use them again on then at the top credible form. I'm going to create a new talk, and I'm calling it authorized. Authorized view. All right, so authorized view open and close on, then. Inside off. Author, as you I can see authorized. All right. So watched an authorised person see in this section versus what are not authorised person should see in that section. So I'm not authorised. Person would be the ones to see over logging and register links, right? However, somebody who is authorized and I can just copy and used by the same allies are if you realize I'm actually retaining the same ally with a class and so it's the same design. But what I'm doing in this one amusing on why person? Andi, I'm displaying the identity name. So remember that when we were parsing the claim and I said I needed to add a special clean for the name, which would have the seam value as a subject, which is the email, that's what this is, right? So say context are user that identity, that name. We're getting that name from the list off cleans that we added to the user. All right, so that's what that is. So when somebody's authorized, they will see that as well as another six on on this one will be for logo try. It's It's another L. I just copy N P. So I think I'm changing here is that the treff is Lagos. This one doesn't have any trip because it will never get to anywhere. But this one is going to go to the love boat on. We have our spun on. I just used on our circle left indicator back arrow for longing haute. So that's our next component for navigating toe logo. Then I need a component that is called Lagos under users are. Just go ahead and click. Add new item on we're creating a newer is a component called love boats. All right, on then, love what is really going to have very simple court? As a matter of fact, let me just Well, let me remove the industry. There's nothing needs to be displayed on would replace it with the page route, which is slash love votes. All right on, then. I'm going to have two things injected some without my using statement for my contracts on. I was injured the authentication repository on the navigation manager. All right, and then inside off this we're going tohave on override for ah, function that gets fired when a page loads. So we're seeing protected over at a synchronous task on initialized a sink right on Then what that does is tell the page what it should do once it's initialized. I'm was going to say once you're initialized, then I want to call La goat in my repository on. Then I want to navigate our way too the home screen. So Lagos, remember, will change authentication state to nobody's home on. Then we just navigate home on then the rest off the authorization views and everything will kick into place because authentication state has changed. But I was quite a bit and it's been quite a bit off work. So let's just go ahead and do one build just to make sure nothing is broken on. After you've gotten to successful builds. Are the two projects have successfully being built? Let us go and see what's happening. So I'm going to in my authentication rip depository. I'm going to put a break point here at the end off getting the response are then puts that the first statement were the responses of come back and they were going to go into the boat moored and ensure you have multiple projects. I do entire. For whatever reason, I took it. Also, I went to go ahead and sit it again. So I'm sorry I have to start over, but I'm just going to walk you through the steps again. Just in case you're in my shoes will toe properties off the solution on then under start of project, you select multiple on you see, start on, start our it's a P and you in that order click OK on, then let's try that again. And so we have were wonderful applications. So you see that we move the log in tow above the home, are good straight. Let's try and log in. So let's log in first as customers that bookstore dot com that's trying to the logging on. Then we are going to shoot arberg points. And when we do, we can evaluate our response. So when I hover over response to see that I'm getting a status okay on if I go down into the contents Well, all right, let's give it some room. So let me go down to the line where it's going. Toe trying gets the content. All right, So if I look inside off contents, then I see token on that talk and string, Right? So, like I said, because the field is talking and the string is there were d serializing it into token response, which has a field for the token. So when I get to the next line, our token variable is no one tohave the string. All right, so there we go talking are talking objects. Our know how is that string called token. Right on then We're saving it in local storage. So I'm just going to go and skipped down to the last line here. Were returned true on. I'm just going to show you inside off the browser in local storage. So if I right click, go to inspect element or developer tools so you can disperse if I if you have f 12. Sorry, but when you goto application on, then in application you go to local storage and then the site you will see that you have this us talking. All right, so this is this is another one that I had from another experiments. I'll just delete that possess not necessary. But we have off token. So you see here is attempting to reconnect to Serverless because we're here holding or progress looking at all of for handiwork. So let me just press if I have to continue on, then I think cleats logging more than once. So when it actually goes in, you know what is No. The authentication state has changed because we're seeing the display name writes. Remember where added the subject as the name claim on that's what's being displayed here on day. We have the logo buttons, so no, we are confident that our long in functionalities working that it successfully parsed are the claims from the token on Got the information in the way we need it. All right, So if I go ahead and click lock go, let's see what happens on. But nobody's home. Everything is blank and we're back. Turn on Authenticated State. All right? No, I want to come out of people more than I'm going to run an experiment of the menu so that we can share in this together. So in the knave menu, I'm going to add another section for author as use just for experiments. E. So I want to display hole. You can show something toe one role and not to another rule. Right? So I'm going to create another authorize view. But this time it's gonna have a parameter are an attribute called Rules equals Administrator. So then, inside of this, I just have something called Admittedly cried on. Then I want to do another one just like that. And then this one is going toe have the rule for customer on. Then I'm going to say custom early. So that means when somebody who's an administrator logs and they should be seeing the admin link on when a customer loves him, they should be seen customizing on. When you're not loving, you should be seen. You should see neither. All right, so let's go ahead and go back into keyboard. So let's try this again. So log in. Onda went to log in as Delia, who is a customer, and it in my break points. I'll just remove the break point and let it continue on Dwell. We're not seeing what we expected and I suspect it's because the area does not have a customer rule attached to her. But I'm just going to go ahead and get the token strings to inspect elements were the application. So I'm just going to debunk this one myself instead, off tryingto people application of this Take a look at the key on Art Deco auditing nor pad on. If we look, we see the t the token. So we get the subject that successful. But then you notice that there is no rule attached, right? So if you look at the previous one you see now we got the rules administrator role on then here she does not have the rule because I think in that maybe we created her before we set up the rules section. So there's no real attached to her. There is no claim. So nothing got fired on the situation of the authorizations, right? So let's try another user who probably has a customer will attached or, well, let me just try and add mean, firstly, so let me try the admin log in, and we see the ad middling showing up. So at least we know that it is working toe whatever extent, right, so the ad meddling shows up. If admitting being a short for you, then maybe you can backtrack on ensure that you had set up the administrator user if admin didn't log in. Also, remember that if you're using the admin that we had to cede, um, that's I would have, or we would have set the user name. So it's actually looking in the using the infield when you're logging in on it. Based on the court of the roads in the user's AP I controller. It is signing in using the user name and password, right? So I believe when we did the seed users, we said admin is the use and human and admit bookstore dot com is the email address, right? So does make sure that that's his cart. You can always go into the database. Andi puts the user name to be the email address, so put it for both the normalized using him on the user name and in Dragon, and you should be fine. Otherwise, you can probably just go ahead and try and create a new administrator user on. Then try that again. All right, but at least we see are logging functionality working out? We do see where the rules authorization is working, as expected. Let me try a different user, have during a bookstore dot com. Who is a customer? There you go. So if we try to register somebody new, so let me try and register somebody on. Would you see Paris at book Stood up Comma me Have carrot started astray. Touch that book startup. Com. Use the same password. Andi. Well, a sentence seems in the button, and it changes What? Not quite what I desired. But that's when. So when we click register, it will be the A P I call and then redirect us to the log in screen, right? So if I say that I'm logging in a statute bookstore, not come and then log in, then we see touch logged in. She's a customer, so she sees her customer leave. All right, so we see that we just tested into in the registration on log in stuff on Yes, there, certainly to things that we need to clean up on normalize along the way. But the large beat off the work is done. So one thing I want to clean up is the the register button, so this should be register All right on. I don't think there's anything else any other major issue. The only other issue, like I said, would just be making sure that that they use the name in your database is actually the email address. Alright, because remember, we're asking the person's along with email and password, and we're checking this by default. Is checking the user name feeling on the email address field. So if the email address is not in the user name and normalize use Indian feels, then they will not work. All right, that controls over user distribution. Andi, with initial settle before, believes application cause we set up all off the files, We set up the log in under registration. And so when we come back, we'll just review all off those things on Check our changes in tow. Our project on Get up.
42. Review and Add Changes to GitHub: you guys, Welcome back. This is over a little review and chicken video, and we'll just be going through some of the modifications that we made and in no particular order. So I'm just starting off with the user model. Remember that we feel, though the logging model with the email address and password fuse that we need. We also went ahead and created the token response model that we used to parse the data coming in from the token response. After Logan, we added the log in love boat pages and did some modifications to register page. We added a new provider in the form off Ikea authentication state provider on this authentication state provider had us, including the local storage libraries as well as the token 100 library. Which a load us toe, Paris or tokens? You know, um, make some evaluation, save the token on manipulated, talking in the way that we want. We also added log in lago log notes and custom functions in this file. In our authentication service, repository added the log in and logoed functions on in the log in we d serialized token store the value using local storage. So we also have to inject that on the authentications they provide into our authentication repository Andi logo to be just call it and remove the stored token in our menu. We made some adjustments where we realize so we can authorize certain parts so we can authorize something to be seen by particular rules that customers might be in. Or we can just do it based on the authentication state at the time. Right, we made sure to add the new endpoint for logging here on for the up the razor. We changed all the defaults in tow, authorize road view and cascading authentication states wrapping off the layout view. Some of the most important changes, however, happened in our start up that CS, where we may ensure to make representation off our state provider so we can inject it in on also associates that custom class with the state provider inside off the dependency injection container on. Then we also injected the security handler inside so that we don't have to declare objects off these two everywhere. We just, you know, just injured dependency and then use that accordingly. So with all of those changes made, we'll just go ahead and check in the solutions we right click, go to commit, put in our message on That's my message. So after we've put in that, you just go ahead on Click the IRA and commit all and sink on. Once that's done, we can move on to our next section, where we start setting off some crowd operations.
43. Setup Author Repository and Service: you guys in this lesson will be setting up our author repository for our blazer. You I application on dime just Oh, I just have the base repository file open so that we can refresh ourselves Us what we set up here. So have the base trip lustre, which is inheriting. Ah. Http. Clans on pretty much it is going through the creation deletion update on. Well, just the crowd operations. Right? So all the crowd operations, the base functions are all line here. So the idea is that for any class and in this case author, we're going to inherit from this based repository where t is the class or the entity. So we have to create on author, entity or model. Since they're using the keyword model over under or you you I side on, Then we'll set up the report stir. So let me start off by creating the author models. I just go to my mother models follow both add class. I'm calling it author, and then I go ahead and hit ad, and pretty much this author model is going toe have to embody whatever it is that we intend to pass through the A p I so remember that we know the response we're getting when we look upon author, um or at least the documentation within to indicate to us what feels we need tohave are represent to get the full data from our Jason response going from the FBI. So in essence, we really needed to look like and going into the project. I just bring up the author class. Or maybe to be less data related, the DT oh, class. Right. So at least the author detail, if you want all the data coming back, would have to look like the author details, since that is really what the get author is returning on, pretty much the it has all of the fields that any other detail would be, including in its specific operation. So what I'm going to do here is actually just copy everything from the GTO on, and I'm just living this way. Expediency. Obviously, if you're developing on top of on a pair that you didn't build, then you would have to do the same thing where you create a class on then model feels based off what feels would be in the Jason response are expected in a Jason request. So I just have this model off what the author will look like. Right on, then. Well, this has a list on books. L, uh, put this as a book because we're going to have a book model, and then I can create that. Just generate that in a new file. We'll get to that one later on. I'm just doing that so that we have all the fields covered. But what I'm also going to do here is add some validations because then when we're using the model, especially in the view, because remember that these aerial view models that we're doing, we will need to have some validation. All right, So I went ahead and added some validation of our idea, and then I put required over everything up to the bio. Also put the display names first name, last name on the bio on. Also put a string length validation on top off the buyer. Right. So all of these things remember coming off a four authentication activities would play some role, invited it in the form before we actually send over in the data through the FBI. So know that I have my model class that I'm going to be using to taxi the data from and to the application. And between application and the FBI, I can no go ahead and create my author repository to in heard from the base repository. Right? So I'm just going to go over to my contracts for the first and I'm going to add a new class are interferes way Know that sent interferes. Aminu interferes on. I'm going to call it I author repository. And then we add that on then if it's interferes, I always have to remember to put public. Otherwise it will give you an era. Right? So we're creating a public repository on then this public repository are sorry. This probably interface called I author repository will be inheriting from our I based repository on. We'll be letting it inherit within the context off author. So we just go ahead and make sure that we have representation off that model class called author? No, no, that we have the contract. We have to set up the rip Lester. So in the service folder, I go ahead and click. Add, and then I'm going to add a class called author repository This time Andan author posit Ori is going to inherit from the base repository once again in the context off author. So notice the interfaces inheriting from the interferes. But then the concrete classes inheriting from the concrete based repository within the author context as well as its contract. So I'm just going to go ahead and include that. All right on then, after implements. Well, I don't actually have to implement anything because everything is already implemented inside off the base. Preposterous. Only if I had, like, a another operation that I wanted to carry out in the author repository. Then I would have the custom functions here on then implement them here. But as it relates to the base functions, I don't have toe implement anything again inside off the repository because they're all in the based repository, right? Know what this is saying is that I need to initialize I CTT clients or I need to inject the client as usual. Http client factory on the spur clients. And then I include what is missing on then I need my constructor, and this construct is going to look a bit different because now it is saying that when I inject in tow, the author repository I must also initialize are passed over the injected value into the base. Right, That's all that's doing. So once we call author Repository, it will dependency injecting the http client into the author repository as well as the base repository on through the author repository, we can carry out any operation, but we have toe do it relative to the class author so I can't use the same report stir for books after that. So I have to create the book model different from the author motto. Andi have to have a different repository for book. Also. Now, after we've finished doing all off this, the last step is to make sure that I have it inside off the start up. Um, bootstrap per side is going to configure services and make sure that I add a representation off high author repository on the concrete class, and they'll go ahead and include whatever needs to be. I think because of the eye authentication ones, we won't need to include anything again. And then that's it. So when we get back, we will start setting up the author pages and the setting of the retrieval off the data through the FBI
44. Setup List Authors: Hey, guys, Welcome back in this. Listen, we're going to be setting off our authors index page, so I'm just going to get started quickly on under pages. So the same way that we started segmenting our pages in tow folders right on which creates a new folder on the pages. And I'm going to add new folder, and I'm going to call it Well, sir, or authors. All right. On then, on the author's I'm going to add a new component on this is ah, razor component called Index. All right, so I'm just trying to keep some structure. We have index here, which is the home page, as you know, But then once you get to the author section, I want tohave a landing page and the first page, Naturally, you would see or want to see when you click on others would be the authors in the in the database. Pretty more trick. So that is why I have done this? No, at the top. I'm going to make sure I specifies the Ph path right on. Then. The difference now is that I can tell it's that it's part is just slash on what you tell it . It is authors, then slash. All right. So by that logic, to get here, you would have to type authors slash So that means back in my knave menu. I'm just going to meet that change before I forget where I have the past two authors being just authors. I'm going to see authors slash Sweet knows it should go authors on, then the default page there, which is or index pace. Remember that the name off the file doesn't have much bearing on the path it is whatever we put as the page path that really matters. No, I'm going to need a few things in this page one I'm going to need to inject, maybe the navigation manager. I'm also going to have to inject my repo on, then to use the report. That's all three people that we just created in order to use that I'm going to have to imp supports the name spaces and so on. So we are seeing when we're doing the authentication that for everything I had to put in the using statements I don't want after putting using statements every single time I'm making a page because I'm going to be using models, and I'm going to be using contracts a lot. So you know on then if something changes, I would have to me the change everywhere. So that is why we have our imports. I let me see if I can find it quickly. Our imports dot razor or underscore imports that result when we include things here. It's included generally, so I can and I'll just go back to the log in page. I can just take these old all right, and I'm just going to contend and I went to wait for all of the era. Stop here, right there in the era school because the using statement is no missing. But I'm going to put them inside off the imports that razor on. Then, when I go back to that page, you see that the red lines no go away because, well, it's no seeing the reference. So by putting the references in imports and making global to the entire up so moving on back toe index No, I have already imported what I need so I can start working with, though it's much fear. Like I said, I'm going to need an instance off my author, author repositories. I'm just calling that one underscore report, and then I can get started with the fun. All right, so let's see what we have to do there. So I want toe print a table that, you know, for each author that I get back, I'm going to be printing the rules. So if you've ever used NBC in the past or anything dot meant related, we have to generate the table. Then this should be from the the territory, for if not, then Well, we're going to do together anyways, so I'm going to start off with a table. Andi, using bootstrap. I can meet the stable look a bit more presentable than it would by default. So I can include my table table dash, responsive on. I'm just going to see table. Well, yeah, Let's just deal with those to the table until we're responsive on. Then I can have a t t head section right on. Then in this section, I'm going to have a TR on. Then the TR will house some TDs. Huh? So the TD's will have the headers or the headings for Well, actually, there would be Th is my butt so th because their table hitters. All right, so one table hitters for different columns. So one column would be the first name. The other one would be the last name on then. Well, I'm not sure I want to display the entire bio right here. So for now, I'm just going to use three off them and I'm going to call this one actions, right? The options will just host some buttons for us. So that's in the head section off the table now in the body or to get started with the body and went to say t body on, then in T body. I'm goingto have a loop to go through the collection off authors. Right. So we haven't declared anything. That's a collection of authors. So I'm going to do something. You're going to see some errors, but we work them over, so we're going to have a four each loop, which is going to save our author. Some was going to say for each far author in, and I'm going to call it models. So I like to call my any class that is representing the data context for ah component are for our view. I just call it model. It just it seems clear it. Right. So for each author coming back inside off the model on, then what I want to do is generate a rule. So for each record, this represents a record going back from the list off records that would have retrieved we want our role on the Metro is goingto have ah column on. Then we have three right now. So it's just going to be I sent author, meaning I want to print the value from author, and I'm sure it will say first name. So intelligence isn't helping me, because as far as that's concerned, it doesn't know what author is because office going from an unknown called model. So that's fine. I'll just leave that alone for Nome for soon started Thought last name on, then for the oxen sick son. I'm going to puts in three buttons. All right, so the buttons that will go into the action section would be Barton on, then I'm goingto have class b t n. So we get that nice wool shop button on beach in dash primary. So one is for view, all right? And I just put like a hype as a separate. Well, they're going to look nice enough. I don't need a pipe, so I just leave the total sum without three buttons suggesting some aesthetics, right? No. So that, you know, it looks presentable inside off the button. So this is going to be a view button. This is going to be like an edit button. So I would probably wanted to say Bt and warning. So it's orange. This is going to be a delete button, so it would be read, you know, danger. Sorry. BT and danger not delete. Right on, then. Inside off the button. You know, you have the option off writing on the word edits. Writing on the worldview. I'm goingto use some icons here. Someone to say spun and then class on then would have seen some of the icons being used in the nominee or so to get an icon were after. I think the library's called open icons. They can always go to their website and look at, um, what I call options. There are, But I'm going to say why Dash book. All right, so I think that would look nice enough as ah indeed as an indication that that's the view, right? So once again, if you write all the word, then you get a button with the icon on the word, if that's what you desire. So for warning on for so forth. Sorry for edit. I'm going to put a pencil to suggest to somebody that that's all you idiot on. Then I think that they have one called delete, which would give me, like a little extra suggest, Well, this is to remove. All right, so this is just some aesthetics. Webvan previewed it yet. So you know, I can appreciate air, probably anxious to see what all of this is going to look like. But let's get into some of the court things and in Sartre's roads, our arrow here. So in court, the first thing that I would always recommend you do is declare whatever it is that you said, the model is going to be declared, So we're going to declare on a list off authors write on. I'm going to call it model and then look at how that red line just disappears, and then everything falls into place on. Then, if I was to use intelligence than you would be able to see everything for the model because no, it makes sense, Right? So that is why we had the red line. That being said, you don't have to do it in that order. You don't have to radiation of. Then you declare the model. You could do this first on, then right additional. And it probably would have been quicker for you if we did it this way. But I was just trying to make a point. So the order in this situation really doesn't matter. It's just whichever one you find easier to do. All right. So the next thing we want to do is to tell the component that when it lords, it should lord up the data or at least feel this data because right now this is what you call No, there's nothing in it. It's just there. But there's nothing in it, which I can tell you would lead to an error when the speech laws. Because then he would tell you that there's another exception because there's nothing here for to generate the table from. All right, So what I want to do here is say, override over default form shown for when the page loads, which is called uh while we're going to its from protected function. Firstly. So I'm going to write off all off the qualifiers for the function first and it's a task on initialized a sink on. Then we close the braces or Prentice's open the braces on then inside off this function we want to see model is equal to on. Then we can alleviate the result off our report. Remember, replays are object that represents author Repository, right? So re pull docked on. I want to get seconds they get And then I have to get some member that we defined to get to have one that will return all and then one that will return a specific author, right? So institution want to get all and all it requires as an end point is our as a parameter is the endpoint or the girl right? So we stored all of four euros inside of for static class called in points so I can just see in points but then noticed this No Oh well, it's already included. Why's it included, or why is it available? That's because already imported it so if it's not on, you didn't do it. You can go ahead and import it into the static because that's something Well, we're going to use all over the place, right? So, endpoints that authors in points. All right, on dso What's what happened? Is that one the pages load It is going to meet this call on. Then model will be filled. No. The problem is that because any synchronous quality, it's not the beach is not going to sit down and wait until this has been loaded up. So that means if the page lords on by the time the page loads model is empty, we're going to get that no era. So what I am going to do here and you would have seen it in some of the examples, I think in the fetch needs a page. What they did was they had an if statement with the content. So they said something like, If I'd say, If the in my situation model, which is holding all the data, if that is no, then do something else display my table. All right, So I'm saying that if when this Speech Lords model still doesn't have any data, then show something else. You know, on what I'm going to show real quickly is just that alert on. I'm going to call it alert. Dismissible color dark or let me use at Ehlert. Secondary on, then I'm just going to say lording data. So when the page lords on, do you know the U eyes open visible. But this is still it's still waiting on a response from the FBI. Because you don't know how long this FBI call is going to take, please our noses to say, Well, you can display something here, so the user knows that it's happening, and then once it happens, then we get over table. All right? All right. So, no, I want to tell you this for test run. I'm just want to go back and make sure that I have the correct parts for And so this is authors on. I'm just going to go ahead, hit, run, and then that. See? All right. So when our application lords, I'm just going to log in quickly as somebody who would have created in the past. All right? I'm loved in on. Then I'm going to go over toe Authors Andi. I set a break point here on the get for based repository. All right, so let's just step through. I'm just going to jump straight don't toe after we've sent off the request. And this I don't think this is going to work on die from current than I'll explain why. So we got ah, 401 chord in our response. So for one means on authorized. So if you remember, when we set up over a P I control of four authors would have authorized the entire controller. And so even though we're logging in the up the FBI sending us that were unauthorized And so if I just press continue here the symptoms that we're just going to see loading data. So I mean right? No, I'm returning. No, just No, um we can probably make it that we return something a bit more intuitive on. Then make a decision based off what we return. Right? So what I'm going to do here is I'm going toe stop debugging on. Then what happens is that when we created the clients, remember that we're actually creating a new plant each time, so, yes, we created a client here. But each time we're about to do a request we create a client on. Then what happens that once his client is created, it sends off the request. But we need to include in that request, the authorization header. So, yes, we may have done it in the past. I think we did it in the P I off state provider was there? No. We did it in the authentication repository, Onda. We created a client in the same way. So what happened when we assigned the value here was that we assigned that default hitter too. This particular instance off the client. So actually, we could have done without this land. Really? Because it included it as a bearer token in the hitter for this client's not globally. So what I'm going to have to do to modify my base repository file is I can create a function that will just say, get Bera talking, right? So if I creates a private's private sorry privates task to return string All right, Private chasing task to return a string. And I'm just going to call it gets beer to can. All right, just make sure my spelling is correct. on. Then what this is going to do is just return or get the beer token stored in local storage . So that's going back on boring the school where I c get Where is? It's I have 1/4 where I get the bearer token. Oh, no, it's not in this one. It would be in the authentication state provider where I c get the item called off tokens. So I'm just going to borrow this right on. Then what I'm going to do is let this function just return that So a return on, then I'm seeing get local storage on return. All of that, which no means after inject local storage in tow. My based repository. So I just hurry up and do that, starting with the declaration off the new property and including whatever libraries need to be included. And then I just put that inside off our control. Calm constructor. Sorry, Andi, just break clients. I don't go too far off the screen on. Then we'll just do the initialize a Sean here. No, because I've included loca storage in the base repository. I will also need to make sure that my authentication repository No, not authentication certain. My author repository, which is inheriting from the base, also has representation. So I will need to inject also the local storage over here. So I'll just copy and paste these lines so I can move a bit more quickly. All right, on then, I in base just c comma. Local storage writes. I'm just passing over that into the beast also. So that's just a little surgery we had to do, but ultimately the purpose of the surgery so that we can look into the local storage when we're about to do Ah, I request on get whatever talking is there so we can include it in the client. So I am creating a client object right here on day. I'm just going to go back to my authentication repository on inside off the function on logging where I say client that default. I'm just going to borrow this, so I'm just copying and pasting court because I have the quarterly, but it's just in a different place, right? So right after I create the client, I'm goingto pace this line. But then I'm going to say the the value that is being passed here is the value that is going to be returned by our function. Get beer talking. All right, on then. I just go ahead and include. All right, So every request we need the bearer talking some literally swims a copy on door. Sorry. This should be a weight. Alright, some just in tow. Copy this line on after every where that we create a client object. I'm just going to pace that there because we need the bearer talk in each time we call or a p I All right. So I just added it to create, update, um, and gets all of the up the functions in the base repository with no sports, despite to get the beer talking on included in the header. So let's try this again. All right? So let's try that again. I'm already logged in as door and I book stored up. Come on, get me. Just make sure you take inspect elements. Goto application Onda And make sure that the token is they're all right on then. When I click authors, you see loading data on. Then it hits my break points on. I set a break point in the controller itself this time, right? on get author. So if you didn't have wonder, then you're probably already seen the authors. What? I had one there. Because what happens is that if it is, if an unauthorized request comes in, it would never, ever heat that controller, which is what happened before, right for that action. Sorry. So because the authorizes there and it was authorized with the token, No, we hit that on, then I can just go ahead and click Continue, which brings into my origin on break point showing me that I'm getting back on. Okay, response on. Then. I continue on DNO. I am seeing my authors coming back from my AP I So that is how the bearer token works in practicality. So we did have quite a bit off work, are owned it both sitting up on both setting off the client toe. Use it. So no, you have a real life example off how it works. And you can see that we're first name, last name on actions. And then we have our little buttons with the icons. So everything is coming together nicely? No, Like I said, it was not very intuitive that it just returned. No and we didn't do anything with it after just returned. No, because then it would sit on their seeing low data forever. Right? So what we could do is probably include another field that will or may be a different return type or more complex turn. Return time on this return type would probably have something like, um, what is the response scored as well as maybe the act, a few for the actual data to come back on. Then we can evaluate if the response scored is okay, then. Fine. If it's not okay, then we show a message accordingly. I'm not want to do that. No, we can leave that as a little activity. For now, we know that we can load off the list off. Authors coming director from the FBI, we see that our authentication is working both locally in the U. I. Onda across the FBI because we were ejected for good reasons. And no, we are accepted once you fix our court According to All right, so that concludes over sitting up, off or in experience for the authors. When we get back, we'll start making these ones work starts with our view
45. Setup View Author: Hey, guys, Welcome back in this. Listen, we're going to be setting up our view component for our authors. Now, The reality is that we're not showing all of the details here on the listing page. There are other things, including maybe the bio on what's the Communist? A profile picture. So right now we're in their first name last name and want that when we click on the button , that suggests that we click it to view the particulary record that it will navigate away to a different components, showing us that relevant information. So we have two options and, well, I'm going to say their toe options. What? I'm going to use one, and I'm going to focus on one, because what? That one is very easy. So firstly, we need to change our buttons. So I used buttons initially, but what I should have used where ankle tags are usedto facilitates this method off navigation. Right? So ankle tags are the most widely used Navigare son, um, tags in html, of course. And there, close to the city on a trip on set an address. So the address that we're going to be using here would be the address toe slash authors because we'll be creating a component in our authors, Waldo I'll be calling it view on then I need to pass in some parameter that you will know that it needs to view this particular record on that. That particular perimeter would be like the I d. Right. So I'm not displaying the i. D. Here because I don't think I need to show you the office I bought behind the scenes. You need it. So I have to say at sign author dot i d and that will create that linked to know that it should go to the view or whatever component has this address. All right, so let's focus on the view right now. So in order to get there, I'm going to have to go to my authors folder, go ahead and add a new component, and I'll be calling it view. All right? Some people call it details. So whichever one works for you on, then I'm going to make sure that it has the address. Author slash view slash on. Then I make provision for the fact that on I d values going to be passed over. All right? So then, when this in the index link when it mops directly will be looking for any component that has, well, this as its page Onda a section for some value. All right, on then over on the view said, we have to make sure we've made provision for that. No, because we have a parameter coming in. I have to make the pH know that I have a parameter. All right on this parameter is going to be a public on because we literally becoming over a sticks. We know it's a number, but it will be seeing their sticks. We have to say a string on. Then we get on set, all right? Or maybe we can just get well, let's just leave, Just get onset. So right now, if you made this integer, we know it should be interred here, but I believe you would run into some compiler era. I don't think you dollars to compile if used integer or anything that's not indicative off some string value coming across so right? No, just for a quick preview. I'm just going to see I'm wins a print. The value of the idea when he gets clicked right. So, author, just right. Author. I d on, then I'm just going to show you the value that is coming across through the parameter. So let's just state that for a spin. Let me just make sure I have everything set here. All right, let me just click. Start. All right. So we're loved being here on day. I'm going to go ahead and click authors on. Then I'm going to try and views. So if I just hover over them, you'll actually see in the links in the bottom left corner. If it's visible enough, the different I devalues, appearing at the end off the link, right? And then if I click one, it goes over and it shows you off. The i. D three I were seeking three being possible. Or if I go back, I look at another one that I c five and five. All right, so we know that we're passing over the parameter successfully. So now let's actually get to the fun part, which is retrieving the data on displaying it on the page, because seeing the idea doesn't make any difference what we want to do. We see all off, you know, everything about the author. So I will have to inject some services here. One being my author, we post I'll just go over and get the line off court for my author Repo and injected there on. I will probably also want my navigation manager. And I'm actually going to call the objects enough manager this time instead of never mind. I just find it easier to say on its, you know, more indicative off what it what the object represents, right? So inside off the cord, I'm also going tohave another pervert property and this one can be private on this will be off type author, right? And this will be my model on I'm going to initialize it toe a new author object. All right, so what I'm going to say here, though, is that on the initialization off this speed, So I want oh, on the loading off this page. Or rather, when the pH has loaded. And we know that this is our function for that on initialized a sink. I want toe retrieve the author with this idea. So I'm goingto say author is equal to or sorry model I called object model. So my model for my page is equal to awaiting the results off my report, which is by author people that get on Then remember, we have to get so this time I'm going to have to pass in the end point. Andi on integer i d So I have my in points file dot authors and point comma But then I need the i d Which needs to be an integer So that means I need to say int i d And I'm just going to use lower case idea because this is uppercase idee, right? So in tidies equal to on that, I can just turn into that parse off the I d volley Communion from the parameter. Right? So now I'm just convert it. Say you have different ways to convert induct parts. You also have convert not into 32. So, you know, this one might be a bit more common in that part is limited to only string. So I mean this situation, either one can work, but I want that I devalue to be passed in as the parameter. All right on, then it will populate model. All right, so then we face the same thing up top here, Where? When the model is empty, it may not load or we'll run into problems. So what I'm going to see is IFOR at Scient. If model is equivalent in all, then I want to display a nice message or something else on. Then we want to display over actual page with the data. All right, so while it is empty, I just use reuse this diff this alert and I'm saying loading author details. So you see that I'm repeating court here and one principle of programming. Don't repeat yourself. I'm using these. Dave's a lot on with the exact style, A lot. So we look into how we can put that into a component and just card a component. Andi even passed in the message that we intend to have displayed right now inside off that I want to display the authors details so I'll just use a table again on I'm going to give it the bootstrap classes, and then this stable is going to have a slightly different format. So Well, let me I'm just going to pay attention to some aesthetics here, so I'm going to put this stable inside off a Div on. I want this live toe have a class call. Thus nd does maybe four so it doesn't stretch across the entire canvas. It just takes up four spaces or four columns off a potential 12 and then inside off that I want this table right on. Then this table is going tohave our role Someone's R t r And then in this T I'm goingto have two TDs. Remember, teas are columns, so this one is going to be first name on. Then I'm going to inserts at Sion Model docks on, then put the first name. All right, Onda, always generally discourage placing, um, you know, text directly inside off the TV tug. So, you know, you probably want to put it like in a P tug or something, but for no, that's fine. We just want to get the data displaying. So we are first name that we have last names. Some really just want to copy and paste these and change the details accordingly. And then we have last name. We also have later on we'll have. We'll probably double back. And after email address and other details where I know we have very few details of biography so we can see a little boat biography on. Then this would be that bio. All right. And then we see that we have books, so we would probably want to display a list off the books on the news. So after seeing the authors details, All right. So I can probably put on a little hitting here to see off the details author details on. Then I'm going to put another section under this table where I'm just going to see a cell, Just break it a little so it doesn't look toe giant on. And then I say our books author's books right on. Then, for the books we can for each or what? I need another table, Someone to put the books in another table on then Or you know what? I'm going to get a little more creative than just using another table. So instead, off a table, what I'm going to do is use ah, card on the list group. So, looking at some bootstrap documentation, I see that they have a special card where you can have, like, a little header on. Then you have the list group, and then it will come out looking like this. So that is what I want. So I'm just going to copy this cord aan den after we see author's books, I'm just going to paste it right. I know we just refractor it together. So instead of having this same featured, I'm going to say author's books. So I'll take this age for Tug. Cut it, place it inside off the six son for the heading for the card hitter, right? Just fix my indentation a bit on, then for the list group. I'm just going to say at sign for each on that will be vier on. That's a book in on. Then the collection here will be model docked on. Then we have books. All right, so, you know, to get this working, we're definitely going to have to fish out our book model. So, um, just bear with me. So for each book inside off the list, off books that will be coming back. Right? So you see that we have the least off books, and if you're not so sure what I'm referring to Remember when we set up the model, we took all of the properties as well as included a list off books. So in the Jason, Easy realizes you will d serialize toe ah, book right. Each book will take on the book characteristics, and all of that is phone analysts call books. So have to make sure that we have representation for the properties off each book inside off the book model. So we'll do that enough us or finish off this design. So for each book that is going to be retrieved, what we want to do is put in on L. I. With the class list group item on. Then the content will be at sign Book on may be at San Book dot and, well, it's an empty object, so there's nothing to bind just yet. So let me just lead all the fat, fix up the formatting a bit on, then we turn our attention to the books. I'm just doing everything one time soda after double back on. Deal with it again, right? So what we're going to do know is go over to our book model. So have the book model, and it is blank that can't work right. Quick fix. We just go back toe the a P I on remember that what we're really doing is just mapping or let me look at the detail or we're really doing is just mopping back the properties that would be coming back from the FBI. Right? So any FBI call for a book will be retrieving all of these data points. Right on. I'm just going to take all of this, so I'm just going to copy all of this, come over to book on within the context off our U Y. Application. Right? We're getting the type. The idea, the year, the You know, all of those details may be the price, right? Um, author I d on then we don't have all the details, but we do have author. So for any book that is going to recruit, we want to get back author details, if at all possible. You know, when we're when they are implementing our bookstore, Fred, but for no, this is what every book will look at. So we're working on the book, ey, I'll put in the validation and so on. So I leave that for no, but back to our list here. When I know, say book, which is remember that object. So it's a book docks on No, I can get some details So one detail I would probably want is the title Onda Maybe the title on the Let's See the Price So at san book the title on Down the Price And then, if you want you can probably add a on uncle tight here to see Bino. Our view later we're would set up that want you Look at an author on the books that they've , you know written which would be showing up in this section You see the title, you see the price and then you can click to see more later on we'll fix that up. So I know we just want to get the view for the author Open running, right So we have all of those things were getting that back on. We're filling out all off the books. One more thing that I think would probably want is a button that would, you know, go back Hope right are some hunk attack. So I mean, you have two options. Like I said, eso if we use the button a button kind of on a trip. So we have to set up a creek event on that would navigate us one. So I'm going to use a button just so you can see how that would work. So I'm going to see a button, um, go back but toe, but to list right to list on, then that would have what you call a tricky event. So you have to see that sign on clean right on. Then that sign on click, you specify what function should be called on click. So I would say backed a list. All right, that's the name off the function. So I Red line is going to appear because there is no such function. So why are that Red Line appears? I'm just going to go ahead and create the function, someone to say, Private, I'll just make it void on Call it back to least on. Then I will see to it that you should use the navigation manager Andi navigates to. And then the link I'm going to put here would not be slashed. But you will be slashed. Authors slash So that's the index page for our authors. Sexual rights. So little. Stick this for a spin and see how it works out All right. So I'm here looking at the list off authors. I go ahead and click view on, then. All right, So I'm getting on her here of boats, the model dot books being blank. All right, So this is one of those areas that I told you. This is why they let us put in these statements to say, if it is blank, then you know it won't cause on her, so that's fine. We can fix that with an if statement. So let's get out of people more. And then I will see at science, if on this estimate is just going to evaluate if the model that books All right, So that means that author, who I tried to view, has no books. So if modeled out books right is equivalent to know there are no books returned. Then what I'm going to do is display this section. Say, say, I'm using the court against. If ever I wanted to change the style, then I would have had I would need to change that at least four places by No. Right. So no books to display books. Well, for this author for it On there, we see else. We want all of this fancy chord that we just wrote. So I don't need to show author's books and no any list group to say, Oh, they're books. I'm just going to say there are no books for this author or shoulder, so let's try that again. All right, so we're back to where we started on Let's Try again. So I'm not sure which author has any books, but we just dragging with the same author with an A K R. So we're not seeing This author has no books. We did see a flash on on flash off and off course. We need to style or button boards. I believe the reason at least we're not crashing. So that's good. So I believe the reason that sweet we saw it flash on is that while model was no, books was no. But then I believe that once model is loaded, the collection off books it's no longer knowledge is has account of zeros. It has something but the county zero. So what I'm going to do is I'm going to see if it is no or wandered up. Books that won't is less than one right meaning? You don't have any books you have. Zero are fewer books, then when The kinds of negative one. Right. So you have less than one book, then we want to display this. I think that should take care of that on. Then. I'm just going to put a brake tug under here on. Then make sure I style my button on dso. That would be class on Bt nbt n dash on. Let's say line and I'm going to see it on line secondary. All right, on, then. Inside off the. But I'm also going to put one of those icons, right? Something You know, I'm not focusing too much under on the look and feel, but it's nice to just do everything on get a full appreciation off for everything comes together. So I'm going to put in a span and I'm going to call my open icon class, and then it will be Oh, I do. They have a Buck Barrow. All right, so the media skip buck word. Uh, let's try Skip Buck word. All right, so let's try that one more time, and we know that this author has no books. I'm not sure if we have any authors with books, so if you want to temper of the force, FBI cause and create some books with some authors attached to them. But at least we want to make sure that our view issuing a properly. All right, so in back on view the same author. And we see author details all of the details on DNO books for this author, and we get our nice toe battle is button looking nice and sleek under there. So I mean, it's not the prettiest interface, but at least we can see what's coming together off. Worse, we can, you know, refine it a bit. You can take off this view on may be. Have author details more pronounced. We can meet these the text on this side board instead, off looking just like that on then off course, with more data for the biography, there would be more detail for display and then off course. Ultimately, we have no books for this author, which will come to life when we start putting in books. So that's it for setting off the view. Later on, we'll do some essential fixes and clean up the interferes a bit more, but for no, that is whole week 100. The floor between the different components. So we passed data between components and how we handle the loading off data once again, inside off each components.
46. Setup Update Author: Hey, guys, in this video, we're going to be looking at doing on it. So we just did view. We already know how to have them on index. So the edit is going to follow a lot off the same steps as the hallway set of the view. Starting off with our links. I'm just going to copy this, a trip that we already have for the view. Barton. I'm now going to put it in the edit button and instead off author. I'm went to see Pity's all right on. Then we go ahead and we create our new components. So in authors, we add a new component and we're going to call this one it once again with a capital E on. Then we outfit our new component with the page wrote. It's supposed to have the report injection and our navigation manager injection. Alright, a minimum. We need those things. If we need anything else off course, we'll add them along the way, but just notes that this step, this time missing edit on it, is still waiting to know which record edit, right? So we still have to retrieve the record on then we have toe bind them toe the form. So, actually, a lot of the code that we wrote inside off the view component is very applicable, right? So I'm actually just going to copy, Actually, all of this I'm just really going to copy all of that, because we still need to have the parameter we need to have our model present on. Then when the pages initialized, we need to go and fetch, right? So we have to fetch the record that is going to be edited and put it into model, and I'm still going to have the back to least button on. I'm also going to have another button. That's his cancel. All right, so I'm just going to go over and see what I already wrote on what I'm just going to take. So I know I need this button. All right, so I'm just going to copy that over. All right. I want to take I'm going to change this edit author. All right, Andi, just the same way that over here we should have had view author. So just save you. Author details out that's wrote off their view, offer details. All right. Bring some consistency. Tore design. Alright, Any hole. The other thing I would want is the if statement. So while I'm here and I'm on that line, I just did the statement, some just copying and pasting once again. So we just move quickly on then have the if else in this if statement. So if it is no All right, so now I'm going toe want this live again? All right. So I'm going to create a shared component because I'm sick and tired off taking this cold every time and taxing it across. Right? So what I'm going to do is go over to shared and then, well, let's look at one that exists already. If we look at the survey prompt component to see here that it's really just an alert on git has some bine doble text called Title and it's really receiving a parameter called title. And if you look on the index page how it works, it's just calling survey prompt, which is the name off the component on, then passing in the message or whatever text should be inside off the sorry inside off the survey problems. All right, so we're going to be doing the same thing. So I'm just going to go to shared click add at a new component. I'm going to call it loading message, right? Nothing too fancy on then inside off that component or someone to do is I'm going to take the Dave on its default takes that were always displaying. So I'm just going toe this right. Pace it inside off the component. All right? So, no, we have that. Dave on its is loading author details. So this one, I'm going to make it dynamic because I'm going to use this same component with its author or a book or user details. Whatever it is, this is the one I'm going to you. So instead, off making this static. All right. And once again, we're just pulling the example off the survey prompt inside off the court, I'm going to give it a Parmenter like what we have been doing, So I'm just going to go ahead, give it a parameter on this one is going to be message. And then what we're going to do is just buying the message here, so I can probably put this in an H three tag instead of just having it printed like that and then see message. All right, So every time we're going to call this component, we're going to tell it the message, and then it will print accordingly. So disclosing what I don't need when I am going toe when I'm going to edit on author, I can no see call the component loading message on. Then it gives me the option to specify the message, and then I can say loading author for edits or whatever message it is you want. I'm just, you know, doing it, for example, sick. I know that I have this component I don't have toe copy and paste that particulate live every single time so I can put the same component call inside off the view on that, I can say loading author details, all right. And then I can do the same thing over inside off the index where we originally created it, right. And then I can just say loading author are loading authors. All right, so that's a nice way to create. You know, reusable components and hotel parliament arise them. So when I pass that message in on, it gets that it will just render that instead off on H three. Tuck. All right, so I know that that bitch is out of the way. The next thing I want is art form. So if we're anything, that means we need an edit form. So you would have seen the edit form from when we did over user log in and user registration stuff, right? And the edit form, we specified a model to be used, which we know we have model for that, right? Whatever you call that object, that's what you put there on. Then I would say something like on valid submit. Then this is what I want to do. So I want to edit author. All right, so then off course, we need this function to be defined. So no, I need toe define this function, which is the its author. So I'm just going to create that function on. I'm going to make it a private avoid Onda. Split it there. I won't be doing anything just yet, but I actually need the form. All right, so we know how forms will look. We have the give these bootstrap forms and then they encourages toe have a class called for mdash group, all right. And then inside, off this form we have a label on. Then it's a good idea to saleable four. And then we put the idea of what you were before, so I'm just going to say first name, all right? And then the labels text itself is first name. All right. And then we have a components. A built in component in the form off input text. Good. And then input text is going to be bone so we can say that Scient bind value. All right, I'd signed buying value. Sorry. Intelligence is missing up. So that sand buying values, equality. And then we say at sign model dot on then the property that it binds to which would be I don't need outside. Sorry. It would be model dot First name. All right. Aan den I givet the class equals form. Dash control. All right, on then I can give it the i d so that it will bind. But to the label, which is first name. All right. Off course with the reform. Sorry I missed that step. I should have the data annotations validator because you have eternity ations in our, um author model on, then we should also have validation. Summary. All right, so I'm not going toe put the validation message underneath that they already have the summary. So I just leave the summary there. Andi, I'll just move along. So I for first name, I'm going to just copy and paste that and do the same thing for last name because they are basically the same thing in terms off their requirements. It's just making sure a change of the ideas and the binding. The next thing I would have is the bios, um, when toe have that also. But this time I'm going to use an input text area as my components. Right on buying this back to bio. All right. Make sure that everything looks like how it's supposed to look on. Then at the end off this form, since I only have three properties that were tending to right? No First name, last name, the bio. So see, Mr Step here. Just double check and make sure you're not missing any changes. The last thing we need is the button, the submit button. So I'm just going to put button on, then this would be that it's Oh, ther. All right, on, then. I'm going to me. This are button by bootstraps Bt and Bt and dash on. I'm going to make it primary, all right? And then I have my but released buttons. So I'm just going to put that back to list button here beside it. So either edit or you go back to list either. Submit Editori, go back to the list. Some putting that there. All right, Andi, if we want to can purpose proofs of the Eddie button with an icon or two our boards. Another thing that we want on this button is the type. So type equals submit does actually wanted to trigger the submission off the form which will, if it is valued, passed on to this function. If it's not valid in the validations will be stopping it from being submitted. All right, All right. So I just modified the submit button a bit I put in the span Onda put on a pencil icon, right? And it says edit. Or maybe I said should say something changes right? That's that's a bit so suddenly changes because you just made some changes. One very essential thing that we need on this form is the I d. Right. So, I mean, we could probably truck the i d from the parameter because we already have it here. Eso real eventually. Usually what you do is hide the i d somewhere in the form. But then we're really tracking it through the this parameters. I really don't need toe hide it on the form again. No, on a valid submission are you know, when edit author is called, what we want to do? He is Ah, See is success. So we want a bullion Sorry. His success is equal to await and then we call a report And then what those are people have for opiate So we call be it and then it wants us to pass in the end points for the u R l So I'm just going to see in points in points dot and then authors in points. All right? And then and then we can disperse in model. So it was saying that we could track the i d through the i d parameter, but what really happens? Is that on, uh oh. Well, I haven't area here because this needs to be. It's not avoid. It should be a synchronous stops. But before I get to that so I can dispatch in the model So task. And then when I just passed in the model the what was boned me change. But then what wasn't boned and prone to changes still being persisted inside off the model . So when we retrieved the model would ever treat it with the I D. Anyway, on when we pass it back, it would already know what the I. D. Is and have it for future use, right? No, we need to check if it was successful. So I'm just going to see if is success. Then I want to navigate away so I can just see navigato. Or maybe I can just call back to this. Let's see if that works. But the list there we go, since that off rewriting this line, which is going to bring about toe the list anyway, I can just see if its success, then call this stand whatever it's supposed to do, it will do all right else. If it was not successful, then we probably want to display some errors. So I think we did that in the log in page where we said if there were any arrows to displayed and display them. So what I'm going to do is define and mother variable here. Onda we're calling it is failed. So you'd notice that sometimes have private. Sometimes I don't. Once again, consistency is key, but by default, if you don't specify private or public, it's going to be private right by default. So then his field will become true if that was not successful. So it's failed. Equals true. All right on then, what I can do up top here is See that if that sign Sorry, So let me just backtrack a bit. I said He's failed to be falls by default, so it will only get to true if success feels right. So then I can just see. And I actually just go with the marriages store because I did something very similar there . Where and then here it is again. I'm repeating a danger alert so I could turn that into a reusable component at doses Lodeiro message. Right, So we have low message for waiting and I can just turn it into a component. For some reason, this sometimes goes to read. I'm not entirely sure, but by the time I'm building, it should fix itself. All right, so, so far, we have everything. Let us go ahead and test that I have an extra button here. Let me just remove that because I move the button beside the subject changes. So I have suddenly changes on. Then I have the other one to go back to this. Right? So let's test it out. All right, So we're back to our list on then. I'm going to try and edit on a case when I click. Edit. There she is. All right. So her details came up nicely and quickly on then she is on awesome author. Right on, then on going to submit changes so we can go back to list. And this justice that first. Okay, cool. That works. Let me just re type on. Then I'm going to submit changes. And then let's see. All right, so no, something went wrong. So you see, I just copied and pasted that that era Dave without changes in the tech so we can make that entire usable component. But something went wrong. And let us see if we can be about what went wrong. So going back to my based repository court and the updates method on I'm just double checking to make sure that everything is whole. We said it should be so we have the put we have the URL on. I think that we didn't form or I don't know if I change this afterwards, but I suspect that the U. R L is malformed because it should also have the idea touched. If I'm not mistaken, let me just go back to my documentation for my a p a. Onda. That is indeed it. It should be slash authors slash i d and I took off the i d for whatever reason. So I'm just going to come out off the boat more before going any further. All right, so I'm going to put back 1/3 Parmenter for the I. D. I'm also going toe concoction. Eight it onto the string. So we have the URL as a string on and let me just make sure that my endpoints have that trailing slash search should be a p i slash author slash and then we're concatenation the i d i d value right there. But then off course. If I change the base repository, I have to change my contracts. So I'm not sure. I think maybe I changed it when you guys weren't looking for whatever reason, But let me just revert. So if you're your contract should look like this for the update with the I. D. On your based repository should have the the three parameters on Beacon coordinating the idee onto the string. All right, so let us try that again. I got an error because I need to update my method call. Right? So I'm passing in the importance, the model, and then I just a model dots, I d. All right, So let's try this again. All right, so we're about to the edit page already made my adjustments where I said she is on awesome author. I submit changes and something went wrong again. So I think I know what it is this time. It's not that we malformed the Earl. I think it's just because we're not acting. So I'm going to set a break point in my base reports story right at the update call after we get the response. And then let's look again. So I went to submit changes, it sends over the request on. Then it says, forbidden. All right, so that means our validation on our authorization stuff works, at least on the A P I level. We need to make it that no non admin should be able to get to the page to begin with. Right? So right here in this scenario, we have door on that bookstore dot com who is just a customer on. He's able to go to the authors this on, actually click on it it author. So we want to make him not be able to see that link one, and to even if he navigates there, not be authorized to even get to the page. All right, But then, on the A P, I said, we can feel confident that it's at least validating that the person trying to do the operation has the authority to do so. So let me love Boat as the user on love back in as an admin. All right, so nowhere back at this speech on, we're using our admin on going to try it again and let's see what happens. So when I submit changes and it hits or break point. I can no see that we're getting back no content. So, no, we know it was successful. Or at least the deduction is that it was successful so we can remove the break point f five . Let it continue. It goes back to the start. And then if I view the details on day, I still have a break point. Just free that up. When I view the details, we see that it was edited successfully. There we go. So we get the edit. We got it working on DWI. See where the AP eyes actively rejecting, um, you know at Thames to call it if the person is not one authenticated or to authorized to carry out certain things. So that's what the Forbidden Response School, which is for all three and believes a 41 is on offer at four threes. Forbidden. Andi. That's what we got when we realized we were using an inferior user. So the bookstore users are customer rule can view so they can come to the lease and I can click on the details and view the books and everything. But what they cannot do is actually edit and delete. All right, so we need to modify the Interferes and we'll do that later on. But we'll be modifying the interfere such that when a customer logs in, they will not see the editor and the delete button at all. And even if they try to navigate directly, you know somebody who is smart on my tough figured out the pattern that might try. Authors slash view r slash idiot slash the i D. We still don't want them to be able to carry out anything on that page, so that's one of the things we'll be doing later on. But for now, we see that over it. It is working fine, Andi. Once again, if it's not working, just make sure that you have no spelling errors along the way. So I've had some spelling errors and solve these errors were really because I didn't spell things properly in the project on its you know, so that can derail you and make you think that you have a big era when it's really just a minor girl. So just make sure that the spending is consistent. Make sure you're naming conventions are consistent on when we get back. We will look at finalizing the section by a lowing ID mean users toe
47. Setup Delete Author: All right, so we're back, Understand? We want to tackle deleting. So we have you. We have update and we need to talk of the leading we already established that only admits can do the edit and delete on. We'll be maintaining a session with our admiral on. I'm just going to Lagos and get the party started. So coming back to our index page, we're going to just copy this link because the deletion is going to look just like the other two on instead off every time going to say deletes. Now, after doing that, I'm going to create a component because what I want is that when you delete from the table , it's going toe. Are you took the lead from the The list is going to bring in tow. Ah, Page. That's going to show you the details off. What you're about to do it and ask if your short particular train So I have a new component . It's called the leads on. Then I'm pretty much just going to be copying and pasting a lot off court from the edits. Because a lot of the court, like where the established looks pretty similar. So the page this time is delete. All right. I already have my repo on my navigation manager, Andre. What? I can change the heading later on on. Then what else do I need from the edit page? I'm basically just going to take everything here. The parameter, the model, the ISS failed pretty much the entire section writes, The only difference will be what I actually put on the trick event. Right? So instead off. And it also we're going to have delete author and let me just Well, everything else can stay. I just seems to report endpoint from updates to really it on delete the delete endpoint is taking the string. You are on the I. D s. I don't need the model objects there. All right, so that's it for the layout off the deal. Well, the cord Well, that's a start for the cord section off the delete file, the view. But then I'm going to borrow court from the view section toe display, What is about to be deleted, right? So, actually, I can just take everything on this speech from the loading. If statements toe printing the details on, then I'm just taking all of that even don't to the battle east. All right. I want to take everything on this pitch. All right, But then I am going to include an additional booking on this piece. So So let me just go through exactly what's happening here in case of lost. So our delete is pretty much going toe navigate with the same i d parameter that we used in the view on the edit when it gets here and it's loaded. When the page lords were supposed to retrieve that record from our A p I and there will be using that data to display. So I'm saying that the display here is going to just like it would have under edit on the view, Pidge. But then at the top, I'm going to see our You sure you want. Sorry. You want toe delete this record. So this is like a confirmation page, right? Say, could lead is going to come over here asking. Are you sure you want to delete this record? Because you're giving the person a chance to review and see Oh, it's the wrong record. I'm sorry. Let me go back to list. All right. But then if they are under months that there are direct place and they're about to delete. So I'm just going to duplicate that battle this button and then I'm going to say, Delete author right on. Then I'm going to put the spun icon to be or I Andi. I think it has like, well, just reuse delete. So I dashed the lead. Or is it's just delete toy already avoid ash. This is a nationally attract so and then the class here will be BT and dash Danger. So this is a red button saying that Hey, you're about to delete so you can proceed to delete author or you can go back So the on click here won't be back to list for the on click will be. Deletes author. All right, so on click, we call the lead author, which then cause over deletes meth odd passing in the model with the models I d. On calling the authors and point, and if it's successful, we go back to the list on. If it is not successful, then we say it's feel is true on then that is supports. Toe. Give us a little era section, so let us focus on that air section. So back in the edit, we have that era section. So I'm going to turn this into a component. The same. We returned the loading message intercom pull it right. So I'm just going toe cut that go over to shared odd on. Then I'm going to add a new component that I'm calling error message. Go ahead. And at that and then inside off this I I'm just going to put the same alerts on, then make it a danger on. Then I'm binding. This too. Some variable called message, which is our representation off a parameter. That's we're going to be calling message, right? So we can no possible or custom error messages on. They will get displayed on the mucus changes from a Pete out to maybe an H three times. So it's more pronounced on, then inside off anywhere that we would have loaded it manually so I can go back to my editor reason on his field will. Now I'll see error message. That's my components on. The message will be equal to a sermon by bar. The one from the author, the the register page Sergeant. See, something went wrong with the operation at a bit more generic. All right, on then. I can reuse. This is failed on my delete section. Right? So I just copied and pasted between two components. Andi made a whole new component with very minimal court because once again, we know what we're getting ourselves into. So it's easy to just navigate around, right? So, no, we can test this one on, make sure that our delete works. So I'm just going toe, go ahead and going to devote more. All right, so where they released off authors were already at me, and I'm going to click. Deletes. All right. So I don't want to delete anarchy. That's the wrong person. So I clicked. Delete, and I see that I'm not the wrong records. Only go back to list on who I want to delete is really just a bantam. Because I have two records. I'm going to delete one off the right Andi. Okay, Jyoti. Last name biography. Nothing. No books. That's okay. Let me click the lead author on Boom. We're back at the index speech with one less just a bent on record. So or delete works just like that we wrapped up our road operations and I am saying road and not crowd because, well, I have no way to create a new author. So that's another thing that we need to implement, right? So usually from the expedient have abundance is create. Also on. We'll be working on that in our next video.
48. Setup Create Author: you guys, welcome back in this video, we're going to be tackling the create functionality for authors. So to begin this operation, the first thing that I deem necessary would be a button that allows me toe navigate their right. So we've done the buttons for all the others in the l section. So if the model is equal to know, then nothing happens. Right? But then afterwards, when something does, Lord, I wanted to load with the button, someone to see Angkor tog on. Then it riff. And then this trip is going to be a bit simpler than the others. Where it slash author authors slash So authors slash Crete. Right? So I don't need any apartment us because I'm going to be creating something new on. Then we give it all off the bills and whistles that bootstrap gives us a bt nbt and dash. On day, I would meet this one primary. All right, on then, the Texas going to be create new author and then I'm going to give it a little icon on the icon of choice is a plus sign. Right? So we have a button at the top there. That's going to say create. You also know while I'm here. Another thing that does occur to me is that this is displaying while it is no if they if the author, well, it's no while the a P I call is being made. No, after the FBI called is made, then model model is no longer know it's, but then it might have account off. Zero. So what happens when it's the first time the application is loading right? The FBI databases emptying the authors table on DSO? This page is trying to load the list, but then it's not know, but the current zero. So we saw something that that's in the view where we checked for no or the corn beings being less than one right. So in this situation, we said, Well, if it's no, they can display that only for the current easier than you display this That was to avoid the Arab. But the reality is that the cones came back a zero or less than one. And that is why we see this consistently with ocean. An Arab. No, The point off that monologue was when the model is no longer know. But the count is less than zero. Do we really want to display this table with nothing? Right. So we're just going to display a table with the headings and then we'll know body. So what I'm going to do here is put another if statement inside. So I'm not putting the create new author in the statement because if there no authors and I want to, but invisible to see creating you also. But then I want to tell the world. So I'm going to take that. Just cut it on. I'm going to put another if statement in here. I want to say if model dots right, and then remember, model is expected to be a collection so modeled off count is less than one. Right? Then we can display something else, and then I'm going to put that my table safe. It's greater than or if it's not less than one, then fine, right. But then, if it is less than one, then I can put maybe a loading message. All right, side, as you reuse my component on Instead, the message is going to say there are no authors in the data stores, please. Or did the store please create author to begin right? So I can just put this in quotation marks Or was not Company didn't sing. Try single quotation marks so that the person gets the idea that they need to click. Creates new author to begin. Right? So this is just a little mediation off handling Hold the interferes looks right. So at this point, if it's the first Lord, if you go into the database and delete all the authors, um, then this message should come up because the author count on the model corn to be less than one right? So it's no longer no, but it's no less than one. So it's bio standard. It's still no, but I'm sure you can appreciate that. It's treating no differently from when it can retrieve a cone and see that a ConEd is less than one. All right. No. Let us get started with our new component for create. So let me go into authors, right click. Add new come new item, which is going to be a new worries, a component called creates on. Then I'm really going to just be copying and pasting court. Ah, lot here again so I can go over to my edit on Die can probably borrow all off this. So everything on the edit page. Um, I don't need the perimeter stuff, so just copy that to begin with. Let me. I also need all off the using statements I neglected under me Go back, get my using on the beach path and everything. All right. And then the pH here is create with no parameter. All rights creates more parameter. I have my enough manager have Mary pull. Um, And then I went to see create new author as the hitting up top. All rights, I have my eyes failed. So I'm going to retain that east field on then. I have model, so I don't need to check if model is no rights. I really don't, cause I'm loading a blank form someone to remove this entire statement. Here. Andi, let me make sure I killed the trailing brace, so I really just want to form on the Aargh. Aargh! These failed section. So let me just review this city. So really, actually, all I needed from the edit, I didn't need the statements. I just need the edit form which is going to buy into some model on this one to still have the invalid submit. And then instead, off edit author relentlessly creates author. We have the same feels because at the end of the day, the create is goingto need us to put in first name, last name and biography minimum we can see create offense that all submit changes. All right on there were about to list. That's fine on then. I believe that the court blocked by accidents are the at sign court. And then we start writing the code that we need. So the first thing that I'm going to declare is something for the model. Right? So I have my private objects off type author model, and then all of those red lines on the model will go away. Andi, I have is field also. All right, so that's initialized. Toe falls initially. And then we have to make sure that we have the two functions in the form of create author and battle ist on Die. Just took the liberty off, putting back in the court to navigate back toe. Author. So we have everything needed for this speech. Take Andi So hundreds some silly spelling errors. All over the place. So the next thing we need to do know is the handle. What happens on a valid submission off? Create author, right? So when I go down to create also what do I want to happen? I need to check. Um, I can see var is success. It is equal to away it. A call to my report from shun dots create on then, what we're creating requires the endpoints docks. Authors in point comma andan author object in the form off model because real, eventually what happens is that when you're creating the form, your binding, the value toe the field in the model. So once you feel this old you click submits on because that the model would automatically have the data Once it gets this far, we know it's validated by whatever validation standards reinforced rides through our validation, and it's annotations on. Then if this success all right, on, I just realized that I really don't need to have success on East Field. So what I can do is on I'm just going to do that. No, because, you know, sometimes you're doing something, and yet it just opens up in front of you so its success is going to be true initially, right? Onda up top. I'm going to see if not a success. So instead of having two variables that really are doing the same thing because they're both billions on their both hinged on if the call is successful or not, right? So I'm saying, if not success, then show the error message, which means that because it's true when the page loads this error message will not show no . Then I will say his success is basically, um, going to be equal to water Provided comes back from the repo call. All right, so then I can see if is success meaning this remains Truell. I remember that We're checking if it means through our By the time we're checking this, the only way it wouldn't be true. God starting off us. True on then it's going to remain true if this was successful, so then we can call back to list. We just never gave back to the list, which is then going to just pull back all off the authors from the from the FBI or through the a p a. Right. But then, if that changes right, then this doesn't get fired on Dwell. This would get fired or that state or change on. Then we end up with this arrow message. All right, so lets us state this one for a spin. So let's go to start. All right, So we're back at our view and we see your button on Dwell. We'll fix in the Little Kings about, you know, the spacing and so on later on. But important thing is that when we click our button, we navigate to our new page and then I'm going to go ahead and put in a new author, all right? And then I go ahead and click the button. Which brings me right back to my first page and I'm seeing my new additions. So creation works, All right, so the only way wouldn't work is if maybe the a p I wasn't running or there was some spending air along the way or some permissions issue. Remember that administrator should be ableto click this link and be able to do anything. So, Makesem, we'll be focusing on some essential fixes. Some off the loads. Um, you know, kings here and there on will also be putting on some authorizations on the links to make sure that they don't show or reject actively reject unauthorized persons from accessing them.
49. Essential Layout Fixes and Additions: Hey, guys, welcome back in this video. We're just going to be going through our pages and doing something that I deem essential fixes a minute of different ideas from me, and that's fine. But I just want to clean up the interface a bit, and I'm going to get started with my custom components. So in the heat off battle with probably made some decisions that, well, I mean some decisions that I am about to change, starting with my loading message component. No, I don't want on each three tuck and probably want an H five tug on. I want this to be an alert info and not secondary, right? So it's not as aggressive in its presentation. So that's the lording message on. I'm going to repeat something. Repeat a lot of it. I want the alert dismissible to also be a ville for alert, um, for era alerts, other dangerous, unstable once against the each five and not an H three. So I'm done with those two ongoing me modifications to my main leotards. All right, so in shared, you can go to me and Leo's on what I'm going to do in this particular file is Put the content inside off a card. All right, So I have my do some adjustment to replace that entire section inside off the main Dave with the card, uh, give information coming back from Bootstrap. I think I have one too many deeps here or once in sewa. All right, there we go. So what I'm doing here is I'm seeing inside off the content. That's the problem. Inside off the content air that we have been rendering just body under 60 million station. I'm going to put a body inside off a card. Dips would have done the card if with register and log in. Which is why I have them open also. So here I'm saying that I want a car that I want a card body tohave the body in it. All right, so that's what I'm doing there. So, for register where we were creating the card, I am no longer going to be using the card here on I am no longer giving this. Well, I can leave that with the car title, um, the car title class. So I'm no longer putting the card only in register, but no every single page will. Look, we will have that little border. Like what the log in and register p just had upon to know. Right? So that's register. I'm going to do the same for Le Guin. Take all the card, Diego that give. And I'm just so I'm just highlighting and using shift and tub toe, pull it back to the left. All right. And then I can standard as my error messages here. Say, See, I'm using the ones that we wrote first that something went wrong. Something went wrong. Instead, I'm just going to use my arrow message components so I can just change here. Arrow message on. The cool thing is, I want to change. Opening will change the clothes also, and I can just remove that, so I'll do. Oh, sorry. And then message. Correct. We need to pass that up as a message. So you just that close? All right, so there a message on actually don't need this closing part. It's a self closing call. All right, that looks better. Is there a message? And then we pass over the message that I was going to copy this so I don't have to butcher the one in logging as much. Andi, I've just been to see with the logging attempt and then removes this one. All right, so that's it for the main loads on the register and the logging so I can close those windows. All right, so I'm disclosing what I don't need and then inside off idiot author. I'll just add the class that says card title. So that's we know at all points where we are and it looks up. It's more organic. I could fits in right on just to current fall into spending spelling errors of the loading message. The error message. I don't think I need to make any more aesthetic changes here. But do remember that our edits, delete and create pages are reserved for our, um, for our I've been in street clothes right, which means that I don't want a customer toe navigate directly to any off these. So there are two things. One I'm going to hide it in the menu on. That's when I get to the index. I'll be hiding those buttons in the menu, but I also want to tell the page that only this particulary rule is authorized toe even. Look at the bed. So even if they navigate to it manually by tapping in the URL, this speed should still the rejects their attempts to get any further because they don't belong. All right, so what I'm going to write here is on attributes. That's right, another page we see at San attributes on. Then I'm adding an attributes called off the res. All right, so remember the same authorize attribute that we built in the a p I. It's applicable here in directly inside off the reserve component, right? So I can then say rules equal. And then I can say add ministry tour. All right. So even though the a p I is rejecting the attempts like we saw before toe create our editor or do anything that customers and supposed to do, even though the AP is rejecting it, we can build our clients toe also adhere to those rules. So that spares us the A. P. I call right, because each time maybe you're using a service that he costs for FBI call. So you want to let the client minimize those a pair because as much as possible, so in the delete we do the same thing on I'm going to also put this toe have the card. Sorry. Classique Waas card Dash title. All right, so let's delete I don't think I need to change anything else here Andan create. We do the same thing where we add that attribute for only administrators. Let the that the title have card dash title. And if you feel you know, a little flare you can probably put on each are horizontal rule underneath that so you get , like, a little line to show. All right, so I will put a br tug. You know, I'm just thinking a lot. I don't know what this is going to look like. I'm just doing these things. They can follow me if you want. You don't have to, but I'm just putting like a space between the title and then align and in another space before the next bit off contents. Everything doesn't look as close as we've seen it looking right. And then in the index raise or I'm going to do the same thing put in those lines, put in the class, but then in the index, everybody should have access. Um, I'm I'm already authorising access to the index speech through the internal applications. I don't need to make any special authorize model on top off that again. Right? So I'm just going a different way sick and authorize you see that we have the authorize view which are about to look at so well, we're in unauthorized when Index, no, on what we're going to do is set up that only the administrator can see this button. All right, so if I want only administrators to see this button we're not telling administrators alone to see. The spirit will want to limit the visibility of this button so I can say authorize view. So we'll see an author as you from a previous example. With the menu we can see rules is equal to add ministry ter. All right, on whatever issue Emily put inside off this authorized view, Todd will only show up when the attribute for the rules is satisfied. And so we can do that for our buttons also. So we have the view button the edit button and or delete points. I only want administrators be able to see those buttons, understand the cooked on, then see, authorize fuel rules equal add ministry tour on then and then inside off this authorized view section. I'm just going to say these are two buttons. All right, so let's take a quick look at what we get when we log in under. The two different users are. So I'm loving here as Delia on going to go over toe authors. And then I see here that well, I'm I'm seeing that border. I'm seeing my index speech a little daylight. Well, maybe I can remove that first, be our because the in the age dogs have a bit off putting, so that's fine. We have that line and then I'm only seeing the options that are applicable toe a customer which are to view. And then if I click view, he goes in Okay, I come back the list, but I can't do anything else because I'm only a customer. So that's we can enforce authorizations from the U I side. So on. Then you see that by adding the car to the me lay out. Any other piece that I would go on is also going to have that card kind off look and feel to it. All right. There is one thing. I'm going to modify here when it comes to my authors, and that's from the A P I side. So Randall is saying no books for this author, but I I'm sore. At least one book is there.
50. Fix Author-Book JSON Response: Hey, guys, welcome back in this video. We're going to be solving that issue where the authors are not seeing the books are. When we look at the author, we're not seeing the book. So the real reason is that we need toe. Add this line off court toe over Repository. Where we're seeing include the books, right? So authors for an author has a list off books, so we're seeing when you retrieve the authors to treat the list of books attached to them are included in the data. So that's what that line is really seeing. So we're adding that to the find all on. Then at a refractor, the court a bit more in front by idea where I added the same line. But I changed from find by our find a A think I think it was toe first our default a sing, and then we use a lambda expression to compare the i. D in the author record to the idea that we're looking for. So it's the same effect just at the different court on then the next thing we need to do is include from you get a library called SB net core dot NBC dot newton's soft Jason. So there is one here. Noone self Jason on. I mean, it works, but because were inducted core 3.1, we want the one that is specially designed for right, So we're going to get that. Don't load it in our project. Then our next action will have. Let's go over to our start of that series where we will be adding toe the act controllers a special option courtesy off the library. We just install someone to say Docked Odd new turns soft J son. All right, on, then we're going to open up. Some options are going to say Opie for charts are for short. Andi, I'm just going to break line here. Someone to say, Opie, let me just close the brace before I forget. So Opie or options docked? I want to serialize or sit some cereal. Isar sittings docked our friends. And then, if you look, you see reference loop handling removed. The most reference book handing. So a reference book means that each entity knows about each other. That's a problem, right? So reference loop handling is equal to Newtown Soft dots J son dots on. Let me just break the line here again so we don't go too far off screen. Newton's off that Jason dot reference group handling. All right, So we're telling O. R um controller that we want toe let Newton's off handle the loop referencing, and I'm going to say that Ignore some seeing override the attention you'd be being at in your attention. You be paying to the issue on that Newton soft handle it and noone Soft is just going to see. Ignore that reference. All right, so let us try and start our project. All right, So let's go again. So inside off for application, right? We were going to say authors, and then we bring up the list off authors. It may take a bit longer because no, there is an extra leg off, including the books. But once you're seeing that list, that's good, because I did it before. I'm not adding the whole Jason reference stuff, so if you just added it into repose terribly into the Newton soft juice on ignoring part, then this would never move faster loading message right on. Then, when I look at it like a Evans, I know that she has a book, and there we go. So that's the title of the book. The book doesn't have any price, so the data may not be a screen, but the point is that this is no longer saying there are no books. So this author, we're getting by the author on We're seeing the books here for said author, So we can first assured that that is fine. All right, on, that's it for this activity. So next up, we'll just review all off the modifications were made and then checking our changes.
51. Review and Add Changes to GitHub: Hey, guys, welcome back in this video just in to review some of the changes that we made in this section on diff there any other magnitudes that we need to make us we review, then you just meet them. So I'm going to start off with the word that we did in the based repository or the fact that we created the eye author repository to inherit from the based repository on once again. The reasoning for this is the fact that current operations will always pass through the beasts. And most of what we're doing with the author, repository or author author functions would be crude. So just having it implements the baster poster we despots in the author class on. Then he will take action against the author class to the relevant in point, as we specified, right? So in the based repository, I also modified. So that's the interface or contract were also modified, um toe include the local storage right, so that we can retrieve from local story to bear talking and included in the authorization hitter for each request, because then we need to make sure that the person is authorised to carry all the options. You may want to wrap these in track catches, right? So what? What might happen sometimes that based on the way the application, those who have seen it from Lord and authentication the accessing off the local storage might try to happen before some other things air in place so you can disrupt these intricate is to kind of minimize the crushing that might happen in your application. So we went ahead and did that with all off the requests, just getting the bearer token and including it in the header off the clients. We also went ahead and modified off our author. Well, we created author pages, so we created a new photo on we put in the components and we looked at the difference between each component and what we can do hold if statements help us still give visible problems to the users to what's happening, how we can create custom components. So I don't have toe keep on rewriting the same court, but you know, error message versus loading message on those kind of things. We looked at all weekend limits, authorized persons or authenticated persons based on their authorizations. So we started with our menu are, well, not well, we did it with the menu already, but we did this more so in the index speech where we said that only administrators will be able to view the create button on. Only administrators will be able to edit our view, the edit and delete options. So we also looked at whole weekend actually at that authorization to the page by adding that attributes to specify which rule can do what. So we did quite a bit. I know we're going to check in well before we move on. A very important thing that we did was to include in the FBI's startup that it should ignore the circular references, art or loop references on DSO. If you're doing a bigger project with more relationships than just an author and a book like I am doing here, then this will come in handy when you're trying to get those payloads with the author and the list off books are or the one entity with the list off the related entity or entities. So this will go ah far away in solving a lot of problems in bigger applications. So let us go ahead and check in all our changes. I distracted the solution. Go to commit, Andi. I've put in my message, added author crude operations and fixed some A p I issues. I go ahead and commit all Onda sink.
52. Setup Create Book - Part 1: Hey, guys, welcome back in this list, we're going to be setting up or create functionality for our books on this is going to I was doing quite a few activities, so just stick around and have fun with me. So we're going to start off by going to the books folder going toe. Add on. Creating Over Newer is a component which is going to be over creates And when the component is created we all fitted with its path at the top the attribute for authorization And we're only authorizing administrators on we're injecting the book repository as well as the author Repository Also made a street taxi create book No in or create former goingto have ah, new Todd. Well, it's not new. We've done it before, but the time is edit form, which is a specialized Italian blazer on. We're going to let it know that the model it should be attention toe is model on then on valid submit We wanted to handle create operation. All right, so obviously we don't have any model just yet, so I need to declare a model object inside off the cord, and I went to see a private book model is equal to new book. All right, now, there are number of things that we have to accomplish. And I try my best not to, you know, be all over the place and tracked it in a structured manner. So I'm going to start filling in the fields for the form. All right, so the 1st 2 things that we have in our form are our data annotations validator on our validation summary. All right, so that's just so we also need to add annotations to our book model. But once again, there's just go bad them one by one. So I want on input section for the book title. All right, so then using Bootstrap Smith odd for form, I'm just going to say leave class form Dutch group on. Then I have the label for the idea or for whatever property. Sorry element has the i d title on. Then we have our text on. Then input techs were binding. That value to model dark title on off course to give it the form control on the I D off title are the next feel that we're going to prepare for is the ISBN. So it's basically the same thing, except we change all the label for the text on the binding. So that's the section for the I s bien. We also want to facility the entry of a price so everything is the same. Except the input is no input number. All right, so the price is not a string, it's a numeric value. So we have to use the input number because we will get some form off era. Actually made that mistake already start Just pointing. Told to you that when it's numeric you have input number specifically For that reason? No, the next one that I would want to enter would be the author. All right, so I want to indicate who authored this book on them. To me, an appropriate control for that would be a drop down list. Now here comes our first kind off excitable, out off the norm operation. So to get a drop down list in blazer well, to get a drop down list off authors, that means we're going to have to fetch the list of authors from the author N p r a p i n point. Which is why, in case you're wondering why I had this injected. That's why I have this injected. So I'm going tohave toe in cord, make a call to the author. So what I'm going to do in court, you say so. I already put up the form group and the label. So I'm going to leave that therefore. No, but I'm going to take here off the court. So I went toe have protected on then override a sink task on initialized the sink on then this function on. We all know that this is what Lourdes When the Component Lords, this is going to get fired inside of this, we need to fill some barrels. I need some variable that's going to have the list off. Author. So I'm just going to say private. Ah, I leased off type author, author bur model right? And then the name of this is authors, right? So this is not going to have any value initially, But then on the initialization, off or form, I am going to see that I want authors to be equal toe and then we await the result off our author report that get they see you. Even though I am dealing with books. I can call on any repository I want at the point when I need it. Get the data on. Then. Once I have authors, I can no use. It's the fillets, A drop down list authors. All right, so I need to actually build this drop down list. So if you're just another form of NBC that would actually just about control or another use off that may question See, they would have a control. We don't have no control, at least maybe not yet. So let's just work with what? We have someone to just create a select list. All right, on. Then I'm going to say I want to bind the value off this select list toe assigned model docked author I lI. So that means any author that is selected from this drop down list I'm tracking that value . How in the former submitted? That's the value that I intend to use to submit a little ease. All right, And then other attributes for the sleepless would be the fact that's a form control on the idea is office A C or copy and paste it to me. So label four Author on ideas. Author. There were people. All right? That probably didn't catch you. So that's fine. No, I want to have the first option being the generic selector or observations off the at sign . All right, so the 1st 1 is going to be the generic option to say, Just select on author Onda. I'm so Oh, this should be blind or not blind us value. I apologize. So that should be at signed bind on, then. Model dot author I d right. So we have the first option being a generic, No value select author aren't. But then every other option I want to say if now these statements were check If something is know, as we can tell, I hope we can tell, but I know they're very important. So this should have the at sign if all right, we're checking if authors is not equal eternal, then carry out the operation. Because if you try to carry out the operation while it's null and we know that it will be no upon to the pages initialized on a plan to the AP and response however long that might take, we don't want the component to crash. All right, so where they carried this old when it is no longer know. So if Authors is not know than for each and I'm I just wrote for each and pressed up twice and it generated that for me. And I'll say author in Authors I want on options are actually just going to copy this. So for each author, I want to create an option that has the value off author darks Heidi Coming back from the list of authors going from the database on what should be displayed will be the author's first Neil Onda last name. All right, so what this will do is generate a drop down list for me on for each author that is in the database when this AP I call is made will get them back here. So, I mean, if you want to get fancy putting on auto complete because maybe this list I mean, with 100 authors I dropped on, This might not be the most practical, but for no, let's just work with its the next section in my form of water already created. The deal for the form group would be for our upload, so I just had a label on I'm calling this on day before Andi. I shouldn't be profiled. Sorry, I got carried away. This should be book cover. All right, so book photo, our book cover photo, whatever where you want to call it that is our label on. Then I need a specialized input here on them, which I have to go on to new get and get a lie before that. So let's do that together. So I went to go to new gets and Justin gives you for gotten. That's go to solution, right? Click on the project on, then go to manage to get packages on. We're searching for blazer input file. All right, so blazer input file on. Make sure you have the include pre really stick because, well, once again, this is bleeding edge technology, so there are a result there, but one is being worked on. So when you include pre release, you get this one. That's his blazer input file on. We just want to don't know that into our project. And once that's done, we need to make sure that we are coned for that dish in Tore project. So our first modification is going to be to our hosts file side the score to solution Explorer. Find hosts are there. It is on the pages on the score host file on, then underneath the blazer, not server dot gs. I'm going to add this script where I'm referencing on the score content slash blazer input file slash input file dot Js on our next modification is in our imports, so I just find imports quickly. On in there we will be adding a using statement for blazer input file rights. So know that we have those install or input into our applications directories. I'm disclosing all of what I don't need. No, I can access a specialized component called input file. So I opened my toe and I say input file right on. Then I have to put something in there to say unchanged on. Then we're going to give it functions. I just a handle file selection, all right, And then that's a self closing Tuck on. Then at the end off. Well, to finish the form, I'm just adding a button beat and primary has a pencil icon and that will say, create book on. Then I'll have one that says back to this, which is just to go back. So this originality was had an unclean cried So I mean, like I said, it doesn't really matter. So what would you do? Alot is defined all of the's functions, so I need to define handle creates handle selection. Andi, back to list. All right. Someone to start with the easiest one to accomplish. And this battle is so in. Orderto used Backed a list. I'm goingto have toe have my navigation manager. All right, so sorry. That should be that sign. Inject navigation monitor on the score, nav manager. And then I'm just going to tackle the battle dysfunction first. So I am just in tow. Have private avoid back toe list on then. This is just going to called enough manager Onda se That's navigates to on. Then the path we're navigating to is slash books slash. So it is going back to the index speech for our books Semi colon, and that's it for that function. Now let's get into more serious matters in order to truck the file that is no submitted or at least selected, Right. So remember, we have on unchain, so we'll actually be collecting that file and temporarily holding it. Well, what I need is a variable that's actually going to have that file. So I'm going to have a private ah, property off type I I fire list into entry on. It's going to have the name file. All right, on, then. Obviously, we're going to be making a P. I call. So I'm also going toe do my my bullion for its success. But I want to do this global because I'm going to use it in a certain way that I don't think I've used it in before, so we'll just get a bit creative with the court, right? So, no, I'm going to write my phone shown toe handle the fire selections. I'm still not quite at the place where I'm going to get the file or get the submission. So we want to handle the fire selected first, So I'm going tohave. Pardon my atrocious spelling. Private A sink task handle. Just copy this, so I think I'll type it faster, handle file selection on then it is going to take the parameter off are a perimeter off type I file in trickery. So I'm just copying that, but it's really an aria. All right, so that means, you know, if we are load multiple fans to be selected. Well, this is how they would get past a lot. But since we know that we only want one file even if multiple or selected or we're facilitating multiple the corners, we know we only want one. And so we're going to assume that the 1st 1 in the potential Ari is the fire that we want. All right, so we're getting the first our default from the area that came in on. We're storing that in our variable our property file that we declared earlier. Then I'm going to say if files is not equal to know, what do I want to do? All right. So if the file is not equal to know and this is a book cover, this is not Ah, book Summer. It is not a document. So I know that I only want images, right? So I'm going to want to make sure that the file name is a certain Well, it's a certain extension. I just want to on There are many ways to check extensions, but I'm going to keep it simple. Some distance. He's a simple statement just to make sure that this file our Lisa finally, um oh. Contends jpeg PNG, Far Jeff are And those are Well, let's let's limit it to Jim Pick. So, you know Jay Peak and B J P g or J E P g on PNG. Those are the three that we are catering to. So I'm going to firstly, get the name. All right. So sorry. This sperm to should have been called files. Just notice the red line there. All right. Yeah, that's working. No. So, first I'm getting the name off the fast submitted. So Vier name is equal to file that name. Then I'm going toe have a simple if statement to check if name dot contains the letters J p g. Or should I say the string PNG or the string J. Paige. All right, so that is essentially what we're checking there. I think I left off a breeze. All right, So once we are checking and if it does, then what I want to do is display that picture on the screen, so, no, I'm going to have to another variable, right? So I'm going to have another private verbal on this one or property, and this one is going to be string image data. You're so we're going to actually be parsing the image in tow. What, to call into our memory stream and and display it on the pit. So this is whole or this is kind of whole people accomplished displaying previews off uploaded images for someone to declare, um, variable off type memory stream survive m s is equality new member stream and thats going toe have some library requirements. So I can put the using statement in this in this file or this component. So I need system that I all for that. All right, so I didn't put it globally in the whole imports. You can if you want to. As I said, it's up to you. Right. But then after we declare, remember stream, I'm going tohave toe await file that data on, then the data in the file. I'm going to copy two. So there is actually a copy to a sing and we're copying the files data into the memory street. All right, so that's what that line is doing. Then we have our either and I want to save iron there is equal to a new stream reader on this street. Readers reading the data from the file. Then we're going toe. So you see that there quite a few steps to getting this done, that I need to get the included string someone to save our image. Bay 64 data. All right, so we're going to convert it into a base. 64 string is equal to convert docked Toe Bay 64 string on. Then. This requires a bite area, which we just, um well, we need to fill this bite area using what is in the memory stream. So we're going to see M s docked on. Then it has a function DeSisto ari, which converts that into a bite array. All right, on then. I think I need to be a bit more okay. Yes. I thought I needed to be explicit with the vire instead of six. Well, seeing string instead of fire. But it's still renders a bass strings. That's fine on. Then I can No. So that means I need another variable. So I do have the variable already. You missed data. You are else. I'm going to see image data. You Earl is equal to on. Then I'm with the four month A special strings, the string dot format on. Then we're going to be passing theater. Holan, image slash p and G All right on then defined the in cording, which is the base 64. All right, coma. So I really need string. Four months. I could have used concatenation or inter pollution, but that's fine. So what I'm saying is that I want to spend my format properly. I am building a special string which has data cool on image slash PNG on, then it seeing that base 64 then it's going to provide the value off the basics before, which is what we have here. Image based 64 data. So I think that put a comma on, put that there. All right. And then what all of this is going to do is temporarily Lord whatever imagery uploaded into memory so that we can display for preview, right? All of that effort to get a little preview. So I'm going to want to put the preview section somewhere near the file upload section. So right there, I'm going tohave on if statements that's going to check if our image later, Earl, Because it's empty. No, But then once a file goes in on, it's loaded into memories. When tohave data someone to say, if it is not empty, right, If it is not Knoller quiet space, then I want an image tug that is going tohave the image data. You are as the source. And remember that this is that image data. You are right here. All right, I see that I have some stree braces are about that. All right, so this is going to be our SRC on that will render our preview image once the file is uploaded. All right, so you can adjust the style. I'm just putting it out. $100 little thumbnail. So that when you, you know, we can see at these life No. One thing I want to check, though, is if the file is invited because I am seeing if it contains this, then fine. But then if somebody uploads a pdf, what exactly do I want to do? Well, I want to give them at least a bizarre prompt to say that a pdf is not a load are It's the invited file types. I'm going toe introduce another variable here. I'll just put it underneath the success private. And then I have Bull, his invalid file type. And I'm just initializing toe farce because while there is no file at the you know, when the pages started, then there's no invalidity off the file type, right? But then I want to sit. So what I want to do know is say, if the file is not equal to know on, then see if it contains this, then fine. But then I want an else here, which is going to say else the is invalid type is equal to true. So if it doesn't contain one off these extensions or whatever extensions you deem valid, so this is what images. But this is kind of global. If it doesn't contain the image, are the beta type that you deem valid. Then you're going to say that the value type is true. Is is invalid. Type is true. On the flip side, if I uploaded an invalid type on the night cheers of file, it's going to go through this check again because each time there's a change right on change. This is going to get fired. So if I open with a valid one this time, then I want to change. He is invalid, so toe falls right. Good. So if I get a valid one, then it's false. So even if we start off for us and uploaded a valid one, then this stays Wasif. I upload a battle on first. This changes the true and they need the current myself afterwards. So change back to fourth. And that's really what we want. Well, and I did say we want to give them a visual cue as toe, um hole if the file is valid or not. So I'm going to go back up to the sixth son on. I'm going to see where is it? I am going to see here that if the Volume four is invalid type is true or if it is, then I display an error message to say, Please remove the invalid file type and select a new image early this year. Black. All right, so we're letting them know and I just use my arrow message component passing in my special message there. So this leads me to do one more check, and I might be going on and on and on about about it. But understand, to make sure all our checks are complete. So we're checking. If the file is not equal to know on, then we're checking for the valid state, right? So what if the person removed the fire? Because I did say it's invalid. You can leave the field block. So if they had an invalid one, then they're going to be seeing this message. But then if they remove it altogether, I don't want them to see the message. So if they change the input and it fires the handle selection events, then I'm going to say if it is not know else, right? So if it is indeed no, then well, if it's not, it can be an invalid type. So once you remove the image altogether than this changes the falls on blazer being so off , awesome will know that this change on remove that prompt from the section. All right, so we're coming down nicely and know the one final one that we need to tackle is on valid submit. So, no, I need a function for valid submission on. I'm going to put that one here in the court sections or private a sink task create. All right on, then, What we're going to do first, are these What I think is a necessary first check. It's still make sure that we don't have an invalid file type working with, because what can happen is that when the person feels all the form and they put on invalid file time on, then Well, let's just say that this is being displayed, but they can still click. Submit on. It won't stop it because we don't have any validation running against this one. So once this submit, if our file this president is going toe upload it on, it's going to save that file on this guy, and I don't want that. So I'm going to start off by checking. If not, is invalid file five times, Right. So if we're not dealing with an invited fat time, then we can proceed. Oh, I'm sorry. This just popped in my head that if the person had a valid file type on, then they changed it on invited one. Then I don't want my image data. You earl toe have anything. So when I'm sitting that the invalid file type is true. I'm also going to set my my recorded string Toby equal to string dot empty. All right. I don't want to have anything in there, So initially, it has nothing on. The only time you should get something is when a valid file time is uploaded. Right? Oh, sorry. It's during that. Empty is not a function. My back. All right, so that was sparked in my head. Just know. So let's go back to the task at hand, which is the save or record. Andi subsequently upload or file? No. I'm going to start with the easiest part off that on that is saving the required. So we know that to save the record, we need toe obey the success toe. Whatever comes back from our call toe our report that create our passing in the books and point, create the new book passing in the model on. Then we're going to have ah, your statement to say if we are successful in our submission, then we do about the list. All right, now, I did say that I was going to use the success, um, to display an error message. So I'm going to at the top say, if not a success. All right. So that means your success is going to be used as our marker to say whether something went well to see if something went wrong with the operation. All right, just express spacing a bit. Alright. So its success is going to render or based on the value of its success, we render our message. So that is why I said it to true initially, because I don't want this being displayed when the page loads. However, if it does change afterwards, then it will display it. Otherwise, if it was successful, if it is true, then we just call back to list. Since about two, this serves two purposes right there because you just navigate away and it's also attached toe the button click for back to list. Now we've done the easy part. By my estimation, that's the easy part. But let me just bring it on this journey. So right now, even though we have that file upload and if you run it right now, you see a picture preview on everything. When you click submit. However, we're only doing the sending to the database for the model, all right, for a book. But then, further to that, we're not serving any data for the uploaded file. So you would actually see knows evenly uploaded a file here. There would be knows, going across the wire here. And that's because, Oh, are we need to actually, you'll some processing to get, like, the file name. I'm going to rename the file by the way on. Then after all off that on, I'm going to upload the file first on, then upload obviates the the image field in the book model on, then send it to the database. So the orner different people do it in different orders. But that's all I'm going to be doing, all right? So I'm just making some space for my file operations, and what I'm going to do first is get the extension off the fact someone to say viral txt is equal towpath dots on, then, because our system not io I have X have access to that path, that extension and then I can pass in the file darts names. When I told you that there are many ways to check extensions, here's a way to just get the extension so I could have done that on just compared the extension against these values. I mean, whichever one works for you, that's fine. All right, on then. I'm going to save our pick. I d is equal toe on. I'm going to generate my own custom values. So I want something that's unique that won't ever repeat. So I'm going to use our good and I want to say good. That's new Good on then. I wanted to be a string Andi also so goods always have dashes. I want to take all the dash insiders want avoid that has the contiguous characters No dashes in between ciders Do a doctor place on Dr Place alos me to specify the item I want er place or the cartel on to replace on what I want to replace it with which in this case is nothing so literally will just drop all off the dashes and put no distinguish er in between, right. So then at the end, off the day, my pictures new name would be equal to And I just used my dolla sign quotation marks on going to conquer to meet the I D or pick I d Your other What? All right. So that that's what that's it wasn you name, right? So pick I d on. Can Katyn it on the extension? All right. So whatever extension it originally after it, Ian, that tickets A, p and G. I can't just change it to j pig. It doesn't work that way. So whatever extension it, I'm going to retain it, But I'm going to rename it to pick I d on. Then That is what I am going toe. Want toe upload as the image names a model. That image right is equal toe pick name. Alright, so I've done quite a bit off work, but we're still not quite there yet. We still need toe handle the file upload. So I'm going to leave it here for No, you can test it. Owt. Um, what will happen is that you will be able to submit the form on. You will be seeing the new Pickney, um, go over if you select a file for the upload, but obviously no upload is happening. So when we come back, we're going to finish up how we're going to finish up that upload functionality
53. Setup Create Book - Part 2: Hey, guys, welcome back. The last time we were here, we were sitting up or create view for our books on one of the key parts off. This was the enable file applause for a book over images. So we need to finish that off on The first thing that we're going to do is go to our solution. What of contracts that were going to be creating a new interface or a new contract for a new service on this one is going to be called file off Lord. All right, so I file upload, we go ahead and add that on. Remember to change the interface on this interface is going to be handling fat. Well, it's going to have one function that's called Task Public Task Upload file, and it's goingto have one parameter in the form off I file list entry four File on, well, another apartment or for the pick names. Remember that we generated the big name inside over Blazer component. And so when we call dysfunction, we need to pass over that name. So now we need to implement this so we're going to go ahead and create the concrete or the implementation class over in service, sire, I click upload class. I said applaud, but it really should have been at, but the class is file upload on. Then we go ahead and adopt on file upload is going to inherit from i file upload. From here, we're going to introduce a new property type, and this one is going to be called I Web host Environment. So I'm just going to underscore and for short, sick and go ahead and include that and include any missing binaries on, then that is our new dependencies. Off course, we have to the final constructor on initialized accordingly, after we've done this weekend, go ahead on and implement the function. Well, you can do it. I'm doing it. I haven't already done it. If you wired to done it, then you're good to go on then what we're going to do and I like corrupting complex operations in trade catches. And then we'll just be writing a few lines off court. As a matter of fact, a few lines off court, we look pretty similar toe what we had to do when we wanted to upload it into the memory stream. So that's where we start. So our 1st 2 Lanza levels declaring a member stream object on Ben, um, copying that toe, the copying, the filed out data to the memory stream. And I need to meet this a sink. All right, So the 1st 2 lines, we're seeing those before I'm even reusing the same variable. So it doesn't seem so farfetched on then I'm going to build my path. So the path where I want this file to be saved on like I said, we're going to be using inside off our www root folder. Uploads are so that's the path I'm targeting. You have people who have differing opinions, but once it once again we're just keeping this simple. So I have my interpretation, my dollar sign and my quotation marks on. Then I am went deploy in on the score end, which is my dependency for the Web host environment on I'm using Web root path, right? And then I'm going to target the uploads folder. So this is going to say wherever the solution is being hosted, from where the site is being hosted from what is the path to their right, and then it's looking for uploads folder on, then we're going to be passing in thick name. So that is the actual name off the file to be safe rights or the actual name off. What? We want this file to be seen as in this entire path on. Then after that, we're going to see using file stream on. I just got this. FS is equal to a new file stream. Terrible. That's right. We're going to pass the path, Onda. I'm going to see that fire moored. You see, file board dot creates actually means that if the file is there already will overwrite it. But ultimately it will create a file. And since we're using goods toe generate the name of the father, the chances off having a class should be very slim. So then I want to say m s as in memory street and variable docked right toe. So, no, we're going to say whatever was in the member stream, I want you to know right toe the file street on the fire stream object like we just saw, will handle putting it in the bath and creating its and then that's it. So then if you get an exception, you can through we can crush a program. Or however you want to handle the exceptional leave through Because I really wanted to crash the program in the event off field file upload. You know, they're probably more graceful with the handle it, but for no listlessly that so back in our create component, I need a call. So before I can access the service, I need to add it to the start about CS. Right? So this is a step that always I must admit, I'm always forgetting. So it's it's a good practice toe have. Right? So we just added a new service. So we have to let the entire application know that this service is illegible for, um, injection. And so file upload. So going back to the creator, I need toe introduce it. So this So I went out to see I file. What did I qualify? Upload Right on. Then I'll just call this underscore. File off Lord Rights of my dependency for file Upload on, then don't Here or so this is create book. It's in between book. It should be handled. Create. I let me that card, son from no. All right. Getting rid off grid lines one by one. All right, so then this line is going to say underscore darks, upload file, underscore file upload dots. A profile on upload file is waiting for the file. Right. So after all of the excitement off was getting the fire, loading it into memory stream we have filed here, right? So that is all we're passing up as well as the name for the picture, which we just built on. It's called Peak Name. All right, let me just on This is a synchronous I need our weight. All right. So maybe how you could do this a bit differently is toe if the file upload function failed . Meaning you could have done it as a Boolean, a task bull. And so if he got this fire on, then everything was okay. Then he returned. True if he caught an exceptionally returned falls and then based on the oh, come off that you can make a decision as to what for? About you, you give to your user or start a visual cue give to use at that point. All right, so I think we did quite a bit off work. I'm just going to go ahead and build and make sure everything is still ticking. And we have success. So let's take this for a spin, all right? So because you set off the restrictions and went after logging as an admission, and when I go to books, I'm seeing all off the buns that daily didn't get to see right someone to go ahead and click, create book. So here's our forms, So I'm just going to put in some values. So this book I experience remember that we don't have any validation running, so we need to go back and put some validation in. But for now, let's just work with what we have. It's a CR drop down. This is working for our authors getting the author, and then I choose a file, and I just selected one off my desktop. There we go. Say, see the little preview showing up and let us see what happens when we create book. He goes right back to list on it is displaying that book. All right, let me see what happens in my view. All right, so we're seeing the book, our seeing the price on. Okay, We need to format some things here and there on If I click on author, it goes over shows with the author's details and the fact that that is his book. So everything is coming together nicely. All right, so we get our books created. And so the last thing I want to do No, just at some validations, though Justin notes that you may have some issues with writing files, depending on where you're writing toe and the based on the permission that you have. All right. So I tried it on a machine that I was not admin or had no read right access toe or no right access toe. So it was creating blank files. So if you're getting blank fires, it may be your permissions, but you can still drop their line if you're having difficulty with this. But if you're at this stage, then we're good to go on. Then the last thing that we need to do know is to check on our validation orbiter notations for our model. All right, so in the book model added these data politicians and me, the title required I mean, the ice being required. I mean, the summary be limited to no more than one of 10 50 words on, I mean, the author I d required. So the reason I made the author I d required is that even though I have, it doesn't know. But in sheer, I wanted. So while the FBI says it doesn't need an author, I'm going to force the author because then I don't want any problems on my side. So remember that we're bridging the gap as the crying developer versus a pair developer. So on the client side, we can make up our own rules to enforce our own strict qualities before we even get to the FBI's rules on their qualities. So I had the question mark here on the into that median gullible, meaning I didn't have to select an author. Well, I just took it off, and I'm seeing that you most select an author when you're using my up. All right, so that's it for the theater notations on the book. I also doubled back to my create component and make sure to add a section for the summer. So everything looks the same except nowhere using an input text area. So we know three even puts you know the for. They have input number. Have input text, which is a text box. No have in politics area, which is the big box. That's almost a ride. The issue. That would be our summary on then. We got the custom components input file toe handle our file upload. No, we thought that set on. Don't. You can go ahead and test other scenarios, you know, uploading and in court unquote invited file testing the different permutations you can. I know that they're gaps in the logic, right? No eso If you can detect any few free to share them with me and we can go through them together.
54. Setup Update Book: Hey, guys, welcome back in this lesson. We're going to be walking through the edit operations for our books. So I was so excited I went ahead and got started without you. Second pause and take it off. But what I already did was to create my edit. Stories are competing component inside the books folder. All right, on. Then I went ahead and gave it its path, which is slash books slash edit slash. Under I d parameter, I put in the authorization for only administrator rules on. Then I imported the book repository. I offer repository or file upload off repository on the navigation manager. Andi. I have my title edit book, and I put in this horizontal rule on break point and I'm ready to go seek. And Paul is take that off, and then when you catch up, you can continue with now. I want to be building the speeches in a combination off court from our view page on our create pitch. Right. So I added, delete authors that disclose it. So we have edit sorry, Web or edit page taken from the Create page as well as the view, Pete. So I'm just going toe piece by piece. Take what I want on. The first thing I want would be this if statements remember that in the view we checked if the value off the perimeter was invited and we show a message. All right, so I want that. So I'm actually just going toe collapse This collapse this and I'm going to take everything between the if statement to that first open embrace. Copy. Bring it over to edit Paste on that. I'm just going to close that curly brace on. Finished on my excitement. I think I may have deleted my court blocks and we just put in my core block here. All right, so we have our check for the parameter, and we're checking if the model is empty else. If neither one of these is true, then we want to render the form on. This form is going to look pretty much like Oh, it looked on our create, Pete. So I'm actually just going to go over there and you can see that already collapsed. The create form, some adjustment to borrow all off that chord, bring it over, and then we make a few minor tweets, some starting from the top and I'll go down systematically. So some changes that I want to make would be I want to use hand update or not on the create . So handle bit. We have all of our fields are authors being bone. So these red lines mean that we need to put representation for them on the form. Right? So in terms off our image, we have a little modification that we need to me here. We'll get back to that. This is going to be instead of create book, it will say, submit changes current and there were booked back to list on. Then we move on down to our courts are Cornel will help us to clear up some of those red lines on the first thing that we want in our code is over parameter, right? So just like we did in the view section or in the view page we have or parameter public I d string, we'll string I d. Sorry, we also have the model, and we have that on initialized chasing someone to borrow all of those from the view page on Bring them over to our edits. All right, we're going to be doing something extra inside off the UN initialized. We're getting the model, um, the model record. But we also need the list off authors, which I didn t create, right? So in the un initialize you got the author some disporting this. So, as you can tell, I'm not in the mood are off to re type call that I have all over the place already writes I'm just speaking the best from everywhere and bring it Bring it in as I needed. So you see, here in the bar, this land off court, we don't have authors and obviously I need to be clear the variable. But if I go back to create on look inside off the court block, then I would see that I have a bunch off variables that look like variables that I really do need either way in self editor, Any the authors, I still need to track my file and need to track success, etcetera, etcetera. I have one extra one that I'm going to be putting in. But I just copy these from no on on. And since I have book again, I'll just go ahead and pissed on, then. Lots offered lines will disappear because no variables exist. All right, so we have the function handle updates. So I need to implement that on hand, albeit is going to look very similar to the kind of create. Really? So I'm just going to go back over to my create this, so I only collapsed it, So I want to borrow that, and I'm going to pace it over and the edit. And then I went to change the name handle the It's all right. So a little change the time made inside off the create on. By extension, the edit would be in the form of this if statement. So if you try to upload the file based on the quarter you had, you probably would have gotten or, well, if you try to submit I record without uploading, our value would have probably being getting some no exceptions. And that's because we have a bunch of file operations here that Randers stop being executed without a file being present. So you can't get the name off. A father doesn't exist, so I have to check before submission. If the file is not know on, then we go ahead and parts off the details, then upload it, then made the change to the field on. Then we push to the database. And if there is no file, well, we just push to the database. We don't need to carry out any file operations, so I mean that change to the create operation. Andi, when I just copy that over to the edit operation, Right. So handle update is going to check if there is a file on act accordingly. We need a back to list, so I'm just going to get the back to list. Also on I'm going to need handle file extension because are fire selection, sir. Because I do allow you to change the book image in the edit. So I'm going to have to handle that seems understand. Take both off these also on place inside off the court block in the edit page. Now, if I scroll back up to the top off the farm, I'll see that, Okay? There are no red lines, So let's start at the top again on go down an address. Little issues are nuances. Know that we're dealing with the edit. Onda neither created nor view. So the first issue that I that jumps out at me. And once again, the farmer means the same goes we have the same fields for the different items, right? So the image all the way down here were were born input file. And in our section where we check if it's an invalid type on display, an error message if it is. And then we say if there is anything in the data you, earl, or remember that the Beetle euro was formed because whatever file was selected was Parson Tau Bay 64 then put into image Data Girl. So we get that thumbnail. So the problem here in the edit is that this court only shows a file that has been selected . If I am anything on existing that already has a file and I'm not changing the file, all right? I didn't do anything to fire the handle file selection. Then image data you are would never change from no, which it is initially. Right. So what I want to do is the displayed image that is already in the database, which is funded model dot image. So I'm just going to copy this if statement Well, I'm just going to say else if all right, let me go into the next lane on, then it's going to have a similar check to see that. So I want a priority to be on the style that is selected newly right. But then, if there is no newly selected file, then I want to check if there is a file in the database reports of model that image. So if want a lot images, not snow, are white space. Then I want the same kind off the maids. But then this time the value is going to be at the path off. Uploads slash on that is going to be model start image. All right, so we have model, not image being displayed. If there is no new image, no, If there is a new image, we need a way toe handled that on. What I want to do is the truck if there has been a change in the selection. So when I said change in this election, I don't necessarily mean that you selected a new image at this winter. I'm less concerned about whether you select a new image from the one that's there already or anything else. But even if you went in, you click the file select on you selected the same image. As far as I'm concerned, that was a change in the image. So the behavior has to change where that means that when you submit if there was a change, then I need toe take all the one that was there before and put in the new one. Or if there if you made that change where you remove the image to get all together, I need to make sure that I removed the image from the record on also from the fire system. So I'm going to introduce a new flag right here that I'm going to call Is file changed on? I'm going to initialize that toe falls initially. So when you make a modification to the file or you trigger the events that say's handle file selection, I want to send out the truth because as far as I'm concerned, I change happened. So inside the handle selection I'm just going to say is file change is equal to true. All right, so know that we're tracking the state off selection, at least if it's changed, are not If if it gets here on day, something happens. I once again I don't care if it is No, are not. No, something changed. So yes, something changed. So at the time off off handling the update We need toe. Do something differently with one. If the file is not equal to Nolan the only way if I would not be equal to knowledge if a new file was selected. Right. So at this point, I need cold that is going to remove and I'm just going to put a comment here. Remove the old picture Onda upload the new one writes. I'm also going to introduce another check to see if our else if this file changed is true. So you change the file. A change of state of the fighter did something to interact with the file selection boats. There is no file present on fire is equivalent to know right? So that means your chain something But there is no fire in the system. Then I'm going to have to just remove the old picture on. I'm also going to have to set the model dot image to be equal toe nothing String that empty because it doesn't make sense. I'm referencing an image that doesn't exist right somewhere to update it, to say that there is no image for reference. If the file status was changed on the fire is equivalence and no. So these two blocks have the same thing in common. We need to remove the old pictures. So we're going to go into our file upload, contract and implement, and you may 3rd and I'm calling this method public void. Remove file. I'm doing it as board because we're not going to do anything is synchronous in there. So I don't need to be a task. I'm just going to remove the file and all I need is string, pick name. What is the name off the image that I should be removing? So in the concrete class, I'm just going to go ahead and implement the interface, get the new methods stop on. This is really going to be our other simple Operation one. I'm going to build a part so you may want to look into getting a static parklike over did with the FBI's. We can look into having a static path for over five Buehrle's. Either way, we build our path where we're getting the same path where we know all the files are being stored. All right, And we get the pick name, toe la chon on. Then I'm going to say if file docked exists because I'm not going to try and delete something that doesn't exist. So I'm only interested in if it exists, then I just want to say file that delete from that path. All right, So the file is there, then delete it. So that's all remove file is going to do for us. So back in our edit, what I'm going to say is the virus removal pictures. So a file has been entered in, and I'm I don't once again, I don't know our cure. If it's the same image that they wanted and re selected, I'm getting the extension, generating a new I d. Watching them together for a picture name on that I'm going to see on the score file, upload docks on, then it's going to say remove file on. I'm passing in, Model docked emits. I'm removing the file that's already there that annoys stored inside the database. And then after I have successfully removed that, then we can go ahead and upload the new one on. Likewise, if the fire status was changed and there is no file present, then I'm going to go ahead and just remove the file and updates the value to nothing on. Then go ahead and not create, but off Biggs and then albeit takes our books endpoints the model as well as the model darts. I d. All right. All right. So, little steak, this court for a spins, understand the click start. All right, so in our book list, I'm just going to go ahead and click edit on one off these on. We see that we have our booklet has preloaded our data successfully. I'm going to give it a price on by a summary also book. All right, and then we see here we have our preview. So let us test changing this image rights, Understand? To go ahead and choose file. All right, on. I'm also going to change the name off this book. Someone to call, it's maybe s b f S B A p I, def. All right. Something that that's something catchy. Block off court as the image on. I'll go ahead and submit the changes. So I'm also going to change the also so that we can see as many changes as we need to. And then something changes and we see where we're getting back or a new book with our title change the new price. The author changed on all of the wonderful changes we made. If I view, we see everything coming up. Now, if you've been following everything I've been doing upon to this point, it may have run into an error because when I got up to this point and I attempted it initially, I had toe quote unquote call the FBI team on. Let them know that I followed all the rules that submitted the data on the author's data. Did not go over properly on the SB indeed, and do not over properly. So pretending to be the team, at least I went in on I D board and looked back at my book bto for my job It on. I realized that okay, my I S b and Field was actually missing as well as my author feel author ideas. So if you didn't put in those two put them in. So the point is that as you develop your follow the rules on the client side, even the FBI is not up to scratch. You will have to reach out to support. Or if you're doing both sides, then you know you need to be attentive to these, that the things, the little mistakes like this you will be led to believe that your client has the problem when it's actually the way the FBI was set up. So I'm just pointing that all, too, because it's a learning experience for us all and want to come out off this prepared for any little situation. Notwithstanding those challenges, we see that our updates operation worked as expected. It removed the old files for each upload and put in the new file on Abated the database record on When we come back, we'll look at doing Deletes
55. Setup Delete Book: Hey, guys, we're back. And today we're dealing with deleting a book record. So I'm sorry I was so excited that I didn't go to guys. But I'm going to walk you through everything because then you realize that just like I did for some of the other components, all that it was really copy and paste the best parts off gold from elsewhere and then push them together as I need them here. So we start off by giving the page a path. Books slash delete slash ideas are parameter or author as attributes. And then we in Jake. Our services are of the book report. The navigation manager, Andy s the file upload repository. Because when we delete a record from the database, I also want to delete the file from the server. I don't want to remove the record and keep the file all right. Only in the worst gets inertia that ever happened. But that should not be the normal operation. So moving along my street out says, Are you sure you want to delete this record? Andi, I have that H r and B are just for the styling, but when we're going to the essential fixes. We make sure it's normalized every piece with those I have my East success check on that's coming from Well, it it on also create. All right on, then. I have the check for the parameter the model data. Andi, the view. So pretty much I went over to view that razor and I took this entire core block, right. This entire court block is what I used inside off this delete page because we're sharing all the details off the record that the person is a boto delete on. We await their confirmation right on. Then at the end off all of that, I have two buttons, one that says delete Well, one that has an unclipped that says Delete book and the Texas the Lead book, as well as one to go back to the list in the court block. We have war perimeter check. We initialize our model on We are born a success flag on, then un initialized. We get the indigent version off the perimeter value on, then we parse it in tow. The model which later populates our page as we know I have my leet book operator, which pretty much just have caused the remove file cycle file upload, remove file past in the model dot Image on that will delete the image from the higher discovery saw in our it it on. Then we have our success, which is going toe await the results off report that believes the books endpoint on the I d off the record on. Then if his success, then we go right back to list. And then I have my battle ist operate are function here being called by the button as well as this success stick. So I know that that one went by rather quickly. But as you can see, it's not a lot off work because, well, the majority of it is the interface on all of this came from the view, right? Frankly, all of this came from what this came from creates as well as edit. This came from the View components Onda. Well, the buttons are coming from basically everywhere anyway, So the rial only difference between this page and other pages that we've done would be our delete operation, where we make sure that we're move the file check if it is success on, then act accordingly. So let us state this one for a spin. Alright, So back in your book list, I'm going to go ahead and the Leeds, SB or SP book someone to hit the lead week over. We show the details. All right. I saw how they kind of phased in. So that's the power off that await one and toe. The fact that we're kicking or doing something different with the model is blank. Because when when there was no data, we're seeing the no data screens and then everything that sparked in wants to date about there. So that's really cool. Any hole we're going to go ahead and believe book on. We see that it works. Excellent. Using this just to understand, to go into the solution explorer and bring up the W W roots Onda the operas full. And we see here we only have one image. So we have two books with two different images. We just delete it once and we have one image. So that means our remove court is indeed working. So that's it for our delete operation. If you run into any difficulties, as always, feel free toe, let me know. Next up we're going to go through some essential fixes and we're going to look into implementing a notification mechanism in our application as we go through our different operations and tasks.
56. Essential Layout Fixes and Additions: Hey, guys, welcome back in this video adjustment to review our interface, see if there any modifications that we need to make on dwell review modifications that I have made off camera as well as implement this notification library called toast. All right, so just to go back to the books, what I've done is go through each view and made sure that I put in that horizontal rule as well as that break on the neath water a title was there. I also added the price column to the index on die indicate the price here where I formatted the string to look more like currency writes remember that it's a decimal, which is why when you put in $50 getting someone to decimal points or just formatted it so it looks like 50 on then off course, that former thing stretches over to the view page where we get the $50 Now. The reason this is so misaligned is that on? If I just want to inspect element on show you what this looks like when you would see that the price is actually off on H street. Tug on it is center aligned, but then the alignment of the images off and maybe because of the dimensions off the image and stuff. So I mean those things, you can probably work old. I don't spend much time trying to fix that and get it aligned. What's under showing you why It looks slightly misaligned so that if you want, you can put your effort towards fixing that now back in the court, and I'm just showing the index speech. Here's where I did that string formatting, right? So I said string dot format on. Then I'm putting in the form of that I want the variables of zero is a place well before the variable on then the four martinis currency, right? So once it blows attainable for months desk currency on. That's why we see that as a display. So pretty much I did this everywhere that the price was being printed back to the screen. I used to string dot format on the currency sitting. Now I did say that we were going to install a notification mechanism for blazer, so let us get into it somewhere to go over to my package manager on. I'm going to be installing this package called blazer dot toast. So when I get here, I can go ahead and install its blizzard doc toast. That's coming from the same guys who give us the library for our local storage. So they have some really cool library sequiturs, typing blazer. You see that? They have model, they have type of head. They have some other cool libraries that you can explore and implement. On it is a well documented library. The next step after getting the package is to register it in our start up that CS. So we just go down to start off that Sears Onda attach it. So have the blizzard. Local storage are just at that blazer toast. And then we need to include a library to get this recognized. And then once that is done, then we need to import the libraries in tow. Our bellies are up, so going back into solution expert will go to imports on. Then I'm just going to add another study right under the input file blazer dot Toast on blizzard. That's toast that services. Right. So after importing those stool, all right, they can always just pause If I'm moving, I'm moving quickly. So the spas didn't know what you need to take down on. Then, after we have imported them on, you can just continue searing as you go along. We're going to go into the main layouts on then in the mean layers were going toe add new components. And I'm just going to put that at the very top, even above the love menu. And I'm calling it Blaze. Erred toasts. All right, so that's Ah, specialized component that we just imported to be used across our our blazer up. All right, so we have one more thing to do. I mean, there are quite a few steps. I'm just making sure the itemize them sake and see how they all come together. So in the host file, I'm going to add a style sheet. So the reference the style sheet will be on the score content slash blazer dot toast slash blazer, the dash toast dot CSS and that's a stash it. All right. So we just add that I just put the threats on the booster because it does inherit things from the bootstrap on order those matter now, using this service is relatively easy, so I'm going to bring up one off the page. Is that on operations carried out on and let's try, create. Somebody creates. Put it on the create author. Right on. Then on the here, I'm going to see inject. I toast service cause service. All right, well, let me keep my convention consistent. And us under scorchers toast service. So we're injecting and then off. What? You don't need to import anything, cause I already did the imports in the import start razor file. So once we have our toast service, we can know. Call it whenever we want to send over a notification. So I'm going to do inside off the success part for or author creation. I'm going to put that I want toast service docks, and then I want to show success. Look at that so I can show success on. Then I'm going to give it a message. So I went to see author created success fully. All right, so we talked about setting up our custom components with error messages. So if it is that you want to display maybe a tool since it off displaying this error message, if not success, then you could probably put on on if on that and else and say toast service that so I'm sure they have something for that. So you have success in four error warning on Dwell tossed. I get stores is just a primary Andi Well in for would be like blue. So he can kind offering a parallel between the the hints. Here are the names on the classes coming from bootstrap, right. Someone to routine that show. Successful author created Andi. I'm just going to test that one. So I'm going to do one on camera. We're going to do one together on, then I want to challenge you. Toe. Do others in other parts of your cord on. I'll update other parts off the cord also. All right, so let's test this old from my author list. I go over to create author all right, and have a new author, Claudine Williams and her biographies that she's very eloquent. I go ahead and create author, and then we see our notification Success author created successfully. So there was on. Here is a little thing that I may have missed our what I missed. I need a break point between the button and the table. So I'm just going to do that. No, that's what this essential fixes video is for, Right? So let me just pull that in quickly. All right? So I just put that in. I just put the break point underneath the but in the end experience, that's a man of thinks. I'm not going to spend any time doing that. But when the focus on this tour, so this message can be set. But then if I say comma, we can also give it a heading. So you saw that? It said success, right? We can actually give it a custom heading if we want our set the blank. So the word successors and come about the notification itself will come up to say this was done successfully. So what I can challenge you to do at this point, just go through the different operations and put in appropriate notifications using the appropriate prompt colors. Remember that fuller suggest different things or successes. Green warning means that something might have gone wrong. Or it could just be the color scheme that you're working with. Andi, you can have a bit of fun with this notifications I go through and update my own. All right. So other modifications that I made inside off the view section would include that I put in a button per well for about in four different operations on any important delete button in and up on. We have the back to this button already. I change the class off the warning line and the danger outline, along with some icons the pencil and the circle export the delete on die also made sure to include the click events where they will navigate to the respective page with the i d. Coming back from our views. I did that in both authors on books. Andi set them up so you can go through, set up whatever toast the notifications you want. You can, you know, spruce of the interface a bit on. While I have given you an idea, I'm interested in seeing what you came up with Onda at then off the day. I hope you end up with a beautiful interface. So in the next video, we'll just review all of what we've done in this section and then check in our changes to get for
57. Review and Add Changes to GitHub: you guys. Welcome back. This is our customer review video on dime just into you. Don't give a high level summary off what we did in this entire 61 for books. So you are dealing with books but details going back to author to be with some things and even back to the FBI because there were gaps from before on where to fix them. So in the FBI, we had to update our book GTO to make sure that we had feels to support being transmission across the pipe in our back. In our interface. You know, you Why were we did quite a few things? We updated our book model toe, have some data annotations to make sure that the form will collect the right data. Accordingly, we set up all of our crowd components for our books. Andi, it's always having to fix some things in the author section. Also, we are also went through, and we created some new services with the form of the book repository as well as a file. Upload her posture. So, no, we're handling files on the system on once again. If you have difficulty with this, you might have some permissions issue on the machine that you're using so you can seek toe , have that rectified or, you know, contact me if anything. But we did quite a bit off work in this section. And no, we want to just check in our court to make sure it is nice and safe. So as usual, we just right click, go to commit. Then we put in our message to make sure that we remember all that we did already use. Have an idea. Go ahead and commit all and seeing on that's it for this six on.
58. Blazor WebAssembly Introduction: Hey, guys, welcome back. So we're going to continue on our development journey. We've already looked at how we create our Web. AP I using dot net core 3.1. We've looked at how we can go both creating a blazer up on then. No, we're going to look at creating a blazer with assembly up. So, up until now we've been using Blazer Server on No, we're going to look at Blazer with assembly. No, Justin notes that there are a few differences between the Web assembly template on Bill Blazer server template. So instead of trying to convert from one to the other, what I'm going to do is create ah brand new project on then. We've already written a lot off the court. A lot of court is actually very transferrable between the two templates, But then we will still take a look at on come to appreciate some off the differences on nuances between the two. So with that said, let's get started. So I'm going back to visual studio and then I'm going to go ahead and create a new project . So I already have two projects in our solution. Whether the FBI project and we have our bookstore. You y project, which is our blazer server up. Someone to create a blazer Web assembly up, and then we'll just see whole weekend. You transfer the core between, so I'm going to go ahead. Record the solution. Click New project. Selects the blazer up template on. Then I'm going to give you the name Bookstore. Keep it consistent. Bookstore dash. You I dots w a s m so dumb A S M. That's the acronym means Web assembly or it's ah, you know, short. Well seeing Web assembly on, then I'll go ahead and create No. When we were at this point earlier in the lessons where Assembly was actually in preview. So no, it's in the full version. I want to show it in this course. So it has finally been released, and it is no production ready, and then we're going to be using it for our application. No, At this point, I want to take the time toe point out a few things. One when we choose Blazer, Web assembly up, we get some different options. And what we had when we chose Blazer server up. So in re click who have assembly up. We know have two options. We can make it a progressive Web application as well as an sp dot net core horses application? No, the relevance off this is that Web assembly is actually a piece off the edge that executes directly in the boroughs. Er so when you build an application that is based on Web assembly, the Broza will actually load all off the contents All off the the resource is needed for this up to run, it will all be loaded into the browser and this up will run from the bro's. Er, alright. A server up, however, actually needs to be deployed on a server like Internet Information Services. I I s r any other compatible swept server, just like any other websites. So once again, the blaze and Web assembly up will actually execute directly from the browser. Now, if we choose the sp dot net core hosted option, what we will get is three additional projects will get a client, a project, a server project as well as a shared library. Now, the shared library will serve as like a middle ground between the server and the claims. You know, in the classes or model classes. That would be, you know, common between the two would kind of go in the shared. What happens is that the client will connect to the server up through a P I calls so the server up could be capable of handling complex business logic on Do you know, if you want to talk to the database directly cause you can build a full current application from Baser than you probably would want to go with it the dot net core hosted so the server would do exactly what we've been doing in our server on then. The client just uses a pair cause to talk to the server up. No, I know that might be hard to visualize. It can probably experiment, and you can create one that is core hosted on one that is not for close. It will be going with one that is not core hosted because we already have on a p I. So I don't need toe. Have another server up Taconic to the FBI for the client after then connect to the server up right, So you don't situational e. You may choose one, but not the others. in this situation and will not want to choose a core hosted option. No, the progressive Web application once you think that it will include certain libraries that alot this application to actually be like a standalone application. So standalone means that you can actually don't know the application on your device with its mobile or windows orally looks, and it will run directly from your machine. It will also support on our flying more now, with all of that said, I'm going to choose Web assembly, choose progressive Web application. Andi, I am not going to choose authentication or anything else, but I'll go ahead and click creates. All right, so know that we've created this application. Let's take a look at what we have here, so I'm just going to expand the server application. Onda. We'll just compare what files we got in either templates. All right, so we do have our www route folders in common. But then, if you take a look, you see that what would get is kind of different CSS live. We added the uploads for our application and get a five icon. I don't hear you have comes in some sample data because off the sample, that's a template stuff. So that's really not necessary. We have. RCs is fuller on. Then we have some addition off that are not present here like the index file. So this index file really replaces the file. All right, So the server comes with the host file. Our web assembly comes with the index file. All right, on then, we have a manifest that Jason, this is like a register for all off the details off the web. Assembly up. So the name off the application on Do you know any other static data where the icons are etcetera? All of those things go inside off the manifest. Start Jason. And then we have the service worker Js, which is pretty much schooling to support that progressive web up option. All right, then we have pages, speeches fairly remain spirited. The same. Except we once again don't have that host dot CS html file. Then when we look in shared, we see the same things on imports and up don't raise their All of those remain pretty much the same. But then notice that we have program, not CS in the server on. Then we have start off not CS that comes default and standard in the Web assembly. It does not come with two files Now. That being said, you can actually extend this toe, have the same structure as the program docs and started because program that see it's actually runs this function, which initialize is the start seeing persons Britain amounting to two. Otherwise, when you're registering services, you have to say builder dot services, that on the new at your school poor transient on the syntax doesn't look too different. So, actually, all of these things that we had to reference inside off our original blazer up we will need to kind off port them over to our Web assembly up when we need them. So know that I have created a project. Let's just take a quick look at its understand to set it as the start of project on, Then run. It's all right, So when it is up and running, you see that it is literally the same layout. So we just went through the server. We're literally just going to be transferring that knowledge over to the Web assembly side . We have the home Web counter sample page Any words Just the same way. And, you know, switch data. So here you will see the example off the A p I call, we're in Fetch data me. Just hurry up and go there. We will see that the page. It looks just the same way. Except this one. They're using a different http client library than we used. So we're going to be re factoring. So the court, because we used I. Http client factory. They have a simple http client library. Andi. So we're going to be changing on some cold, but that's besides the point right now. Um, on initialize it does an A p. I call so it doesn't get called right on. Then this get called asks What do you want me to parse the Jason into? So it's disguising. Http. Get from the Jason content that you're a boat to retrieve on. Parse it in tow. Honore, off type weather forecasts over the forecast SYRIZA classified us Hold on control and Oh, sorry. It's right here. My But all right, so there's a lot of work off. So that's just the class. That's all it is. Andi. So it's an array off objects off type with workers coming from sample data slash weather dot Jason. So if you remember in the Www Route folder right there, we have some police slash whether or not Jason. So that's all I meant. It was just for sample purposes, but the principle remains the same. So when we're when we're a boat to retrieve something from our a p I what we'll be doing, you're seeing get from Jason Issing, parsing into whatever it is with its authors. Are the books on If it's a list coronary on basically putting in the U. R L four the A p I, which we already have in our in points file, are So we'll be looking at how we can convert from the I http client factory cord into this one. It is worth mentioning that we just stop this, that in our program, not CSU would see that this that they added the CTB library toe the the inversion of control container. Right. So, in other words, we can just dependence inject it. Http, client on it will already kind off our base address, but we don't need to change that much. We can just tell it, which you are a wanted to point toe and so forth. But this is highly configurable at this level. All right, so now that we have created our client up and we see that it's really very similar to what we've been doing upon to know, the next thing that we're going to do is start configuring over authentic you son on authorization for our application.
59. Port Blazor Server to Blazor WebAssembly: you guys. Welcome back. So I have about on screen my visual studio on the two projects the bookstore you I server project as well as bookstore you I Web assembly project. So what we're going to start doing is transferring some off the court over some of the things that we're going to have to be mindful off missing libraries between the two. Because, well, we have a bunch of packages here in our server, but we don't have them yet in the web assembly. So we're going to have to make sure that we get those as well as the name spaces. Because I'm really just went to copy and paste a lot off what we already have. I'm not going to spend time retyping any classes or anything, but we're going to have to make sure that we update the name spaces so that the references work. All right, so let's get started. I'm going to get what? I'm just going to start with the models, so I'm just going to take the model smolder, Andi. Well, actually, I'm just going toe kind of do it as a bulk operation, so I'm going to take the contracts folder Because we have the I authentication repository in the contracts folder we have the models folder on. We have what? We have pages with users. So I'm just here marking what I need. I need a static, right? No. And I need service. Oh, and we need providers. All right, So I'm literally just going to be copying all of these things that probably imagines her to stop e everything. And then we just spend some time re factoring together. So let me just do that. So I understand the hold on control on click contracts models pages provider's service s static on. Well, I guess we can take shared because we have the error message and loading message. We also have the knave menu. So literally, all off, these things can be directly put into the web assembly. All right? And we just spent ah, few always building these old. So we're we're really familiar with what's in them, right? So I'm just going toe copy, just control and click each one on, then copy and then come down to the Web assembly project. Right. Click on click pieced. And then it's going to ask me if I'm sure I want to override on when to say yes. Because whatever was in the original pages the users, the authors of books, all those things I do want override someone to say yes on living to, say, apply it all items and say yes. No. When I do a build, I'm going to be getting a lot off errors once again because those names spaces need to be abated on. We don't have a lot off the fire references or library references for our Web assembly project. Before I do anything, though, the first thing I want to do is remove this host file because this horse file actually give problems, Understand? Toe, go ahead and remove it from the web assembly project. Click. OK, Andi, some errors. Winter we you probably don't see on. Then the imports file. Well, I would want Well, I can leave that until it will do that on a case by case basis. So, no, I'm going to spend some time cleaning off the references. So let's go to contracts and then you see it Same bookstore. You Why? But that I need to put in thoughts W A s m not contracts right. So on that note, I can probably just go find where we went to look for everything. That's his bookstore, don't you? I only Right on. Then I'm going to replace it with bookstores. You? Why? Dark stubble. Asem. So this would be a nice, quick way to just kind off clean off these references. Just remove this one. That I just did. I wanted to do block. All right, aan den. Not entire solution. But current projects are in project being the Web assembly project on Do you can off find her place all maybe. Or if you want to be more carefully, Kandarr place next part of the story place. Aw, Click. Yes. 37 occurrences replaced on. Then do a build on my build yielded 108 errors. All right, so I have quite a few errors, but a lot off them are really referencing like missing libraries. All right, so you see here I don't have the blazers. Claverie, the jade of the tea and certain libraries are just missing. All right, So not to worry. What I'm going to do is just important those libraries, so we'll just right click the project my Nisshin get packages and then I'm going to go through and install anything that I figure it's missing. So I know I'm missing this Jason. New mutants off that J son someone to don't know that. I mean, you can follow my leader. You can just open up. You get from the server project on, then you know, whatever is already in started us go ahead and bro's and install it also. So I know we had blizzard toasts, some discipline to get that one at Blizzard local storage. So get that one getting input file. I'm getting SB net core components authorization. So that supports authentication and authorization for blazer up. You have to get that one off course we can't forget over JWT Library. So just that indeed, ability. And we're getting the 1st 1 and then after getting those libraries that they build on our fewer errors. But a lot offer Francine's are still missing, so I need to make sure that I have the card imports. So I didn't mention the imports earlier, and let's just go over there and get them on. I'm going to get all of these little here. The input file a toast, Onda and, you know, implement them in the projects and then do another build on. I just corrected to areas here because of my friend and replaced the book story. Why reference doubled up. So I just changed all those who speaks those references. And then when I take a look at some of the other errors, they're saying that they can't find, like, I author repository. So that means I need toe ad made a global reference to the contract, so I'll just duplicate this line on DSI. I want, uh, our friends of the contracts build, and then that's even fewer errors. There we go. It's coming on nicely. No, it's complaining about the authorize flag. So the authorized attributes. So we need to include a library for that. Andi going back to the server imports library that or start the server projects. Imports Full file. Sorry, the library for the authorization would be these to some distant To copy them Andi, go back to my new Web assembly imports file on. I just put them at the top just the same way. And then when I do another build, I'm don't even fewer errors, though it's complaining that it doesn't know what author is. So author would be in the models. So once again, we're the stopping over references. Right? So here we have a shared static models and contracts. We just want to make sure that we're doing the same thing here. So let me just duplicate this and get the models. All right. On the newsstand, Maduro build errors disappear. So you see that these are not errors that are oats. Landy Shore. You know, out of the ordinary you can't find in points. You know, endpoints is in the static folders of there's going to be preference, the static. And then that era will go away already. Some off them did. But all right. Yeah. See where Coming? No nicely. Now, some eras are not going to go away on. The reason for that is the hosting model dictates certain things on certain things. Yes, Canton happen in our Web assembly, up the way they happened in the serve up. No, right. No, I am in the file upload service. Andi, if you remember, what we had to do was get the hosting environment, meaning the server up wherever it was being hosted. Get that environment on, then find the Web root path and look for a prose fuller. Now the Web assembly up is not going to be on a server is going to be on the client's machine, meaning it's going to be running on your machine and my in machine individually. There is no server for it to talkto upload a file. So we're going tohave to either exclude the file upload feature from the Web assembly because it's really not practical. Or I'm going to extend the A P I that we're going to, you know, pretend remember that the A p. A. Was developed by somebody else is 1/3 party api I but, you know, theoretically speaking. But then we're going to extend it to say, OK, guys know you can upload your fast directly. So that's one of the drawbacks are some of the dropbox with Web assemblies that it runs on the client's machine. So certain things are just not possible, like handling a file upload on saving it at a globally accessible space. All right, so what I'm going to do right now is just comment this entire class vote so that we don't have any errors. Both file uploads are, you know, missing references here on. I'm going to kill this reference to remove the arrow on. Then I would build on. Then I'm done to eight errors. So I hope you're don't id eight errors like I am. I know what these eight Arizona and they have to do with the A C T t plans library. All right, so this library doesn't quite Where are all these Web assembly has the HDTV client library . Um, but then it doesn't quiet. Have or need the i sgtp client factory. I could have been probably doing it this way in the server at both. Hey, we didn't want to in the server up. We're going to be doing it another way in the web, assembling up. So with those eight errors that I have, right? No. Are these errors that I have a bright know about the http client factor when to leave them ? The last thing I'm going to do, however, is transfer all off the score for the references to all of the services. Right? So that our well, we don't need service side razor. Definitely. Don't you that one but we do need blazer storage and all of the other ones. We don't need the at http client on DSO. So we're going to be kind of picky with what we're copy here. So I need They're Frances to the service for the Blazer local service and toast him with a copy. Those from the startle Relenza program. And then I want to convert them to the new student talks. So that's builder docked services with a capital s on Do the same here, builder dot services with a capital s We're getting red lines because we need or using statements of control dots onder t The suggestion that we get include the references on then what else? Doing it from the start up. I need all of these, right, because these are all services that we have. Well, the FBI state provider, we have the authentications. They provide aware of the JWT token handler and our internal services that we created someone to just at all off those. All right on. I'm just going to do Ah, quick, find and replace. Can I let me just usable? So no, we have builder dot services. I'm just replacing wherever we had services with builder thought services on, then Just include all the missing references on. After doing that, file upload is giving an error because actually commented out everything in that class. So it doesn't think this understand to come in that line out later on, we can deal with that bullets right now, the priorities on reducing these arrows and making sure that everything lines up here. All right, so if I do another build, I should only see the errors that I know off. There we go on. Then, with that, I'm going to leave everything as it is. And then when we come back, what we're going to do is re factor or based repository on how it uses the http clients.
60. Modify Code for Blazor WebAssembly: Hey, guys, Welcome back. So nowhere went to be re factoring whole used the http client. But before I do that, what I want to dip eat is whole. You would probably see a lot of examples writing chord with the issue to be clients. So if I go back to fetch data, you're going to see a live example of what I'm talking about. We inject http clients, give it a name off course on, then you actually can do the FBI call from right here inside the components. Right? So you just do the FBI call right there on it will return the be it up on your good to go while we did. However, from even in our server up was that we didn't do the FBI cause inside off the component. Instead, we broke it open toe repository. Pattern kind off on. We have a baster poster that handles all off talking for us. So we did was inject the appropriate repository are served. So if I look at the index for authors were calling the author people here on we're using the author report enough or Theriot, get operation. No. If I wanted to call the a p i n point directly in the component. What I would do is something like inject, http clients give it a name and you know, I like to put on the square client on. Then I could easily have said model is equal to await on the score clients darks on, then underscore Klein gives me all of these options. So I think what we use is send a sink right now in our based repository, every call that we make, we simply add the bear talking on. Then we do ascend a sink. But then we would have depicted the request stop here, put in the URL and everything. So let's look at the get phone, Sean, specifically. Right. So here in the get we build a request that you know that it's I get requests that that girl , then we create the client on. Then we add the beer talking, and then we do the send a sink, and then we get the response, and then we d serialize the content into the list off whatever type we want. So you see, all of that is kind of condensed into one FBI called the only thing that doesn't happen in what I'm about to show you is the addition off the beer talking. All right, So I could have just as easily said client gets from Jason easing on. Then tell it what exactly I'm expecting. Which would have been a list off author cycle said I list off type author. So the right there is going to handle the d serializing off the Jason for me on. Then, after doing that, I would just see the URL, which we know is endpoints dots, Author Europe. So a lot of people actually write the static string right here, like they would actually write old local host. It's five those and slash FBI slash You know, I don't like to do that. We did the static file so that we could avoid that. And if we needed to change and we could change it one place and it works, right? So instead, you could just say endpoints. That author, in point on what this would actually do is do literally all these lines off court in one in one goal, right? All of that would have been done in one call on then it would automatically return No. Here is something went wrong? No, of course you have to put your try. Catch are only 10. Manage that, You know, experience a bit better. However, because off additional operations, like adding the beer talking before the call and so on. We you know, it was better toe abstracted from the component. Put it in its own class. I would just call it as we need it. All right. So I'm just going to leave this land of cool commended so they can see what was possible. All right, But we don't really need these because we have or trustee off the repository. Nor author Repository, as you know, implements a class that's really calling functions from the beast repository. The based repository has these errors right now. So we're going to fix these errors and then re factor this court to look more like the issue tp client cause as opposed to these factor cause or we build our client manually. So I want to change this toe. Http. Client all right on them went up. Did this one also? All right on then you're going to see a bunch off other errors popping up because no We don't need to do this. Create client because this is a created trying this. We just injected our client that exists. All right, so I'm just going to go to the top. This is the create on. We're going to rewrite all off this and probably condense it toe maybe three or four lines . So what we're going tohave is Well, the first thing I would probably want to do is make sure that the bearer token is present, right? Someone toe take this and put it at the top on Give the sun on the score. So it knows that the client that was just injected please add the default better off bureau on then we still have the function to get the bearer token. Alright. And then this is a create function. So I know that I am expected to do opposed Say underscore clients. Dots posed. E think so? Off course after how it post a sink on. Then this is going to take the u R I. So we have end points. Sorry. No would have been point. So have you are else. Sorry, you are l on. Then we have tea. It's our object or B J my but all right, so we have O B J o b j being what was passed in Andi so VJ is what we passed in. Also, let me reread, So it's not posed a sink. If we do post a sink and we look at the overloads, we'll have to convert the old Bijan to some http content right. So context early, we can say post as Jason E sink on. Then we tell it off type T, sir, Remember, teas are generic because we don't know if it's meant to be author or it's going to be book or if it's even going to be user, we don't know, So teas are abstract object. So we're saying when you send the posts and the Jason equivalent of whatever object is here on this up, this all BJ this literal object has the beater. So this should be I should have said class, So send the Jason equivalent of whatever class is t at the time book author user, etcetera on d o B J has the actual packaged actual beater that should be sent across the packed right. No, this returns and http response message which is the same thing that we declared don't here . So I'm going to say http response is equal to await that call on. Then I can delete all of this. And then what we have no is our check that we have before where we see if the response code is that's then return true, otherwise return for. So you see, we just condense quite a few lines off court in tow, maybe two lines on the same statement that was there before. All right, so we're just going to do that for all off them. I'm someone to do the same thing for delete. Let me just pick a proper point. So, yes, I want to keep this, But then I don't need that part. So I'm going to see how it first let me add the beer talking. So we always want to do that first at the beer token. All right, on then. See? Clients. Darts. Onda. Is there a delete? The think is there on the waters. Delete facing need as, uh, parameters. So it wants to request you. Are I so literally? Whatever we had here on, you can just say that Put here on, then this returns our response. Miss it. So we want to see http Response message is equal to await this car because it's a thing. So we have to make sure we are weight on. Then I just delete all of those ends off court and bring up or if statements. All right, so let's just make sure that we remember to put the beer talking before it makes the call. All right, so the next one we want to get a specific, uh, record. So what we're going tohave here is firstly, we're going to get the We're talking involved at its or client. And then I went to have our let's see, remember that Don't. Here. We would have gotten a response. Evaluated the cord on, got the content to return. Right? So, essentially, when we change the sole to the client, not get if it either gets funding turnout. So we just returned the content, So if it didn't get content is going to return. No. All right, so I'm going to see vier. Response is equal to on. Then clients docks, Get on. I can see. Get from Jason e sink. Whatever. Class type at the time on, then that's going to expect the U R I for that. So the you are a or U R l Sorry would be u R l plus i ds And they just is that in there on , then I can return response. So all off the schools are we had I just return response Rx So there we go three lines on getting that red line because I need awaits. All right, so here we go. Next up, we have the getting off the list, so it's pretty much the same. I'm just going to copy this. Andi put that inside off the try. Except this time, we only have the URL, not Europe, plus I d. So it's just the URL on this time. It is a list off type t. So you see here without a list off T. So it's going to be the same thing there on. Then we returned the response so all of this literally goes away. All right, so I mean, there are good advantage, You know, you can probably go back and see if you can re factor our original based repository to this , but I want to leave the original on the way it is on. So you have two examples. You have the original court, and you have this method. But this once again, is in the Blazer Web assembly project for the beast repository. All right, on, then, for the puppets or upbeat. I just went ahead and did it. So once again, we I mean, I left the initial check. I included the bearer token set of the response to put as Jason a sink a type t with the URL on water gate a package on that I'm taking if the response code is good or not on returning. All right. So that is what our based repository no looks like on when I do a build. I am getting these errors in the others because, well, they're still looking at http client library. So that's that's been planned. Factory. So I'll just go through Author repository on mothers of babies. So it's no longer I TTP kind factory. It is. No. The http client class on dwell file flowed, was excluded or is being excluded for no. Have to make sure we do it for the authentication repository on. Then we're going to have toe refractor chord in this also, because remember that this is using the current factory. So know what this would look like is some post is opposed as Jason. Anything, Right? So I'm going to start off by saying bar response is equal toe my clients start posed as it's on. That's our Jason. You sink and off course after, see, await. So poor says Jason is think on gun were calling in points, not Logan Endpoint on. We're passing in the user as our data. Right, So that is our post on. Then I'm going to take out all of this because this one line once again replaced all of this scored. We're going to check if it was a success. Starter scored our knots Alright on then. We don't need toe. Take all the rest of this because we want the content from the response. We're going to fire, sit and get the token. We're still going to set the default storage talking on change the state off the up on then well, we can routine that line off cored, but I don't think this is necessary because we're really adding it to the call every time anyway. But I'll just leave it there as bit off legacy court. All right. Say, see that one line. Just he thoughts Quite a few. Alright, We leave the love boat, as is on then. Just the same thing for the register where I'm putting in that we have. Sorry. Let me just normalize. So we have response being equal to a post call to the register endpoint, and we're passing off the user object just to seem we on D. C this 19 Of course. Once again, just removed maybe six lines off court. All right, so I can just remove all that legacy cord on the two lines. We would have either registered a person or knots, right? So that is our new look repository on. Then I'm going to do a build on Dhere. I'm getting on air in my up The razor on it is complaining a boat program. So let me check my program. Financier. Everything is okay on when I check. I see here that have Dr Watson twice. Right? So there's a simple name space. Uh, on I go back there, the color coding is no what it should be. Let me just build again. All right, on it's built on. I don't think that we took the content for the update. Razor. No, we didn't. So the Abdolreza remember that We would have consecrated with the authorized view on the cascading on certain things, so I'm actually going to do that. All right, let me just copy this over, but I'm going to me a few changes. Andi use changes will affect the experience for the user. So what happens right now is that if somebody is not logging and they tried to get to a page, they probably would just have at the Pete. What I want would want to do is probably redirect them toe long in p dread or the log impedes. So I'm going to modify the author eyes route view. So I'm going to turn this town into an open and close someone to take that talking out on. Then put a closing talk for it manually. There we go. On day inside, off this authorised route view, I'm going to put ah flood that is not authorized. And then inside here, you basically can put a component, are put up something to see. This is what should happen when somebody's not authorized. So what I'm going to do is set up a component on that I'm going to call redirect to log in . So it's red because it doesn't exist yet. Boats. That's easy for us to fix. So we're just going to make a costume component and which puts the inside of shared so it's globally accessible pretty much our Reza components. We're going to call it redirect to log in Andi pretty much. All it's going to do is just navigate toe the longing p dreck. So once it gets redirected here, it's just going toe un initialize, just navigato lugging. All right, so let's just one more build on. We see that we have a successful building. I'm going to stop right here. So when we come back, we're going toe test the fruits of our labor or factoring we're going to do inter interests with the authentication Onda, the book management Sorry, the author management, since the book management requires up close off, which is not quite ready, but let's just go ahead on test some of it
61. Essential Layout Fixes and Additions: All right, so we're in. I had some data quality issue. So indirect effect those on. We can see that we're getting that authenticated state look and feel on. If I go to the author speech, then we get back. All of for authors. Dana is not, I mean, so she's only getting the view options. If I click view and we see where will you get him? Back? One. So you see here, I'm getting back. Thesis on the side on That's the toast. So I think I need to do some cleaning up, but that's no problem. We just want to verify that we're getting back or deter. If I look at books, swells, the new projects or not, off these book covers will be showing, So that's fine. That's understandable, but we need to get a handle on these post modifications. All right, so at least we've seen that we we kind of successfully bit are surgery brought our server called over to the Web assembly, and most things like a glove. Minor differences. So let's just go ahead and clean up our application. All right, so let me start with the toast, so the toasts would be missing a CSS file, which would have bean in over pages and host Andi. There's that CSS file reference. Understand? To copy that and put it in over index, start Eastern of file on this side. Right on, then. I'm just going to go through and make sure that the toast notification is coming up at the right time. So on this, on our create or we did was we said if it is a successful create, then, you know, show the toast while navigating away. That's good. We do that for the deletes just the same way for the error, just that index where there's no toast on index. But then, for whatever reason, I put the toast for the view page on the tops, Understand? Caught that on, put it below the model initialization. So once a model gets its data, then we show our toast, seeing all your no viewing forever. So that should fix that concern. So I just went ahead and looked at the view file for the books and saw that I had it at the same place and the tops. I just replicated that gene off thoughts. All right, so our application is up on running. No, What we need to do is figure out what we're doing regarding the book. Cover up. Roads are open. It's in general. So let me just review what everything about uploads from the server application. The expectation would have been that this application, the Blazers server application, would have been stored or hosted on a server machine, a central machine where people who grows to the Earl Andi execute the up on when they upload. It's going toe that server. The Web assembly up works a bit differently because it's actually being loaded directly onto the clients machine. Our guys. So what I've done here is toe run, both the Web assembly on the server up side by side. All right, so all that it was going to visual studio go to the solution. The properties and select start on all three projects on the FBI's running in a different way. No bullets, both client applications irony side by side on inspecting elements on looking at the Network Lord for either app. You can see that well, the where assembly loads a few more things than the server does on. In addition to that, you based on which browser you're using or sometimes you can actually see. The DLL is being loaded. So the deals on all the content need needed for the websites or for the application are actually loaded directly into the browser at once. So there's no where Central for a file upload, actually place of file. So for that reason, what we're going to be doing is extending over a PNG just close. These will be extending our A P I for the create on any book toe include a space for our file uploads. So we'll be uploading files to the FBI and the FBI will be storing them on what a reserve ER said, EPA is being hosted on. All right, so that's what we're going to be working on when we return.
62. Blazor WebAssembly and API File Upload (Create and View): you guys welcome back. So, no, we're going to be modifying our book operations to cater for our image uploads. When the previous listen, I would have mentioned that Web assembly applications will not be ableto handle file uploads the way that we would have seen with the server ones. Onda more specifically over blazer server up in bookstore You I it would have allowed you to upload the file and stored on the server that the server up is being hosted on the web. Assembly up, however, does not have such a mechanism since there is theoretically no server behind it. So what we're going to do is modify over FBI such that we can cater for handling ah, file upload or file transfer between the client application Web assembly client application on the server that the FBI is being hosted on. All right, so within the whole scenario, off the scores and all the tasks that we've carried a little to see that the third party FBI vendors have no extended the opportunity for us to actually send over the files instead of having the holes the files ourselves. All right. So I'm going to start by modifying the book model in the a p I. So we have the DT a DT Oh, sorry. Book DT Oh, file in our bookstore FBI on. I'm going to modify all three classes someone toe add a new property on I'll just a detractor on the price on this one is going to see a string file. No, this strength file is going to be different from the stream image property because the image is going to be stored in the database. That value is meant for the database. Over this one is just a little snow Some beaters about the file that is being originated from the client so that we can have it in the server side for the alright. But as we go along, you see, So I'm just going to add that property to book GTO on any other detail that you may have that well, namely book updated on book create because we're also going to be using this property toe, get the details off the file for an update it as well as get details for create on. Then whenever we're loading up our data using the regular book BTO, we also need to load up the file details per image. I'm also going to modify the full A structure a bit, and I'm going to include an uploads fuller. So just right, click the projects. Goto add Select New Fuller on I'm going to call it up loads. All right, So although uploads will go here so we don't have the doublet a bit of the route for the like we did in the, well, the Web assembly or the server. We don't have that here, So I'm not going toe Bernie too much. We just create and upload folder on. We'll just note a point to the content with instead off the environment route. Now let's head over to the book model for our assembly projects. So we had the book, not CS on. I'm going to add that file. I feel there also, so that there's a direct mapping between the detail on the Web assembly UPS model. All right now, let's go over to our create components and let's modify it a bit. So I'm going to take all this file upload service reference because I'm not going to rely on the regular file upload mechanism again, so I don't need a reference to that service. And of course, if I remove that, we're going to get a few errors below. But that's fine. So this I can I just remove it and I'm going to comment it I just remove it on. Then let's modify this cord toe are liking. Now the concept behind what we're about to do is based really in what we did here in exploring the file upload itself. All right, So when we did the handle file selection, what we did was we got the file that was selected. We did some validation on. I actually reviewed this court, and I think it would be better to get the extension. So instead of looking at the file name to see if it contains, I'm going to get the extension, right. So I just made that change as we're since we're here right now, and then I'll take it. The extension contains these key words for the validation are because the thing is that when you do file name, you could have something a txt file with the name J p. G. So it could be jpg, doc. Txt. Right, so that was Let's just say a poor decision on my part. If you caught it and you fixed it already, then kudos to you. No problem. All the better. So let's move along. So after we're validating or file, that was just selected. What we do is uploaded to a memory stream on. Then we do some conversion toe obey 64 data string and then we use that be 64 date astri toe, create a on on immediate representation or preview off the file. No, what we're going to do is rely on this base 64 data toe, actually transport across the pipe between the FBI and the clients. So this is actually just a string on. If you look at it, it's like one huge hush that just represents the data so you can convert from the data. This memory stream represents the date up right? So the reader represents the the actual data, or at least the M s spiral represents the actual data loaded into memory, and it is like where d serializing it into a static string. And then you can take that string on re engineer it into an image which is pretty much what we did here. All right, um, So what we're going to do is rely on this line off court to give us the base 64 data that we're then going to be mopping in our file property for the book. All right, so let's do that together. So on, create when we're putting together all the details off the image and whatever else and then we said the image name. Let me move this off a bit. What I'm going to do is also say model dots file is equal to M s file, which is the memory stream. All right, that has all the data. There's that memory stream. So I would ever advise this court a bit where instead of having multiple memory streams have one memory stream, So if you if you don't have this done, you can just look at it. We have one memory stream that is global to the entire page on. Then what's we do on handle selection is that we feel this memory stream with the data, So that means for the entire life cycle off the speech, that member stream will have the data that represents the image that was just selected. So all I'm going to do at this point is convert. It's basically do this, right? So this image Bay 64 data where we convert not to be a 64 stream just going to copy that since I've been there already on, that's what is going to be the value for the file. So the string that is going to get generated to the base 64 that is going to be included in the file on, then sent across the wire with the model and off course, our book, BTO, has the file property, so it's going to receive it on then know what we need to do is process it on, then re engineer it into the physical file to be displayed are to be saved rather in our uploads order. But everything else remains the same because we're still getting the image name as usual off course. We're going to have to change out some of the path stuff as we go along. But that's what we're here for. All right, so know that we've done this. What we're going to do is just modify the create action for our book. Just just do that the same time. So we have create on day, we're going to have to modify what happens inside off this. So I'm going to check after we've done all of these operations. And I'm going to do that after I know it was a successful creation off record because I want to upload the file on. Then the record creation feels so we can just do this operation after or check to see if it was successful someone to see if not right string dot is no are empty. Meaning is their data inside off this string and the string that I'm going to inter get is in our book BTO docked file. All right, so remember, finds us string, so I'm checking. Did I get anything inside of this and all the way I should get something inside off file is if there was a file on DWI. Got the image as well as the physical file. String be 64 string. Right. So if there is in the data inside off that file file feel sorry, then what I want to do is get the well creates an image path. So our image path to save our I am G pass is equal to on. We need our environments. Someone to go back on. I would have to include some of the things that we included in the original. So let me just backtrack. So I'm just running parallel so that, you know, you see that most of this stuff we did it before with this kind of transferring knowledge, right? So in our file upload, we would have in injected I Web host environment. And that's what give us access toe the entire four. The structure off the server application. Once again, Web assembly application has no web host environment, but our FBI does. So this library would not work inside off our with assembly. Which is why we commented out all of that file upload cord initially to get rid off the Eros. But it is very much present in our A ks. I'm just going to borrow that line on Dinar books controller. I'm going to inject it all right. And off course, while injecting it we had toe include the missing reference. So once you've done that, then you can continue. So when we are going to create over image path, I'm going to have to see something like what? I just use my interpolation on build all the path so first have to get our environment. So underscore the envy dots on. Then, in the previous one we used, let me see what we used in file upload. We use Webroot path now. There's no Webroot path because Www route is what Route pot. There's nowhere Rupa In our acre, we don't have www roots. So instead I have to use content route path, which is where our applause for that is, which is the root pot for all our fast anyway, right? So I'm going to say, Where was I in the controller Envy Dots Content route Path on. Then I'm just going to build out the entire part here slash uploads slash Remember, we have to do the double slash because of escape character on. Then I'm going to see book GTO dot image. Right, so the book detail not image, because I know that that's what I want to see. Vitter's right. I want to see it in the uploads. Folo on the image name or the family and I came across the pipe in the detail. Object is in the image property. So that's the finding that I intend to use. All right on, then I'm going to convert over Bay 64 string. That was in the file. Property in tow. Ah, bite, Hurry. All right, so we're going to create the bite, Ari. I mean, this could have easily been bar fired, but I'm using the explicit data time just so you can see exactly what's happening. So we're seeing bite, Ari. Image bites is equal to convert from Bay 64 string. Right. And if you just look at the overload or the what it takes, it takes, it returns on my atari, and it takes a street. We have both. So we have the bite area to receive it, and we're converting the string. That is the base 64 string that is found in file. All right, on then. Once we have done all of that, we simply do filed out right all back. So we're basically seeing file, which is this is conflicting because, okay, I don't want this file function. The function are I want are the class. I want despond in system that I owe that file so you might have that conflict. If you have that conflict, it just need to qualify it. System that I will not file is equal to write off. Sorry. System that I would not file dot Right, All bites on. Then we have the image part, which we just constructed on. Then the image bites. All right, all right. So I have a good mind to take this for a spin, so I'm just going to start off our project. All right? So I'm logged in as admin, and I'm at the books sexual inimical to the create page on right off the But I'm getting an error. So let me just check the console and see what's happening on. I'm getting an error that we cannot find blazer input for. So that means I'm missing some reference. Somewhere on that reference is a JavaScript file. So in the hosts or the host file from the server project, we would have included it's boats. I guess I It overlooks that inclusion when we searched over. So I just go over toe the web assembly project in the index file on included in the same manner. And then let's try that again. Okay. And we're back on. There is no error this time, so let's just proceed. I'm going to go ahead and create a book. So this one, I'm going to call it Auto Bio. I'm going to give it on Spn, Give it a sensible value. A prize selecting author. My book on then moments have been waiting for will choose a far somewhere to choose my headshot on. Then click create book on, then were redirected. And we get our success, Mrs. I guess something went right on back in our visual studio. In the solution Explorer. We see that we indeed got that file across the pike. All right, so we see that be a 64 string was converted. Don't to the battery and written to the right location on that is our hope. Close folder. Right here. So that works well on DNO. We can continue with our proof of concept across the other pages. So that was for the creek. So I can close create that component is done. What I'm going to have to do No, for our view, index and Raisel is to make sure that our image is actually being sent in the other way, Meaning we're sending from the a p R from the server. So the clients, How am I going to do that? Well, I did mentioned Now that is what we have our new property call file for right. So we need toe converted from the physical file into A by its 64 string on base 64 string. Sorry on. Then put it in the file in the object on, then send it across the wire. So let's start that's process with our view. Complete well view component first, but the view Ah, action. Where we So where you get books? This is get book one book. All right now in get book. What I'm going to want to do is get the path off the image that is inside off the record. So when we get the record, if there is an image value, because there may were very well not be an image attached to the books required, so we need to want only get it. If there is indeed an image, make sure that the file exists and then converts because if we fail to do all of that, then it will definitely catch an exception. And just through a 500 0 any time we try to navigates So I'm first going tohave toe, do something like after we get the record on then we have market into the DT Oh, I'm going to check on DSI if our image property is not know Lar empty right. So if string nuts is not all are empty, not string is no are empty on response stock image threat So we're making sure that there is indeed a value. Then we need the path off the image. No, I already wrote cold like that in the create where I was getting the path right. And then I went after it. A similar bit off court know my philosophy and a good rule of thumb is that if you have to write the same thing more than once in more than one species, write it one place where everybody can call it. So in other words, I'm just into creative function that's going to return Ah, full path for any given image need, right, so at the top. And there's no particular reason going to the top boats, you know, you can write a function anywhere inside a controller. I mean, once stood in the class. But I'm just going to put this one at the top here, and I'm just going to create a quick, private string function that's going to see gets image path. All right on. Then it's going to take a parameter, and that's privates. It's going to take up parameter string imagining. Let's see. Well, finally, string finally now, Cool thing. Ah, boat c sharp it upwards is that we can do all of this in one end. But I'm going to show you something first, where what I'm going to do is return, and then I'm just going to do the same interpolated string. But this time I'm going to have find him cause we're passing and fired him. So I have the environment content rules. The up close folder on whatever fire name is being passed its that way. Any time we need to interrogate that fuller, we can just get the full part from this function. All right, on, then, if it is that we have, you know, we had me for this in other classes or other settings that are not just in this controller than we can make it a bit more accessible, but for no, this is the only place we need it Now, See, sharp. It allows us to write all of this without the curly braces. So we can almost right, like the Lambda expression where I'm going to see the literally the lambda pointer on, then open and close breeze on. Then whatever it is you want to return. So any time you have these one liner going, sons where he doesn't need a quick computation and return, you can write it like that, actually. All right, so just showing you another way to right here functions. So here, this is just going toe return the full path for any image name that is given. All right, so then I can go ahead and replace in the create the part where we said fire image part is equal toe, and we wrote out all of this. I'm going to replace all of that static string. And I don't like being static strings that after reconstruct, it's never good. They call that magic strings on what happens is that, you know, you can make a simple mistake and it throws everything off. All right, so it's easier to just construct at once and make everything else ready. So here I'm just saying, Get me the image pot for both GTO image. So I just replace it with a former sunk. All right, so I'm going to do the same thing inside. Off, over. Where was We are looking for the view, right? So here I'm going to start off by getting the image path. Andi, it's just going toe returned that string, so I had some fluff our own. It's terrible that so we have. Our MG path is equal to get image. Five. Book image, right? So that's the path that we want. Then, as another precaution, I want to check if it exists, right? So if it does exist, then I want to carry out the operations, Understand? To say if system that I o dot file exists this image path on, then we're going to construct or bite Ari somewhere to say by it. Ari on. I'm just going to call it I am G bites is equal to, and then we have our system that I owe, not file on. Then we're going to see, read all bites on, then the I am G path or the part to the limits. So we're seeing read all the bites. That's so I'm GPAs. All right, So read all the bites that this file has on. Then we're going to convert. I am G biting to be 64. Then start in response or going to see a response. DOC file is equal to convert dots to based 64 string on. Then we're passing in my AMG bites. So here we're deconstructing the image in tow. That string that's just going to contain data. So if you take a look at the payload, maybe you can test it in. Postman are so on. But all you see inside of this is just one long string with a bunch off seemingly random characters. No, inside the component where we actually intend to view the image when review the book. If there's an image person that we need to see the image right, what it is doing, Rando is it has a court from the server, so I mean, we can be up to upset, but it's just looking at the uploads for though for that image, there is no close folder in our Web assembly project on. Furthermore, that image name worse does not help. But we just included the data for the image on going back to the example off. The creator shouldn't. Of course, it just yet went back to the example of the create. We constructed what we call an image data. You are l rights were using the basics before on that was used as the source for the preview off the image. So since we are getting back, obey 64 string. What I'm going to do is I just remove this section here on a copy, our cold that will use to construct the base 64. So I'm just going to copy this bit. All right, on, then, inside of you, that's what I'm going to set a sort So that sign on, all off that. But there's no Image Bay 64. But we do have our model docked filed, which has that be a 64 string off course? If nothing comes back, are the string is no? Then this image we know what is going to look like already. Right? All right. So let's take this one for a spin once again what we just did was to hunt, stroked our image file for the view, All right? And we're going to know click on view and see what comes back. All right, so we're back at our list off books on. Then. If I view any off these books, I'm sure I'm going to get some form off error or well, we get broken image. There's nothing there. No problem. But then, if I view auto Bio, which is about that we just created where we have the uploaded file, then I will be seeing my image. All right, so this one was the serialized cause of file existed one. So it was converted into the base 64 string sent across the pipe as a static string on then just, you know, displayed at this preview stitch. All right, So with these two done, the next ones that we have to modify would be to make sure that the image shows up in the listing. If it is present, Andi toe have the any page operated properly. So you see, I click edit, and it didn't even started bothering to Lord because there's just an instant error. When I tried to load it, so we need to fix that. So when we come back, we'll fix the index listing as well as the Edit page.
63. Blazor WebAssembly and API File Upload (Edit and List): you guys welcome back. The last time we were here, we're sitting up or create on view pages, toe work with the new paradigm off sending and receiving image data from the ape yet? No. We're going to start working with the edit. Andi, I've actually gone ahead and written a lot off the cord. Haven't tested it as yet, but I'm going to walk you through each line that I wrote on what it does, and then we'll test it together and re factor together. So let's start off with the fact that I introduced a new function to the book repository on Die. Call it. Get image filing. All right, so the purpose off this function will be toe, just retrieve the image name that is on the record when an opiate is being carried out. Now, the background to this will be that when you are editing a book and you upload a new file, whether it's the same file or not, what I want to do is compare the file name that is coming across the wire, right with the fine name that is on the record. Now, if you didn't change the found him than this filing will be the same. If you changed the file, however, then the findings will be different. And then we'll need toe removed the old file on at the new file, just like we did with the file Upload service where we had to remove the old one and put the new one. It's a similar concept, but then you know where our hands are. Kind of tired? No, because all we can rely on is text. So once the data sent from the clients no, we have to interrogated to see is the the new file name really a new finally meaning after you've edited the record? Did I get a new file name or is the same? Find him if it's the same than I do nothing. If it's new, that I'm going to have to do something. So I just introduced this to retrieve the file name for any book given on idee. Right? And I put that in the book repository on DSO in the book repository Concrete class. Of course, after implement interface, which would then give me this new function. So I have made it a synchronous on. What it will do is just get the books. No. When I wrote this court, I ran into an era boats, multiple ideas being trapped on. That's probably because when if you run it Ah, Basil wearing it in the controller, it tries to find the sea and book twice and transit Carrollton operation on one instance of it while the other one is active. So when you say as no tracking its selling into different word that yes, I looked up, the books are looked up a book, but I'm not tracking its own track it don't use it as any point off reference for any operation. All right, so you can try with and without that function and you see the exception come up, you can just put on break point on the catch line in the action for update on. Then I'm pretty sure it will hit that catch with that error. If it doesn't, then please them. You know, however, that so ever in mind So all I'm doing is getting the book as no tracking where the first or default has that I d number on. Then I am going to get the image so all I want from that is the string the finally All right? No, in the controller, what I have done and you can see I was here d brilliance. And we just removed that. What I've done is after we've done all of four chicks, I put in the call to the gets file name get image finally in function right here, right before we actually do the mopping and the orbit. So I'm retrieving the file name on then. The reason retrieving the family before the update is that well appointed at this point, the old find him is there. So the family and changed, then we no longer know what that all fine name was Andre. Then we don't know what to remove from or uploads folder. All right, so I'm saying that the whole file name it is currently old image on. Then we do the opiate, then have went to do a check. I'm going to say if the image value coming through the data transfer object is equal to the old image. So of course he can just pause and then, you know, replicate the cord. But I just wanted to explain Is the image name coming through the a p. I call the same as the old image if they're not equal than I want toe find the old emits. I'm getting the path to the old image, and I want to delete the old image so that's similar to what we did in our I A file upload service, right? Accepted probably shorter because it didn't have the system that I would. But that's fine. So same thing. So we're just checking if it exists and deleting it. If it does, that's if they're not equal. So even even in the case where maybe there removed the file altogether than that means this would be no or just would be an empty string. So if it's an empty string, meaning the person no longer wants that book cover on that book, but they would rather know image, then we have to remove the existing image either week. All right, then we move on to check if the file property was no large empty aren't so. You soon see where I said the fire property, but it's basically going to be set at the same place it was for the creates right? Remember creating it look very similar, but We'll see that in a moment. So if they if the file sorry for if the file property in the book data transfer object is not null are empty, then I'm going to want to convert it to a bite. Ari does the same way we did it in the create created into the converted into a battery. Sorry on then, right. All bites toe or new path with our new image Name boot GTO dot Image on. Then we have a new image on our server. No. Once again, if an edit is carried out on bond, nothing changed with the image. Then this won't happen on the way we set of the component. The only way file will get set with a value is if the image name changed anyway. So that's will be how we carry that out. No. In the edit component, I started by taking notes. The references to the i file upload service. I removed those. I modified the preview to look, you know, have the SRC just like oh, we had it in the create. They can just go over to create and copy that bit off court and paste it there on then inside off our handle up be it All I did was removed the references, the function cost of the file upload once again. But add the fact that I am putting in a file so right. No, I just checked back on. It seems that put in the wrong factors are stopping and pacing some media space. The cart one where I'm converting toe obey 64 string the memory stream, Ari. All right, so that's the same thing. So all of this looks the same way as how it looked in the creates. All right, on, then. Don't hear if something changed, we just empty the image. At which point, once again, if the image property changes where they gets a new value or it's an empty value, once it comes over here, is going to do the comparison between what existed on what it is. No on, then, delete. All right, delete the old one on, then. If there is content in the file and it will recreate the new one on by the time it gets here, the reference to the new file, if there was one would have already been set in the update. All right, so everything would just kind off flow in that logical pattern. No, I'm going to just take it for a spin, all right, so let's go ahead and try and edit the record that we created. Since we've been modifying these things on, I'm getting that error again, and I figure it's relating to the bullies. Are inputs. All right, Please input file. So I get that era. But generally, when I refresh, it goes away a deceased at the time of this recording, I think it's an arrow with that library and Web assembly, so I'm sure we'll get sorted out soon. But let's press ahead. So I'm going to change this image. I'm smiling. I don't like the fact that I'm smiling, some putting my more serious piece on on. I'm going to say my book for the ages, right? Just to changes. Submit changes on then what? I had a break point there. Let me put a break point that they catch to see if it's going to catch any exceptions. Let's take notes off the file name that's there. It's one D something, and that's the file. Somewhere to go ahead and press F five it does not hit the exception on then. If I view, I see my new image. If I go back to the solution Explorer, I will see that's where his applauds There's a new file. There are. So there we go. We can replace the files on. Then I'm going to try and edit this book again. But I'm not going to change the image. I'm just going toe. Here's the summary written by me. So make changes on the changes were submitted. If I look again, the image is still there. Onda. We have the change that was submitted being represented. All right, so that's good for the edit, The final thing and probably the most important one. And you're wondering, OK, when are we going to get her on to it is to fix the images here in the list. All right, so let's just get down to that one now to modify the data that is being sent in the index listing, we're going to have to change what happens when we're getting the books. So the mere fact that we have to know concert this base 64 string is going to march is going to change How we went a boat building old our response object. Our response object is on object type or a list off type this book data transfer objects. What I'm going to have to do is Luke through each one on. Then for each one with a file name on the file exists, then I will send the corresponding Bay 64 string with it. All right, so let's just do that together. So for each on double time, just generally source of it, and I leave it in item in response. Presenter. Right for each item. In response, what I'm going to do is see if the string containing the image name is not null are empty, right? So I'm only going to do this with those that have values. If you don't come about, you don't tell about you. Say you don't have a book over. You don't get this special treatment, right? So if they image field is not empty, are no meaning something is there, then I'm going to say if the system darks ioo dot file not exists. Andi, check for the path so they get image path passing in. Item that image. All right, So this is just that Double another check just to make sure that you know the file exists. Because once again, we'll hit an exception. If we attempt to convert nothing in tow, Obey 64 Street right on. Then this conversion would look just like with the get book where we just need our bite. Hurry. And they were going to convert its only just do that quickly so this wouldn't be response that far Responses The list party would be itim dot file Right. So once again for each item inside off the response, we're going to be checking if there's an Imagine if there's an image, does a file actually exists, right? Because remember that if I'm using the same database, um, or the same a p I that we use for the Web server. These records are going toe have images, but based on the new path, they're not want to exist. So we have to check if they exist, and then if they do exist, then we're going toe read. Okay, So let me let me do something here instead of calling dysfunction twice cause I need it. Don't Here also, I'm going to just save our I am G path is equal to the function call. All right, on, then I went to check. If it exists on if it does exist, then it will be used on there. All right, so then let us modify the listing. All right, So the parts where we display the image, which is appeared image SRC Once again, I'm just going to change that toe. The type of course that we had for the view, understand? Copy that. Forward index based it in the SRC section on this wouldn't be model a fireball. Now it's book about file. All right, on DSO For every record that has that has on image, it should show otherwise that's going to be no land. We're going to see the same broken images that we're seeing. No. Any way off course, you probably would want to put like, a default image. Or you can, you know, check if it is no and put no text display are no image display or something, but let's just test it as it is. All right? So when the page loads will see that we have our image being displayed successfully, all right, they can probably go through on any of the other ones. And once again, I'm getting that era. I'll just be fresh and then proceed. Choose off file. Let me choose another one. Aan den, Submit changes. All right on. Do we see that it is now being displayed properly? All right, so that's pretty much it for handling the file upload. Once again, we had to do all of this because Web assembly does not necessarily support the hosting off files on a client machine. All right, so we had to rely on the server for that. So if we have gone with the sp dot net core hosted model, then the server up like we have the server up here that we would have created already. So the server up would have acted as the beast on the server toe store, the uploads. Right? So if we're going with the host and waddle, it would have given us the web assembly up as well as the server up already connected on. We could have easily leveraged the upload structure on the upload benefits off having the static files here. Alright. But then we went with Standalone client on DSO. We're just exploring all the options as it really, it's toe server versus kind. Next up, we're going to look at progressive Web applications that I think we've been a pretty good job so far. Off porting or blazer server upto a blazer who have assembly up nowhere want to look at the benefits off the Web assembly, namely, the fact that it's can be installed natively or almost natively on almost any device.
64. Progressive Web Application: you guys, welcome back. So in this lesson, we're going to be looking at whole progressive Web applications work now. A progressive Web application in general is usually a single beach application that uses Broza MPs, and this is usually a modern browser. Andi. I would usually see Google Cruel is kind off at the top off the scope Andi. Most other browsers are based on the chrome engine, but still, Crume has certain things that other brothers can't do. Either way, it uses these modern AP eyes. That's these roses have nobody's toe have capabilities like a desktop application. So in other words, you can build us out single page Web application that can then act like a client side. They stop or native application toe whatever system. So if you bro's on your phone, you can be able to download it like it's on up. He can push notifications to it. It has offline mood, so that it, you know, whenever gets connection, it obviates itself off. All of those wonderful possibilities exists with progressive Web applications. Now the first thing I'm going to do is change my debugging Roeser. So I'm not going to use up prom when to change it to Crume. So if you don't have chromatic edge is also capable. But just make sure that you're using one off those on. Then I went to launch our application. Alright, So having launched it in chrome, you can see a plus sign toe this stop right corner here, and if you click it, then it will prompt you to install. So the thing is that when we were creating over whoever sent the project, we made sure to take progressive web up on because we did that. We got a few files. That kind of just let it know that it's supposed to be progressive web. The browser is detecting those fast and so it saying, Oh, I'm dealing with a progressive web up. Well, then you have the option to install me. So I'm going to click install, And then what happened is it actually installed this application right here on my desktop safe. You what? You can't see my status bar. But if you look at my start menu, see that the up is right there on if I close it all right, that's going to make me exit d boat moored. But then if I go back into people more, with only the way we appear, something to change it to just the way a p i me just said this. A start of projects. All right on. No. With only the Web AP I running on my desktop, I can go ahead or in Deeble More rather, I can go ahead and run this application directly from my desktop. So it's running natively on my desktop. No, it's no longer a bro's er up on. What we had in our project was the manifest file. So I think I give a short orientation images school and find it Manifest that Jason. So with this, we can actually modify the look and feel off the window when we have the up installed. All right, so using the manifest, not Jason finally can actually depict, like the but grown color, the window color, those kinds of things, all of that. It's possible from this file, all right, so I can go ahead and log in. So that would mean at bookstores. Come on, my default password, and then it will again. And then you see ham log being so Actually, this is almost like a little sandbox of browser sandbox because, you see, it's still kind of behaving like Oak Room would behave, asking if I want to see the password. Yes, I can click. Save Yes, I want to turn on sync and whatever, so it's like a Broza sandbox. But the reality is that it is no almost running like a desktop application. So blazer is like a cool way. No to rebuild. Even your Windows forms aren't this stuff. Applications are the applications that have to run almost natively on a device, But you don't really want to go and build a native up. You can just use blazer toe build a progressive Web application that can install almost anywhere on do the regular things on. Remember that this is no talking directly to the A P I. It is not relying on any server in between. It's not relying on my machine really on I can. It is literally just going across the Internet to the FBI, you know, theoretically speaking, going across the network to the FBI on doing everything in real time. But it is a desktop application. If we take a look at inspect elements, it directly can go to inspect. I get the inspect element up just the same way I see all off the logs happening. I can see all the source I can look at the network on. Then I did network and I just referred to the page just to see all the resource is coming back on Dad. At one point I was trying to allude to the D alleles being loaded. So while it's in way more, sure, it's not loaning the dealers. It loads them into the onto the machine. The entire document run time and all off, the library's independence is there. There are the deal is the packages. There's blazer, tools, input file, local sort. All off them that we would have been including on using in our project. There are Get loaded on installed with the the actual package that is this application. Now, that being said, you want to be very careful and particular about your hosting models. I have alluded toe, you know, each one having its purpose in specific situations. In a situation like this, you probably don't want to go to many things. So in doing the server hosted application, you have the option to kind of abstract. A lot of these dependencies or other more serious dependence is on. Have them on the server rather than loading onto the clients machine where you're doing a straight assembly. Then you have no choice but to load everything onto the client machine as you see here, so you know it can pick and choose and refuse. But at this point, you have created your first these. I think it's your first, but your first Blazer progressive Web application.
65. Review and Add Changes to GitHub: Welcome back, guys. Where are the points where we're going to just do a quick review off All off the things recovered in this model on, then check in our court to get up. Now, the first thing that we did was to explore the options off the Blazer Web assembly on. We went with the Web assembly, not core hosted on progressive Web application options. We also didn't choose authentication. No, Once we did that, we got a project that was very similar to our believes. A server project on. I'm just collapsing everything so you can see the structure as it waas. So we got pages. We got a program, not see a snow start about CS andi just collapse everything in expand us. These two, so we can compare while we had to do really was bring over most of our cored named the contracts, the models, the pages and would continue. The components are already built. The FBI status off state provider stuff, our services, the shared files, the static so literally. All I'm trying to say is that most off our court from the server application was reusable in the clients or Web assembly versions so at the core, the body groaned. The server and the Web assembly templates are very, very similar in terms off the court required to get open running certain differences. Though the Web assembly uses an issue tp client, that to me is just much easier on my need to double check if it's actually available in the in the server version. But the CTP clients here most examples I think a pointed out would show using the GDP clients directly from the view. I'm just making your calls. But we built out our repositories for over calls so that we don't have to, you know, spin up a client every single time. We just did it one time on. We put that inside of four Biest repository on what we did was re factor or be supposed her to use the http clients instead off the http client factory that we had in the server person on what we did was to just put in our beer token on then make or calls. So this library has posed as Jason leads a sing get from Jason on dso on right, So this handles the de serialization and serialization out of the box. We didn't have to do much more than just call that function on Get the response. Alright. Other factoring included over re haul off the upload procedure So we actually have to modify over 80 I project where we included the uploads capability on the A P I side so that we could facilitate the fact that this web assembly version off our project does not have a server to store fats on. So we just turned that a p a. That whole city appear into that server to store files. All right, so now we're just going to go ahead and right click and chicken. So you're going to be getting FBI experience, server blazer experience as well as Web assembly, a blazer with simply experience, right? And we just go ahead on commits, all right? And I put in my message that I added Blazer, Web assembly on file upload toe 80 ibooks controller. And then I'll just commit all and sink on once that is successful. Well, you can always come to my repository and make reference. So all that has been done
66. Migrate Project to .NET 5: Hey guys, in this video we're going to discuss how to upgrades and gotten it five or even installed it if you've never installed any dominant framework at all. So.net five is all encompassing and it is actually backwards compatible with lots of things that you would have in your ASP.net or your detonate core 3.1 application. However, if you do desire to my agreed to.net five, then this video is for you. So our journey starts off with a simple Google search for.net five, we can follow the first link and then that will lead us to an era where we would either download the SDK or the runtime or bullet. There's really no limitation on which one you should. So you would install the SDK so that Visual Studio gives you all the tools you need to be able to create a dominant five application, whereas the runtime is more sets off libraries so that you can host the application on like on iOS. So you can check on my other video on hosting dominate core applications. And the steps you need to go through to install the runtime, prepare eyes and publish your application. So for the SDK, we want to download the appropriate version and say if you're on Mac, Linux, Windows, they have an installation package for you. So you can go ahead and click the appropriate one. I'll go with the x 64. And once this download is completed, you will get this installer, which allows you to just go ahead and click Install. You go through any security checkpoints F2. And it's a fairly quick, straightforward process, so it will let you know and it was successful. If it wasn't successful, you'll probably want to double-check die. You got McHarg version and are reachable to Microsoft support. Either way, if you have the silk screen, then you're one step closer. Again, go ahead and click Close. And then if you're going to be creating our brand new project, then you can go ahead and launch Visual Studio. Click Create Project 2-0 templates and let's go with a core web application. Click Next, give it a name. So this is just a sample, so I won't be too formal with anything wet and click Create. And then on this screen you would be able to select dot nec core 5 from the list. If you are however, intending to migrate dominant core API or blazer project to.net five, then we're going to be doing this with this project. So I have here an existing project. It has the bookstore when it's called bookstore API altogether, what's it has a bookstore API, TAS, bookstore wi, which is the blazer server. And we also have a blazer Web Assembly project here. So I've actually done a lot of the work. What's I'm going to do is bring up the existing dominate core 3.1 version of the code. And the relevant code changes so that you can see exactly where your changes need to be made. So let us begin with our API. So I'm just going to write tickets, go down to my source control tab and compare with the previous version before I made all the modifications. And I'll just walk you through all of the most important parts. Actually, there is only one very, very important part in this file, and that is the target framework. So if you are using dominate core 3.1, that's what you would be seeing, what this is, what you need to see. So to the left is the existing and to the right is the new. Alright, so we need to change that to net 5. So you can just mean doesn't just even go ahead and save. And then after making that adjustment, you need to update all off your project or France's Aldi or library for instance. So that's why you see some of them in red because I would've already done that update. Some of them I haven't done the update, so I'm going to walk you through that one by one. So you Candace, right-click, go to new get package manager. And what happened to me was that when I selected all packages and then send updates, I got some form of arable and not the exception object, center reference are not entirely sure why I'm getting that book. The consensus seems to be that when sometimes when you tried to do it in bulk, you might get the error. That was my experience I'm sharing with you in case you have that struggle. But what has worked for me is if I just select like three at a time and then click update, then the Package Manager will just take over and do it to those any errors, of course I have to accept one or two times those errors you can ignore those. Those are just build errors associated with the entire exercise. But my point is that you just wanted to make sure that all their packages are no updated to 5. So you can just go ahead and do them individually if you have to, if the if the whole bulk update works, so you then that's perfect. So no, I've completed all of them. If I go back and look at the diffusely even more updates, right? So anything that was one seeing 3.1 is no seeing five any previous version is no C in the latest version. So that's what you want to do to upgrade your API project. There's nothing more to it than that. So know that we're done with that. Let's us move on to our delays, our projects, no, blazer projects have lots in common. Once again, this one is a server, this one is a Web Assembly. They have a lot in common in terms of what the changes are so weird, there are commonalities. I'll kind of show them side-by-side. So you can see that you do it in both are the corresponding fuzzy and both. And there are certain things that we will only do it for the web assembly. So our first change has to do with the host file in the server versus the index file in the Web Assembly. And I'll just, just for our friends, in the server project you will two pages and then you'll see the host dot CSS file in the Web Assembly project to go to www root and you see your index.html file. So in the host file, the major changes that you're going to be adding, this bit of code, this line of quotes here, adding a new style sheet. Alright, and what you're seeing is the assembly meme. So this should actually be an underscore because that's my assembly name. So it starts out dash, what an underscore. So let me just me at that. And so you see it's a good thing going through this together. So this underscore and save. All right, so that's what that line looks like that and make it a little bigger. So we're adding link, HRF, bookstore UI, bookstore underscore UI or whatever your assemblies nim is some nice liquids annoyed Assembly Name is just to look at the namespace flag up here. And then you will see what the appropriate accepted solution name is. And then we say a dot styles.css, and then we add the row equals stylesheet. So we're going to be adding that inside of our head section for our hosts. Alright? And then we're going to be doing something similar for our index. So let me just bring up the index individually. So we are going to be adding this line of code here. And it's the same principle. I'm going to change this to underscore. So it's bookstore on a score dot Watson or whatever the name of your project is, not styles.css. While they are here, you can this me, this change also. So let me just go boxes he exactly what we're changing, where it changing this from up to the div with ID up. Alright, so instead of seeing a tag named up, we say div with an ID up, and then the content remains the same. So you can just go ahead and meet that change in your index file. The next major change comes in our imports fossil ours, spective server and web assembly projects both have imports dot areas or file, and the inclusion is the same. So you might get an error in the server blood, then you have to be a tear components in order to get rid of it. But we want to have using Microsoft dot ASP.NET Core.com dot web dot virtualization and tried to place it in a similar position to where I have it, which is underneath where, but before the HTTP, whereby somebody dot HTTP, alright, and that would be for our Web Assembly, for the server, it goes in the same place. Or at least under Web, cause you probably wouldn't have the Web Assembly HTTP library. So you just have it underneath the dark web day and just add dot virtualization. Next is to our main Leodes, the Reserve component. So that change applies to both. So I'm not going to show you both. It's a CMNH change in both server and web assembly where we just want to include a new div. And we're going to give it that class equals speeds. And then all of the content that was there before. So this is the origin out here. We're just going to take all of that and put it inside a foreign you div. So it's going to look something more like this to the right. And let me see if I can reduce the left. There it goes. So that's what your new mean, LEO, which is going to look like whether it's Web Assembly or server. Now another major task is that we are going to be adding a CSS file to that very component that we just modified, right? And there is a class page that we just introduced, the content for this CSS file. You'll find it in the resources. Or you can just go on the repository and look at the contents of the file we can copy and paste. Haven't made any modifications outside of the default that would've come with.net 5B is a project, but this is what the file looks like. So instead of me trying to show you sake and type it, you can just go to the resource and gets into yourself. The main parts of it though, is that we're going to be adding it to the shirt. So you're going to go to shared, right click, click add. And this goes for both server and a web assembly. We're adding a new item. And then the name that you're giving to these new item is the same name as a component mean Leodes, Dr. razor. So that's mainly old dot razor dot css. And then if you notice in my solution explorer, you actually see that it gets listed on the mean Leodes. Alright, so you sit up close and I just added it. Once we do that then is going to actually come as a subfile off the main Leodes. And then we can just put in the content once again, that's applies for both server and web awesome. No windows CMV, and we're going to be doing something similar for nav menu. So we have nav menu dot razor, and once again for both server and web assembly, we have nav menu.html, or we're going to be adding enough menu dot, dot CSS. Once again, you can go ahead and copy the resulting CSS or the religious CSS rather. And PhD in. You don't have to go in and try and type this, just get the content and plug it in. No, well one more CSS activity to complete, and that will be to the app.js CSS file in the web assembly. So in the Web Assembly project, you go to www root CSS and then uci dot CSS. In your server projects, you would go to www root CSS and site dot CSS. However, the content for both fads remains the seam. Alright, so this is once again does the default that would come with.net five blazer project. But since we are upgrading, we're just trying to move across all of the resources that would be needed by default. So that is actually it for the side-by-side activities for both the server and the web assembly. Just to backtrack a bit for the server, you want to make sure that your target frame work. So that's for blazers server, just to be clear, your target frame where it needs to be as Kelly say, the same thing that the Web API target frameworks. And so you can actually just copy that from the web API, a project, and make sure that your blazer, you sorry, or blazer server UI Project also says target framework net 5. So I'm going until focus a bit on the server projects. So what I'm going to do is unload this so that I see fewer arrows. And just wanted to make sure I'm dealing with just the server project. You probably don't have to do this part, but the very seeing the errors. And you want to make sure that you're isolating your server project activities, then you can do that. So I'm just going to do a build just to see what's wrong. Alright, so you see here I'm getting some errors of boats, my projects so I can go to new get. And then I see that I have a few updates that receive. The bulk update feature will work for me. And it did. So let me try and build again. No, I'm still getting some errors here. And that is actually due to an ambiguity problem. So this error is saying that the function input file are the toggle or component. Rather, input file is ambiguous because I have a library called blazer input file. And there is one that comes built in with blazer at least right. Know there is. So that's his ambiguity issue. I'm just going to comment this old because if you're not using input file, then you don't have this problem. However, I will do another video where I refactor the code surrounding Blizzard, or it's actually just go into find all the references to that input file and just go ahead and comment them out to get rid of any errors just to make sure that we don't have anything else. So we see one build succeeded. So that is good. So old sad off this ambiguity which is probably unique to meet. Anyway. If it's not, then we'll work through later on. No problem. Right. And all we have upgraded our blazers server application to.net five. Now I'm going to switch over to the web assembly. So I'm just going to reload the Web Assembly project. And I went to unload the server project just to make sure that we are looking at only one thing. And then the first major change, I'm going to point all it has to do with the project file. So if I compare this with the original, I'm going to show you the changes that we meet. So one, we change the project SDK from Microsoft.net dot dk dot web to Microsoft.net dot SDK dot blazer Web Assembly. Another thing is that we removed these two target Framework references on. We changed it's all to just net 5. Alright. And then we're going to continue with updating semaphore references. So another thing is that we remove this pocket reference so that a bucket or friends of components that were by simply adopt built, we just removed it. So that's null missing in the new Version. Now at this point, feel free to try and D2 are not quite done yet, but you wanted go to manage packages and see if you can run an update for everything. So let's try that. And that is done, good. And then we want to go to our program.cs. Someones have compared this one so we can see exactly the lines that need to be modified. So the first line is that we are going to be updating this reference to hub, a hashtag in front of it. See it, that's really all that we did. It said builder, rude components that add up. And then in quotation marks up, we're just adding hashtags up. Alright, the splitting on what's a pound sign or a number sign or hashtag in front of the word up. The other change is that we're changing. Well, we already had if you already had this as odd scoped, then that's fine. Some people use a transient, but the recommended way would be scoped. Alright, so you want to add scoped your HTTP client. And the only reason it's showing the whole line highlighted, because a fix some spacing or broiled alive. But essentially that's the major change here, being sure that that says at school. But after doing all of this, we can do a build and see if we have any errors. And the error that I'm getting is the same area we had with this server. So I'm just going to comment these old for null just to make sure that we can report a clean migration. Although eyes, so if I do a build and then I see one project succeeded, so almost doing to reload the other projects. So does right click reload, right click reload, and then do another build and have no errors to report. So let me just do a quick run just to make sure everything works. So what happens is that you have to make sure they are APIs running and your and your clients. So I mean, all of them starts at a if in case you don't know how to do it, you just right click. We'll do properties and just make sure all of them are on starts. At least if you're a project loops that in mind. If you'd, if you'd Sardinia Server hosted blazer up and probably don't have that problem. So I am not seeing my side and let me just go ahead and inspect and see what the problem might be. And here I'm seeing that I'm a 404 error, so it's failing to load the resource or the CSS file that I added. Alright, so I just suspect that maybe I should've used a dash, should send a Fonda score. So let me just double back and check. So back here I'm just going to me, that's adjustments. So I'm just going to try the dash instead of the underscore. And all the thing that we want to do is, and this is my man topologies in our manly all to want to put our sidebar inside of our PhDs. So skip that step. Eluded to it because of all fire was from everything. But our sidebar should also be inside of this page div. So let's go ahead and restart. And that looks more like it. So there we go, there we have our blazer UI application being rendered. This fact while it was being rendered initially, but we did quite a few things, so we know at least know where running in.net five. Well, that's it for this video. Have a good one.
67. Fix File Upload - Remove BlazoredInputFile: Hey guys, welcome back. Now coming off the heels of us update our blase or applications that.net five, we had some issues with our input fields, so we're going to just put that to bed. So what happens is that initially we had to rely on a third party solution to facilitate the file upload. But Glaser has since implemented a more native input control, and so we're going to start using that. So the first order of business, and I'm going to show you the changes side-by-side with both the blazer server up as well as the web assembly because the code will look pretty much the same between the two with a few modifications here and there. So the first thing that we wanted to do in both import files is remove the reference to blazer input fast so we can just go ahead and click it and remove it and save, and then you can go to your create. So I have a bunch of open here, so I'm going to try and narrow it down to the ones that we absolutely need for this exercise. So what we want to do is go back to our create and we can uncomment that lion. So I've done some of the work. I'll just be walking us through what you need to do, right? So it can go ahead and uncomment this input line. Actually took me a little bit easier. I'm just going to bring up that comparison view that we use when we're doing our grid so that you can see exactly the lines I'm changing. So we uncomment this input control line. And then we have to see, and some are for data types. So initially we were using IFF file list entry. And we call that file will retain that name, but we'll call it eyebrows are files. So that's a new datatype. Were also not using memory stream book just stream. All right, so you can go ahead and meet those two changes to the data types. Now moving along inside the part where we would have done the whole processing. So this is the handle create our, let me, let me do it in the exact flow. So this is hundreds of file selection, which is the event that is called when the input file is changed, right? So we handle selection. So we want to change that parameter once again from IFIs list entry IRI to input file change event arcs. And I'm just calling that one E. Alright, so that looks a little bit more like if you did win forms or there would be if that's what you kind of see for the events, right? So E is going to embody the file or files or the object with the files that have been selected by our input selector. Just denote we could also put on multiple here if we wanted to Tableau for multiple selection, that's how we would just attach that attribute there, multiple. In this situation, we only want one. So I was just making that point because E, using that E or using that object, we can get multiple files just to see, you know, once we have made that change for, you know, lead file B equal to E dot file? No, I could've said E dot and get multiple files which allows me to say how many files, up to ten. Our well, up to whatever number I can get, right? So I think by default it will be ten, but I could specify two, I could specify one. It's really up to me, the developer, but I can't get multiple files. But in this situation I only want one file, so it's E dot file. And then I did introduce this if statement previously, so I just made sure to have it everywhere where instead of checking the entire name for the extension, I'm actually getting the extensions of our extension is equal to path, but yet the extension a file name. And then we check if the extension matches what you want. And after we do that, we wanted then initialize our streams. So initially we had it to be MS file is equal to nu memory stream and then we copied into the memory stream. Well, no, we can just see MS file is equal to file.js open read Street. And so we just read the file directly into our stream object. No. Some additional stuff and actually found this quite useful. What we can do here is just resize our files. So let me just reduce the old code and show you what I've introduced here. So, you know, we're showing a preview of the file. And the bigger the file in any situation is, the less efficiently it loads are, is handled by an application. So what we do here is just resize the files. So we say resized image file is equal to and we await file.js request image file a sync. We specify the file type that we want. And then we just say the size. So right now I'm just resizing whatever file has been uploaded TO 100 by 100 pixel file. And then after that, we load it into a buffer. So we say var buffers equal to new byte array with the resized image file dot size. So it's a byte array to the size of our new resized image. And then we await the resized image dot opened the file stream or opened the stream, read and read into the buffer. So this is where we copy it into the byte array and then converted to the base-64 data, and then we have the same image URL. Alright, so this is quite useful if you want to resize your images in-between. Quite easy. Alright, so that is it for how we handle the fascination. Because remember the file selection just shows the preview of the file. I'm know to look at what we do when we're handling the actual form submission. And the change here is really little cosmetic change. So I've kinda refactored our file upload service, where I have a function or method, same name, but I removed the dependency on the file. In retrospect, we didn't use the file and we went over to the Upload File. What I have is a stream object and our name for our image. So let me just jump over there and show you the changes that have been made. So inside of our eye file upload contract. So I'm gonna start off with the interface again as heat that's added a bit of a cleanup because add more than one method's does off the refactor that we did earlier. But it's always good to remove old code, especially if you're using source control because you have the versioning history anyway. So I removed the old code and know how this new method, which is public task upload file. It takes us stream parameter and a string name. And so for the actual implementation of this, let me just go over and compare. Well, probably doesn't make, since I've gone bureaucrats as almost a new method. But let's go through it anyway. So this is an AsyncTask taking this tree and call MS file and a string name, we remove a lot of other things. So I probably need to put bought that try-catch block. You can put it there when you're doing this, but let me just reduce the old cooled and focus on the new code. So what we do, I retain that buffer right by it's red till a teller ID. And I initialize my file stream, right? So I think that, that line is almost the same except I did a using statement right there and then I wrote into the memory stream. So forgoing all of that word, just initializing this. And then I'm just seeing Wild by its red is equal to, I'll wait MS file, which is my stream dots read async buffer. So stream read whatever is contained inside of the buffer. And while that is not equal to 0, once again, let me reduce this secant, see the flute picture. So while by thread is equal to, I don't where are we hitting? Reading the contents? Where just doing some math here, total or it is accumulating to the bytes read. So just so you know, while it's reading, it's just adding up. And for that entire period is just writing asynchronously or buffer ari. Alright, and pretty much that's it, right? That handles our file upload. So that is actually the code required for or create in the, I believe that was our server project. Right? So let us just take a quick look at what we do for our Web Assembly. Cause you know what the Web Assembly where actually uploading to the server, the API server as opposed to handling it locally like we're doing with a server project. So it's pretty much the same thing except OnCreate. So sorry, the Honda selection is pretty much the same thing where doing the same thing here we're taking the input file and displaying it. So you could literally just copy and paste the handle selection from the server over to the web assembly. But then for our handled creates, we do something a bit differently here, where I initialize the buffer to the size of the actual file. All right, then we open it and then we send the toolbar as a base 64 string. All right, so that's the only difference. So just four bit more contexts that may bring up the comparisons. They can see exactly what are, at least see what was there before. So we'll do the same data type changes, right? But then don't hear all we did was convert the MS file or our memory street until IRI it, that's all we did. So we're adding two more lines or we're initializing this Bytes, sorry, and then reading the files contents into the battery. Then we're converting it to the basics drew, And that's just about it. Everything else, once again, is quite similar to the server. For our edit. Not much different. Once again, it's pretty much the same. So once you have those changes though, you can go ahead and test it out for yourself. And you see that our file upload is not working.
68. Essential Code and Configuration Fixes: Hey guys, welcome back. So in this module we want to actually deploy our application to the Azi, your cloud. So I'm using as there because it's just the unnatural feats. Visual Studio's already tuned for Azure deployment. And well, everything is Microsoft. Everything will work perfectly. There may be some hiccups along the way, but any hiccups we encounter, Be sure to walk you through why they encounter we encountered them and how we get our own them. But before we start looking to 0, we have to look to our code because there's some configuration changes on essential file, changes that we need to make to make sure that we have a smooth transition. So while we're recording on our machine, it was almost Okay enough to hard code some of these pots. But the problem is that these bots don't exist on another server. There's no see users and that folder structure wherever we are going to be deploying our application. So I want to do is make it a bit more dynamics. So this particular file I have open is for the bookstore APIs, the actual project file. So you can just double-click the project file. You'd get this XML. And then what we want to do is put in a new node, the property group. We wanted to say generate documentation file, true. All right, so on that, and then we need to change the actual documentation file path. So what I'm going to do is remove everything all the way up until the actual name or the sludge can afford a file name. And then I went to replace it with bin. Then slash dollar sign, open parenthesis configuration, and then close parenthesis. So this would make it more dynamic and it will actually tell it January, this file in the bin folder. So the bin folder is basically universal to any weird that our application. So on to me and that change to avoid any conflicts on the Azara server when it starts seeing oh, what's I don't know where to put the file because we're told me to put the file doesn't exist. So this will bypass all of that. The next major change would be to the n log config file. And it's a similar situation here where we would have hard-coded, we're, we wanted the files to goal. So instead, I'm going to set all of this to be the base directory. So it's literally going to read dollar sign BCE, dear. Alright, and then, well, I need to have my logs folder slash logs slush. So what's going to happen is that our n log would directly to our logs folder that will exist in our solution. We want to do the same thing for the internal log. I don't want that ever end anywhere. I just I don't want it on the C drive. I wanted in the base directory solely and just have a lots folder NOW with both internal log and the daily activity log. So now we can move on to our blazer files and all configurations here aren't that much. It's just that we really, really, really would like for the endpoints file to be a bit more dynamic because retinal and I've hard coded the baseURL, which for development purposes was perfectly fine. However, when we actually deploy, our API, or API will no longer be located at this location. This location is only existent when our APIs running. When it's in the web, we need the address so that we can make the baseURL are relative to that address. So what I'm going to introduce here is a quick if statement. So it goes from the NYC hashtag if. And then we're checking if it's in debug mode, then we know we can use this base URL, right? If it's debug, then that's fine. However else, meaning it's not in debug mode and I'll just end here. So, and if so, then we can know, introduce this URLS, something else here, I don't know what it is going to be at because we haven't deployed or bookstore APIs yet. But we want this here so that when we're a boat to deploy our blazer ups, we don't have much more to do but to just fill in the blank with the null homestead address for the API. So I'm just going to go ahead and make that change for both blazer projects. Right? So we have our web assembly project looking for debug versus not the bulb. And then we have our server project doing the same. And in our bookstore, EPA is now a bit more dynamic with its configurations. So when we come back, we'll start the deployment of our API.
69. Create Microsoft Azure Account: Hey guys, in this video we'll be creating our Microsoft as 0 cones. Like I said earlier, we can get started for free. To get to this websites, we go to absorb dot Microsoft.com and then I guess the roads you according to your region or your language. But this is what the website looks are should look like. And you can read through it to see exactly what 0's all boats. It's about being futuristic, allowing more collaboration, and operating more seamlessly in a closed space, right? They're all over the world and you usually would just choose the region that is closest to you. So I'm actually in the Caribbean region. So my Joel says, region is east to us or East US two. But not for this video. This video we are just creating the columns were not sitting up anything about reasons just yet. And so to get started, weaken those. Well, if you have a live account already, then you can just go ahead and sign in with that live of cones. But you can just click Start free. And here they tell you that you can create a free have gone today and you can get started with 12 months of free services. So that's a good deal to me. And if you scroll down, you see 12 months of free, popular, free services plus $200 credit which will expire in 30 days. So they give you $200 a can create V virtual machines, again, create resources in the cloud and experiment until that money is o. And that's really just for one month. But then there are certain services that you just get for free for the rest of the year, and then you will have a few other services that are always free. All right, so what we're going to do is just go ahead and click Start free. Then they'll ask us to sign in with our live of cones. If you have a live account once again, he can go ahead and use that. If you don't have another cone, then you can go ahead and create one. And this is a very recent option to sign in with GitHub. So I have a live a cone that I use, but I'm just going to walk you through the create 1 first. Know the live icon doesn't necessarily have to be at live or at all.com. It doesn't have to be traditional Hotmail account, it can be a Gmail account. So I can actually use the same email address I used for GitHub or email addresses I use when I'm signing up for things I can use that whether it's Yahoo, Gmail, Hotmail, whatever it is. And just click next. And here it's already, it's telling me that I already have a Microsoft dot gone. So that does this driving my point though, that once you have an e-mail address, it doesn't have to be a Hotmail or a traditional alive AECOM boats there, thus creating a Microsoft or Collins for you with that email address. So you can go ahead and sign up. It's a pretty straightforward process. Now they are Conda decided already existed. That's an account I was using to sign up for the free colon. So. I actually just went ahead and logged in and because I really didn't settle much more, I think that your registration process is actually going to look very similar to this regardless, so on to get over the hurdle of putting in your email address and proceeding, then you're probably going to end up on a screen like this where you're going to be asked for your demographic information just for their record, keeping my country energies on his Jamaica. And I'm quoting him my phone number that I click Next. And then they say, do you want to verify your identity by phone or the want by card? Or it's I'm going to choose takes me by phone and I just got the text. It didn't take long at all. So I'm just going to put in that code and then verify. Now here's the part that might deter you if you're not prepared for it, they will want to verify your identity by card so you won't be charged unless you upgrade, meaning they have different YOU clause subscription plan, so right. No, you're signing up for the free subscription plan. Once that free subscripts on plan is done, then you won't be able to do much on the platform until you send off our new subscripts on brand, which coincides that upgrades. So like I said earlier, there is p As you go And then there's pay-as-you-go dev slash test, which is the one I am on, which is like half the price off the regular PICU cool. So I actually provided my card inflammation when I signed up. And having done that, you can click makes them click agreement if you don't have a card or you're not comfortable with providing our card details then. Yummy, and you can stop here, that's fine. Later on when we're actually deploying to Azure, you can still see what it will look like and see how beneficial it is to you. What, if you wish, then you can go ahead and provide your information and then click on the agreement and accept the agreement terms and then you would be in the platform. So I'm just going to sign into my Rayleigh cones, might quote unquote Rayleigh cone, but one that I use and show you what a 0 looks like. Well, actually I just typed in Porto dot 0.com hoping that they would ask me to login, but I did that and it just rewrote and mus into seem a cone that I was just setting up George Williams at gmail.com. So this dashboard, so this is the dashboard at the very basic level, they have a panel to the side here listing ODE. Quite a few services that you can get. But then, because we didn't complete the set of four because I didn't complete the settled, at least then when I go to subscriptions, I'm going to see that I have no subscription, right? So like I will see in the subscription is how the rate you as a customer with AARP as you go enterprise or whatever. So if I later on decided that I wanted to provide my information, I can just come back and click add. And then that will bring me to complete the sign-up procedure where I actually add the subscription. And so this is a free trial on that war sitting up, just know you have pay-as-you-go developer support. Uzziah of quite a few of them. Alright, so I would probably go with pay as you go. But that yeah, this is all in the in the steps of signing up for Azur, and that is if you wish to proceed with that. But then for this detour, really and truly, I just wanted you to get as far as the dashboard so that you can see that this is a 0, looks like this is slowly workload management portal. You can set up your virtual machines. But for this course, we'll be looking at up services.
70. Deploy Book Store API and Database: Alright guys, welcome back. So we're going to actually deploy our web API project tool or Azur hosting. So I'm assuming you already created your account. You need to just go right-click the project and then you will see publish and it's eluding. There we go publish. Once he clicked that, if you're not already signed into Azure, please go ahead and do that. Then we'll see the targets here. So if we wanted to publish to our local server would choose yes or, you know, choose the one that works according to our situation. What's I'm facilitating a 0 here. So as you're, we click next. And then we wanted in an App Service, right? So we go ahead and click Next. You may be prompted to log in at this point, if you're not already logged in with your cones are your Microsoft account. But at this point, what we want to do is create some eyes your instances. So my subscription here is because you go dev test and you may not necessarily have that one or you may have a different one, but as IZ get access, then you should be fine. So I'm going to go ahead and click the plus sign because I don't have any resource or resource group, or whether I have a few resource groups here from previous experiments. But what's I'm going to do is create a brand new one. So this is going to be Bookstore RG, Right? So I click OK and then they're asking me for the whole steam plants. So I'm going to click new and I'm going to choose, I like using East US, but then you use the one that's closest to your reason. So I choose East US two, that is the recommended one for my reason, which is the Caribbean. And then my size is going to be free. So you have free and you have others that you'll have to pay for. So, you know, to be most cost-effective, we're just going to choose free so we can get this operation done well, you can always scale up, that's the beauty of Azure and clothing generally can always scale up if you need to. So then we have that hosting plan. I'm going to call this bookstore API blazer plan. All right? And so I'm just renaming it. You don't really have to do that. You click Ok and then click Create, and then you actually have to give that sometime. Now once that operation is done, you can go ahead and click finish. And then it would have done the preliminary settled for our publishing package. Alright, so let's just, I'm just going to walk you through a few things here and we do have this little cautions and so we do need to just double-check everything. So I'm just going to click Edit on any thought published. And what it is showing me here is that it's going to create a server or the server that's it just created for the AP service is called that the site name will be Bookstore dash API. So that would be weird. The EPI will be deployed. I probably, you know, he can probably customers is a bit Berlin Plutonian name or something. You don't want tough too though. The destination URL will be determined by the ST name ish, right? So you can choose the destination URLs, I can say. Bookstore, API, dash course. Alright, so then that URL will now be taken by Assyria. God used that URL at least until I unpublished, my court are unpublished does subside your current. Alright. So I can say bookstore API. And I'm going to put my name. Alright, so that's Society and then bookstore API. And let me just say a turf war. There we go. So if I tried to validate the connection, it will just try to verify that it can actually get in touch with the site. And a green tick means we're good to go. If we look at the settings, you would see that the target framework, which is net five, goes up for recent upgrade. And then we have the file publish options so you can remove all files that are already there. You just love fresh, applaud every time. You can look at the deity BASECASE. Yeah, the default connection here, this is our local database connection. You have by agrees shuns they can do. And you can also install extended logging services. So you might not want to, you want to be careful what you tick, because these things cost money. So, you know, the fewer things that tick is, the less money theoretic value but spending, but just to be very careful. So I'm just walking through this. Understand what you're looking at. So I can go ahead and see if that's and then you'll see that my new site URL would be that when it does get published, we haven't published anything yet. The next thing we need to do is set up the database. Now this one will cost money. There is no free database, or at least at the time of this recording there is no free. So I'm just going to go ahead and click Configure, choose Azure SQL database. And unless you are one of those hybrid setup switches usually facilitated by big corporations and you might not be able to do on on-premises database. On-premises means where you are versus in the code. If everything is in the code, everything is accessibly. If it's on-premises, then you're going to need some advanced networking and good ways. And as I said, bigger cooperations tend to support that. I am not one strand support that it's cheaper for me to just create the SQL database and local. So I went to go ahead and click plus to add a database. So then does ask me what does the DSMB S name? That's I want bookstore dash API underscore DB. Thus the default name is giving because of the project name and that's his. I mean, it's obvious, that's fine. I choose the resource group that I just created. So it's always good, especially in closed to keep everything within the same resource group. And everything can be in one container. That's what resource group means. The database server. I don't talk on active server. So because I don't want to have an active service for database, for Azure SQL. I have to create a server. So I went off to create new over here. And then it's going to spin up a whole server. It's going to ask me for the username and I'll just put in a password that I know I can remember. So that is very important. Make sure that you can remember the parser because you need it to login later on. You click OK and then he will fill out the rest for you and they go ahead and click Create. So that's going to create the server and set it up for connectivity. And well, that process may have taken awhile, but once it's finally done, you can go ahead and click next. It will show you the connection string. So it knows that we're looking for default connection in our project. So it's just going to call it default connection. There does ask you to provide your username and password that you just created. So I'm just going to do that. And what happens is that it will actually just put that in this connection string. So you can actually just copy that connection string. You can view it if you want. But you can be careful with that because it's going to have the username and password that you just entered here. You can also choose to use the app settings are the Key Vault. Key Vault is more secure, but then once again, that costs. So I'll just leave it at the app settings and then just click next. And anything else it's asks us we just clicked Finish as your and Microsoft nor best so anything they suggest he does click Next and let it know that you're interested and then we can close so that caution button is gone. Our database is now gone. Figured, let us try and do a published. So I'm just going to click publish. And it's just going to go ahead and do some, some operations in between. Alright, so when our published operation is done, it will try to launch all upset and this is what I'm getting at the moment. So let me try and get over to my cones. Alright, so I'm logged into my xhr cones and I wanted to go and try and look at all the resources. I see here. I have the web, the App Service, right? Then you have the SQL database itself. And then known area of the service plan, which is basically just a fancy way of saying the server.js hosting the service, as well as the SQL service server, right? So let me look in our web application. So sometimes it all node because it's missing a configuration. I think I know what it is, but I just wanted to show you guys how you can go about kind of debugging and finding out what's happening. So what we want to do is go to advanced tools. And then this advanced tool is called Khufu, right? So it gives us some operations at the lowest actually interrupted the service or the underlying files or infrastructure. So I wanted to go to the debug console and I'm going to navigate to site www root. And then we can see all of the files that would've been published from this perspective, right? So from here I'm going to do.net and bookstore dash api dot DLLs. So this is not me. Starting the application there it is, Bookstore dot DLL. And that console just give me a whole telling off. So let us go back up and see. So this is a warning. Okay, I can go by that one, but then here you see the fail. So in sorry, it keeps on jumping. So at this point it says fail and it's complaining that an exception occurred for the context. And then it saying that it cannot find is B net rules now so if it's company enables, In other words, it can find the database. There's something going on with the one-off the database tables. So let me just take us that Azur go over to the database itself and then we can look at it. Well, well, it's a really want her to connection strings. So just wanted to know how do I connect to this database server so I can actually use my local tools. So I already have my Management Studio installed. And so I actually want to connect to this server using my, my, my local server or my local tools. So I can select this server equals part, just get that TCP. So the port number that says my server. So to school with demand management studio and connect. And then I'm using server authentication because I need to use that same credentials as I had just settle while creating the server to use those to connect. Knowing trends of conduct is going to tell you that you don't have access because you need to actually setup some firewall rules or a low for the firewall for external traffic to get to your server. So from here I can sign in and then enable it. So I'll just go ahead and do that and let you see. So once it verifies that I am YM, we'll ask if I wanted to add my client IP address, another sale kink, because I don't need the entire internet to get to this database. I don't need my machine. So once I'm here I can look and I see my idea to BCE. And this is kind of, so let me zoom in a bit for you. And then I can expand my database and look at the tables. And then when it takes funds, what don't you see? So that is our problem. There are no databases. So yes, he created the database, but once it failed to do was actually carry out any of the migrations. So let me go back to visual students, see what setting was there for that. So I believe if I go to Edit, go to settings, and then it's going to take out to discover the databases there. Alright, so I can drop this, don't, but, and I see this migration unpublished, meaning, when I'm publishing to this, do I, what do I apply? Right? So I can just say save and then do another Publish. So once we double-check our database off that that last deployment will see the migration done. However, we still are not completed because we don't have our books and authors tables. So the problem is that remember that we did Database First, we approached this entire project from the premise that the database already existed and were connecting to it. So we don't have migration files for those those what should I say, those tables, right, those files. So what I'm going to do is just create a migration. And then we can try. That's again someone just say add migration. And we're going to say add existing worded differently if you want tables. So we'll just create that migration. And then that migration, No, we'll take into account the fact that we have the authors table that we need to create, a books table that we need to create. And as you add to it, you may have other tables and so on. So now that we're publishing again where he told it that it should add the migration. Let me just double check that that option is there. Alright, so those say apply migration. So that's fine. Let me go ahead and publish I get. And when we look in our Management Studio or no CO, two tables that were missing. So authors and books are there. So we know that each time, and this is not necessarily the best practice, this is us doing it, but foreign for me, son sick in a real setting, in a production setting, you would never have automatic migrations. Alright, best practice would that you would be that use crypt, don't the database with all the tables and artifacts and anything that needs to be created. You hand it to your senior, whether it's a DBA or your senior developer, and then you get it into the system. But never, it's never good practice to automate your migration. Alright, so where buck with coup after we've done those last two, publishes upon to know you're still seeing the 500 error, the error that we saw initially. So let's try this again where we say a.net bookstore api dot DLL. Let's see what's happening this time. All right, so our application is not having any problems as far as this is indicating. But then once again, we're still getting this URL off. It's being able to find our site. So at least we know we've gotten certain things out. So anyone who published, we have to make sure that the database is operating and running. And we can see that that's what's happening here. So let's go back to your back door up and see what other settings might be there. As I'm not off, here's what we're going to do. So as you're actually sorry, dominate core actually gives us the ability to view logs based on things that might be going wrong in our site. So I'm going to go over to the site, go back to w, w roots, bring up our web config file so I can actually edit this file right here. And I'm going to change this std log, enabled them changing this to true. So what this will do is actually produced a lot because sometimes the obligation is running, but there's something else in the underlying infrastructure that is causing it to fail. So by enabling that log, we can now see a physical log file and we've already established TO imports on log files are. And the location for the log file would be insight in knowns that are root log files and we should see it appear here. So let me try and execute the application once again, a few times and see if anything, if any log file appears for me. Alright, so nothing came up in my log folder. Let me go back to Uzziah and just make sure that everything is okay. So Buck in the web and I'm seeing here that the URL, the URL reset, the euro, got reset to this values. So that is our URL. This entire time I was trying to go to the URL that typed in, which is dash EPA industry awards. So let's try this URL and see What's happening. And voila, beautiful, beautiful sight we are seeing are swagger API, like we know we should be seeing. And the exception is that this is not running on our local machine. This is no load. Alright? So if you use post money should be able to go across the internet and access your API that you have built. Note that we have our API hosted. What we want to do is publish our blazer ups, but to make sure that they are pointing to this hosted API as opposed to trying to see the local one. So we'll do that when we come back.
71. Deploy Blazor Server To Web App Service: Hey guys, welcome back. So now that we have our API, we need to print our blazer apps for life in Azure. So we have our API being hosted at this address. So we need to meet this, the base URL in our end, 0.5 for both the web assembly and the server will be doing server, right? No, what? We wanted to see him ten, so don't forget what that is. Our base URL for our showed hosted API. So we're going to go ahead and are published activity, right click, click, Publish. We choose a 0. The web, the Azara observe is what we can reuse the same up service that we have already. It would just overwrite it, right? So I need to just add a new service, and this one is for the bookstore UI. So I'm not going to change any names. We can reuse the same resource group and I can put it in the same hosting plan. So all of that is fine. But the service itself is the actual container for the files for the web application. The hosting plan, once again is more that the machine that we'll be hosting. So I can go ahead and click Create. And the ones that creation activity is done, you can go ahead and click finish. And then it's going to bring us to this familiar screen, except it's going to tell us something about what signal are and configuration. But if I click Publish, it's going to then prompts me to have to configure signal r. So remember that this is the server that the blazer server that we're deploying. And I believe I already have the sigma aliased services enable it. So I didn't get that prompt bullets. If you do get the prompt, I load them to install the signal. Our services and all of that will just be Bootstrap for you and they will be to your project reference accordingly and publish your website. So here is our blazer server application running. So let us test it out. So if I try to login and remember that would've already seabed. Some default users still have admin, bookstore.com, Piazza and Na. And then if I login success with annual for short, speaking to the API, there I am. If I go to authors, it's going to churn though. The authors, there is no author to load. I can create a new one. I'm just there we go. So now we know for sure that our blazer up is speaking to our API.
72. Deploy Blazor WebAssembly To Azure Web App Service: Hey guys, welcome back. So we've published our API and we've published our blazers server. And if you looked closely between the two, you'd see that there was not much difference in terms of publishing to Azure. Yes, the better required some some additional work with the database. But the both of the app's worked fairly similarly when publishing to know for the web assembly, it's slightly different because this is not server-based. It is a static application. And so Azure has a static container for this kind of website. So we are going to be doing slightly different steps for our web assembly. Before we go on to the publishing part though, I just have a few code changes that I wanted to point out for our program.cs file. So the program.cs file in our web assembly, we're going to make the following adjustments. Initially, we would've had a line that would have given us the builder dot add services. So I had a line here to add scoped JWT security token handler. We're going to remove that line. It has been proven to be buggy. And someone pointed out that we have to do that slightly differently. So what we are going to do instead is underneath where we initialize our HTTP client. We're going to just have two lines that looks something like this. So that's an underscore. Here, is an underscore. There we go. Did OUT header and underscore equals new JWT payload. And then we have to make similar adjustments to our authentication handler, or more specifically the API Authentication stateProvider. And what we're going to do is remove the, before we remove, we're going to initialize the JWT security token handler in the file itself. So instead of injecting it in, we're just going to have private read-only JWT security token handler. And then token handler is equal to JWT token handler. So initially in the trie, we started off with this line var Tolkien handlers equal to new JWT token under. So you can remove that and just initialize the object at the top here. And then in the loved in function, we also had that line so we can remove it also. Alright, so then our Tolkien handler object is known global to the entire class. It's not being injected in. And then we can use it accordingly so you can make those two adjustments. And then we're going to get into the fun stuff, which is the actual deployment of our application. So log into the portal and while you're there, I want you to go ahead and create a resource. So from the marketplace we're going to look for, I'm just going to type static. And then I want a static web app. It's still in preview, but it is stable enough for us to compete our tasks. So we're going to go ahead and say Create. And it's going to give us a little form to fill out so that our resource group where using the same resource group for everything else. I'm just going to give this web up the name blazer dash WAS some reason for me, US East, US two. Then they will require you to sign in with GitHub. So what happens is that the default setting for this is going to set up continuous deployment and integration pipeline using GitHub actions. So they require that you sign in with GitHub. So from the get-go, I would encourage you to get, to get to Hobart cones to be checking your code on GitHub. Well, here's where everything becomes integrated. So we're going to go ahead and sign in with GitHub. This authorize it. And then they're just going to ask you some questions. So I don't have anything special to put here, the repository or tough all their positives repository on GitHub. I'm going to choose my bookstore API. And then the branch is master. Then we go down to the build-up details, which I don't have to provide any details on. It's not required. So you'll always see the asterisk when something is required so he can go ahead and review and create. The next screen is just the look over. Are you sure? And then I'm going to say go ahead and create. So what this is actually going to do is set up my good TO Bob colon with the deployment configuration on fast as he can see, he's actually trying it's actually doing the deployment, right? No. Right. And then it will create the upset. If I go to Resource, Then I would actually or should actually be able to get to the resource or the application from here. So when I click that link, well, they're only seeing your static web app is live and waiting for content. So we have to make some modifications. If you're a senior up then kudos to you, no problem. You've done it. However, if you're not seeing the up, then just stick around a little because we're about to go into it. So for the deployment history, I'm just going to click are well, I can edit the workflow. So it's really the workflow file, which is just a configuration file wish they'd just created inside of my GitHub repository for this project. Alright? And there is a key part in this file where it's talking about the application. So the application here means when I look in this repository, where do I find the Web Assembly up? So when we look in at least my own and if you're on was set up the way I have mine set up, then you're going to see are then you would have it in the Web Assembly folder. So you need to make sure that you know which folder year Web Assembly up is in. So I'm going to go back to the workflows and Mackenzie, I have to because at cento born before, but we're focusing on this one. Years won't have the same name as mine. That's fine. Just fine. The one and we can just from here in GitHub. And I'm going to meet this adjustment here. So for the up location, I'm going to put the folder in the repository that the OP can be found at, which is Bookstore dash white dot was. And then I can go ahead and commit these changes. Now the cool thing is that when we do a commit, it's actually going to start a deployment everytime we committed changes starting out deployments. So where do we see these deployments? If we click options, then we would be able to see all of the workflows. So anytime we do a committee, Candace, go to auctions and you'll see that it's setting up its already setup with the CIC pipeline and this one is in progress, and if I click it, it will then show me the jobs in progress. I click, click on build and deploy and it will show me that, okay, it's doing a builder at No. So you have to give this a few moments. So you see we are getting some option. Alright? And if you're not getting that action and just make sure that you have a cart folder path, otherwise it will fail. If you look back at my actions, you'd see that some failed and that was mainly due to me not having the correct path. So with the correct path, you wouldn't be seeing better results than that. And it will be going through. Alright, so you see, no, it's running these actions and know it's at the build and deploy fears. And my axon phil eventually. But then in retrospect, I really haven't checked in all of the wonderful changes that I just made. It's still trying to publish the old code that we just had fixes for. So I'm just going to go ahead and do a commit where I quickly get, Sorry, I got to get changes. Because of the new Visual Studio, certain things have chin, so we're in good changes and I have my message and just thought commit all and sync. And once we've done that and this is head back over to git hub and double check on our process. So if I click on Actions again, then you would see that I just did that check in and it's no doing the deployment. So let's give that a few ones I get. And this field again. So maybe are having better success than me. But this is good because at least when these things fail, it's good to know and understand what to look for when they fail. So I suspect that there might be something wrong with my with my YAML file that is the deployment for someone to go over to the code, look at the workflows again, and check through. And I think I see what the problem might be. So the good thing is that's actually have two of these files. One not I'm sure worked and one that didn't. It is not working. So what I'm going to do is look at them side by side and compare and see what I might need to change. So I'm just going to get some big creative here with my Leodes. So I'm going to have copies of this type of file on either side. So this side is the one that we need to get working. The left Islam not working and to the right is the one that worked for me in the past. So I'm just looking through to see what could be different in terms of these configurations as the application is the same on both sides. Up location is bookstore, the bookstore ui.R. Guassian on both sides then have API lift. I kept it a on one set and common AND other. Let me just normalize that. Also have www Rutan ones that are not on the other side, even though it does say optional, but at this point I'm not entirely sure what is not working. So I just wanted to make sure that I have everything accounted for. So with those changes, I'm not really seeing anything else that could be could be different. Right? So I'm just going to go ahead and save. And of course that save will trigger another build. So let's watch the auctions and see what happens this time around. And those changes seem to have done the trick for me. So what's a successful deployment at least according to github? So I'm going to go back, refresh my web sites and loading, unloading. There we go. All right, so this is our Web Assembly application running from Azure to cause our bowl, we finally got there. So if I just do a login just to verify that it is speaking to the APIs. So that's admin book store.com and be that a dot. And then we try to login. And there we go, where successfully logged in. If I click on authors, it's when to bring about the authors that I would have previously created from this server application. They're both talking to the same API, both being hosted in Azure. Epa is in Azure. Everything has been deployed knowing knowhow to deploy an API blazer server up and know our sub-assembly. And best of all is that this is the progressive web apps. I can actually just install this directly from the browser and it will be an actual application on my computer, no. Alright. So this is an actual application running from the computer, but speaking to the EPA, being hosted in Azure.