Spring Boot Firebase CRUD Application 4 - Implementing Firebase Services in Springboot

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we'll talk about how we can create a crud service and connect our local springboot application to firebase and do some operations on top of the data which we have stored in firebase and firestore so welcome to the third video um fourth video where we finish almost finished building up our crud api using firebase and springboard and once we get done with this we will have a fully functional crud api application up and running which contacts firebase so let's get started and let's uh start implementing our current service where we actually use the firebase apis and connect to our database and do a bunch of stuff so let's uh start implementing so first we create uh our host we implement our create apis so let's start with that so we have files store db5 store is equal to let's import the classes which we want so it says no firestore is available oh my bad i should spell it right yep great so we have fast or adb faster and we use the first store client um dot get faster and since we have already configured our application using the service account key we don't have to worry about uh authorization anymore our app is automatically authorized so that's a great thing to need to know let's have some boilerplate code here collect shins api feature and this is going to be equal to db dot fb db faster dot collection so which collection which database are we trying to get our data from so this is basically our database inside faster so if you go inside that and if you see our collection so we have two collections here the first collection was made before the videos users and we are using cloud underscore users so let's call this card underscore user so inside this particular collection we want to create a document so we use dot document and here we create our document so let's actually create it so we do card dot get name and we do a set and suppose so we have our crud name right here and now that you've actually uh set or committed to our database let's send back uh the time when we did this uh when we get the result back so and we'll convert that to a string so api future dot get right so we don't get and here we have created our uh created or implemented our create functionality so what's happening here so first we connect to our database using our credentials which is happening behind the scenes when we initialize or we get the file store from our uh account the next thing that's happening is we are telling our using api features to actually connect to our cred user and then just do a set of crud and that's basically as simple as it can get when it comes to implementing our api the next thing would be to implement get so once we have created it we need to get it so let's actually implement our get api and we'll see how that works out for us so how do we get it the first thing which we do is the same as create cards so we connect it here you can obviously uh abstract it out inside card service but let's just use it uh for easier purposes here so we do a document reference so basically look up inside our document and which document are we trying to reference right so we db faster dot collections again give it a collection so user underscore name and we do document and we want it by document id and that's how we want our document so once we get our document reference uh the next thing we want to actually get it from the api so for that we'll be using api future um document snapshot so document snapshot and this is going to be a future value which you're going to get from document reference dot okay awesome so now we have our uh snapshot and from this snapshot we want our uh from the api feature we want our document snapshot so let's quickly write the code for that so this goes away we have our document snapchat it's not a future that we want and this is going to be our document and we are basically going to do for printed above so we do a future.kit as you can see a lot of abstractions that we you know have to deal with here add the exceptions and yep now once we get the document from firebase we need to convert it to a plain old java object so pojo right so let's do that now so let's have a crud and the next thing which we have to do is check if the document exists if document exists then what do we do we do crud is equal to document dot to object pretty simple rod dot cross and that way we return perfect and if it doesn't exist then we return so that's basically how it usually is so we first connect to our firebase uh client and then we connect to a file store client and then we get our document we get the document reference the snapshot and then the document snapshot back from the api feature we convert our document inside two objects from a pojo and then we send it back to the user so that's how we implement the great crud api more information can definitely be found on the website in the description below and let's implement delete so once we get our data we can delete it so how do we delete it again pretty much the same as before but slight changes so let's talk about them so instead of doing a document we do a document uh id or name so id dot delete and as simple as that we are good to go and we don't have to do anything else here so this is just going to be uh right result spell that correctly and this is going to be api future and the next thing which you have to send is basically uh the document id so success fully deleted space document id and yep we are good to go with delete as well so this is how we implement delete get and create so let's quickly see if we have something here so we have a document id as user underscore one so when we do a get uh after running this we should be able to get that back and it should be converted into a pojo giving us the so what is giving us it's giving us document id name and profession so if you get that back when we run it so let's run it and see what happens do we actually get it back or not so this is going to be user my pad again user because that is what we our collection as and let's run the app and see what's happening let's open up postman as well so that we can do our queries and our api hit our apis so we have that here pretty interesting thing and let's wait for the server and post mine to be up and running it always says a few minutes but never actually takes a few minutes so that way uh you expect that you know you're expecting it to be minutes but they uh give it to you in seconds and you get this uh dopamine hit postman is you know fast so that's how they get to you but anyway apart from that we have our server running we have postman setting up so it actually is taking minutes that is weird so we have some time till our server runs and until then postman hopefully should be up if not then we can obviously use uh we're doing a get call right so we just use the browser for that but let's give postman some time the server is up and running so yep postman is also up and running and it did take some time to do this so what are we doing here so we're doing a get drug right let's quickly see that inside our controller we are doing slash create okay get no uh get cred so we do a get and here the key is going to be document id and the value is going to be what user underscore one user underscore and this when we do a get on this we should be getting back our data so document id is not present okay i get what's wrong here let me quickly fix that so close this down go to inside card and this is document id so what was the issue it gave a bad request right and what was the vargas requesting parameter nothing id is not present so it needs a string parameter which is not present so controller document id oh my bad i think i know what i did wrong yep i spelled it wrong so let's run this over again should be up because we didn't do any changes and all you have to do is just have to be id my bad and almost we are good we're done server is up to ascend and let's see what's up so initially it does take some time and as you can see we have our class and freelancer professor here so perfect it was working and the next thing which we need to do is uh implement our update api and also test our application and see if it's working perfectly or not so thank you for watching i'll see you in the next video
Info
Channel: ProgrammingKnowledge
Views: 11,710
Rating: undefined out of 5
Keywords: Windows 10, How-to (Website Category), JAVA_HOME, Oracle, Javaprogramming, Javatutorial, Spring Boot, Spring Boot Tutorials, Learn Spring Boot, Getting Started with Spring Boot, Spring MVC, Spring Boot Actuator, Spring Boot Projec, Learn Spring Boot Tutorial, Spring Boot Full Course, Spring Boot Online Course, Spring Boot - Online Courses, Classes, Training, Tutorials, Free Spring Boot Tutorial, Go full stack Spring: Spring + RESTFUL API + Spring Boot, Hands On Spring Boot Course
Id: 49QUcPoR9W0
Channel Id: undefined
Length: 12min 49sec (769 seconds)
Published: Sun Sep 05 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.