Table of contents
No headings in the article.
The 1st service that we are going to straightaway target is going to be our flight search service. where we will not just be able to create flights but also search flights. We can filter them based on multiple criteria's.
The aircraft that is actually used can be common in multiple flights.
We already have an airplane model. Let's prepare the whole CRUD for airplane model. We already have it.
Then let's prepare a bunch of CRUD api's for city & airport model.
For city even we don't need CRUD. City can be handled using seeds because once you add the cities it's done & dusted. Still we will be making a bunch of CRUD api's but you can use seeds as lot of things are going to be redundant. Same goes for airport too.
In the flights table we will talk about Sequelize capabilitites.
Inside our CRUD repository, we refactored our create function for that error handling mechanism. Maybe we can do that in destory as well.
In service we will be handling a bunch of stuff. So we can remove try catch statements. We will do error handling in the airplane-service.
Let's say I want to write an API. You just need to focus on our repository layer & the controller & the service.
We just write a service function, getAirPlanes() & did a module.export.
Will go to my controller then. Whatever is the error object returned by our service, we will attach that & inside error object we will be having a status code also.
Now v1/airplane-routes
. If somebody does a post request we will create one.
If somebody does with id:100. There's no id 100.
We sent an Get request to get airplane with a specific id. We are getting response as successful even when it shouldn't be as in when we send an invalid id.
When a copy of the webpage is sent from the web server to your browser, each line of code is processed in sequential order from first to last. As each line is interpreted, the browser creates the building blocks, which is the visual representation you see on the screen. This creation process is known as page rendering.
We completed a complete REST API for 1 of our resource. Let's start 1 more resource. Now I want to add a city resource.
If you want to add a city resource then there would be a city table. If there would be city table we need to create some migrations.
To get a new model & migration npx sequelize model:generate --name City --attributes name:string
To make a mysql table npx sequelize db:migrate
Now we will create CRUD API's for City
Create a repository
Now create a service
Now controller
Now let's go to v1 routes & create a new route.
We will do a middleware just so that req doesn't go too deep 7 returns back in case of error.
Show off- "uski complexity batakr , usmein kya cheezein handle kri hein wo batakr, kya specific feature likhe hein wo batakr, feature likhoge & github pe project expose karoge"