Transcript
Hello friends. So previously we created a global company search engine that allows us to find company information across different legislations and, uh, have basically have a form to create a company in a Rails app. And, uh, to find a real company from the database, uh, from national database, I would be able to select a country code. I can, uh, search for a company by the name of the tax registration number in the country that's search in France, for example. Find this company in the name of this person. I click on my selected result. It auto replaces this info field with the, uh, registration number I save. And here I know that, uh, I saved a legit company with a legit registration number in my database. But what if I want to not just, uh, save the registration number, I want to save, uh, all the company information and be able to pass it. Well, the simplest thing I could do with, uh, my current approach is just, uh, uh, auto complete this info field, not just with the company registration number, but with, uh, the whole information. So let's try again. I will again search for France. Ian, click on it. And you see it, uh, kind of looks like, uh, uh, uh, ruby hash. I click on Create company, and here I have this whole information, the whole payload saved in my database. How can I pause it? Let me go to the company partial, and let's say I want to get company info. And inside it, I want to get the, uh, complete name of the company. So non-complete. Normally this should work, but it doesn't. Uh, oh yeah, I'm doing it on the country code. Of course it doesn't work. So I do it on this info and you see it doesn't work. It just finds, uh, this specific, uh, element. I will make it, uh, not exactly this element. And you see it doesn't find it. Okay. So, uh, this kind of search doesn't work. Okay, let's try turn it to Jason. Let's say JS Pass company info and find noncompliant. It doesn't work because we have this UNP token error, most likely because, uh, JPA doesn't work, uh, with, uh, this, uh, symbol. So I would need to say company info G sub. So I'm going to replace this Ruby symbol with, uh, this symbol. Let's search now and it still doesn't work. So, uh, the problem is that, uh, we get a ruby object as a result when we create a company, when we search for a company, let's, uh, search for a company. You see it is kind of, uh, a ruby hash. Then we send this H as HTML string into our controller, the store it as a string and it becomes very hard to pass it. We want To save it, uh, as, uh, js o straight away, not in text field. That's why JSON format kind of exists. So let's try storing the estimation as JSO. Uh, let's rate migration rails, generate migration, add the payload, uh, two, uh, companies. I'm going to add, uh, JSON payload column two. Companies add column, uh, to the company's table named payload type js O. And also I'm going to rename this info field into a registration number field because, uh, basically we are store currently the registration number of the company. So, uh, I will say rename column in companies table. Uh, initially it's named info and now it's going to be made the registration number rails DB migrate. Okay, duplicate name payload, maybe already did this kind of manipulation. Let's try once scan, I will just drop my database rails. DB drop db create db migrate. Okay, let's have a look at our schema. So have the registration number, the payload. Let's just replace, uh, the word info with, uh, registration number across our application here in the form. Uh, anywhere else in the controller info replaced with the registration number. Okay, so, uh, let's just see if the app works. Now with this new migration, I'm going to go to the list of companies, create a company. We have this registration number that we cannot manually edit. I'm going to find the, the company, okay? Create a company, okay? And define method info. Yeah, because, uh, info whether we still have this info. Yeah. Validates info, validates registration number, presence through, let's try again. Okay. Uh, I created the company. The registration number seems to be empty. Let's have a look. Rails Console company. Oh, okay. Yeah, it is present, but uh, it doesn't look very nice. Let's have a look at our company registration number. Yeah, we have all this text. So let's go back to our search front and just store again the registration number. I will destroy this company, create a new one up save. Okay, we have the company's registration number and country code, and now we want to, uh, store the payload. So all the company information as Jason. And I think the best way to do it, considering that, uh, this form basically currently works to find the registration number of the company in a, a specific country to know that it's legit. So we already do this, and now we're just going to, uh, make a separate call to the API to update the payload, uh, with the JSO information for the company. So here I will say after great commit, uh, update, uh, payload. Now I will say dev update payload. And uh, I'm going to make one of these two API calls. So I will say if, uh, uh, country code equals France, I'm going to say company dot search France, and the query is going to be the registration number. Here, I will have the results. So results equals company search France by the registration number. Let's try doing it first in the console. Um, company equals company do first. Uh, then I will say company search France based on the company do registration number. And this is going to be the results. Okay? Results. Okay, here we have the results. Inside the results, uh, I have this hash of results, so of elements in the search, and here I will have results. Results, okay? And here it is, uh, an array of results and let's say count dot count, okay? So we searched exactly by the company registration number. So, uh, Uh, they have only one result. And it is, it is very good. So, uh, uh, if results, results equals one, then I'm going to update the payload. Self update payload with results. Results the dot first. Okay? So when the company is created, we make another API call to update the payload with, uh, this information. Let's, uh, quit. Let's actually just try running, update payload on a company. Company equals company. First company. You see the payload is currently nil. I will say company do update payload company. Okay? It's still nil. Uh, advise it nil. It means something may went wrong here. Uh, let's try running again. Uh, company do registration number results. Inside results, uh, I will get results once again. First, okay, this looks, uh, good and uh, I will say company update payload, the results first company. Okay, now the payload has been, uh, updated. So this seems to look well, let's get the console and try creating a new company. I'll go delete this one. New company again, b Create company. Let's, uh, see if, uh, we have the payload updated. So company dot payload, okay, it is empty. This is, uh, not good. Why is it empty? Maybe let's try calling, uh, self registration number. Self country code, just in the case again, delete company, create company payload, uh, is still empty. So let's put a binding here and see what's happening. Binding B gonna create another company. Okay? Uh, self country is France. Let's run this. Let's run self. Okay, it didn't fail for some reason. Let's try to see line by line. So we get the results. Let's see if there is just one result. No, there seems to be more than one result. Let's see. Results. Results dot count. Oh yeah, I should have put the dot count here. Sure, yeah, I didn't count the results. Yeah, this kind of dynamic mistakes can take some time. Okay, let's try create another company. Create company. It's run the a p call. Oh, no, I didn't know yet. Yeah, I forgot to remove the bin. But yeah, you see the payload has been populated. And the final, let's check if, uh, uh, we can pass this payload as Jason. So go into the company payload, CRM. Okay. And we get a company registration number. So looks, uh, good. And now we can just, uh, uh, display it in a nice way. So I will say each do key and value. Then I will have equals key equals value. And, and I will put them all in a separate line. So div on the start, diviv on the end, uh, I will make the key bold refresh. And you have all the company information, uh, displayed in a nice way. So we actually store the company registration number as a Columbia database, the country code, and we have the payload that can be different for each company in each country. And we just display everything we found looks good. Let's make sure that it works not only for French companies, but for UK companies. So here I will make a very similar thing. Uh, I'll make it Elif, uh, UK and for uk we just have results about, uh, items. And here search, uh, uk. Now of course you can make this, uh, you can optimize this, uh, if you want, but it's not for this example. So, uh, let's find another company in the the UK database. Okay? Company payload, uh, is empty for some kind of company. That's why I get an error. So, uh, here I will say at each, okay, so if company doesn't have payload, we don't, uh, try to display the past version. Let's, uh, remove the company's so it is clear to see. Okay, now it's create a company in uk, Skippy, create company. And you see we have, uh, all the information, uh, in the payload stored as Jason, so we can easily pass this js and display it in a nice format. That's it. That's, uh, why I would use Js to store, uh, and pass, uh, hash like data and not just text field. Also, another small thing I would like to update, uh, going to our company search controller. So, uh, I wouldn't, uh, search for companies only if there are more than three symbols because there can theoretically maybe big companies with, uh, fewer symbols in the name. So, uh, I'm going to remove this condition. And also instead of having headers accept the text to stream, there is a simpler way we can just say, uh, that response kind will be to stream, okay? And this, uh, should be now, uh, possible. Of course, we can also try like a syn and evade. Okay, let's see if it works. Now, uh, go back to companies at a new company, uh, French create company, and, uh, it worked. And, uh, we have all the information about this French company. So that's it. Here we conclude our series of building a globally company search engine. This episode was just like making improvements, making sure work. And, uh, I, this year all the best, uh, in, uh, real company information in your applications. Goodbye.
0