From 34ff1ed8c89e533965dd3a3e71a71295229847a8 Mon Sep 17 00:00:00 2001 From: Chova Ram Sinha <75615469+Ramcr32@users.noreply.github.com> Date: Fri, 19 Aug 2022 10:04:13 +0530 Subject: [PATCH 1/3] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f70d1d0..86f984b 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Admin can maintain a database of drivers. Drivers have to register on the portal # Cab Booking Application ER diagram ![cab_booking_3](https://user-images.githubusercontent.com/68966858/185020617-92914a9c-b5e2-4b3b-aa36-dc6a26454cba.jpeg) +. After running this program in spring boot we have to hit this url to see all the API's in swagger http://localhost:8888/swagger-ui.html#/ # Functions of Admin, Cutomer, Driver ## Through admin we can : 1. Can Log in/Log out of the system.
From 193cdb538d30728be11b1d4191520cf44009fd50 Mon Sep 17 00:00:00 2001 From: Chova Ram Sinha <75615469+Ramcr32@users.noreply.github.com> Date: Sun, 28 Aug 2022 11:57:31 +0530 Subject: [PATCH 2/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 86f984b..95fe898 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Admin can maintain a database of drivers. Drivers have to register on the portal ![cab_booking_3](https://user-images.githubusercontent.com/68966858/185020617-92914a9c-b5e2-4b3b-aa36-dc6a26454cba.jpeg) . After running this program in spring boot we have to hit this url to see all the API's in swagger http://localhost:8888/swagger-ui.html#/ -# Functions of Admin, Cutomer, Driver +# Functions of Admin, Customer, Driver ## Through admin we can : 1. Can Log in/Log out of the system.
2. Admin can View/Edit/Delete taxis into the system.
From ed5b72f9811437b29e071c6f23988af93fd6a78d Mon Sep 17 00:00:00 2001 From: Ram Date: Sun, 28 Aug 2022 20:27:45 +0530 Subject: [PATCH 3/3] start version 2.O --- .../com/masai/controller/AdminController.java | 17 +++++++---------- .../com/masai/controller/CabController.java | 4 +--- .../masai/controller/CustomerController.java | 7 +++++-- .../com/masai/controller/DriverController.java | 12 ++---------- .../com/masai/controller/LoginController.java | 2 -- .../masai/controller/TripbookingController.java | 9 ++++----- .../src/main/java/com/masai/entity/Driver.java | 11 +++++------ .../main/java/com/masai/entity/TripBooking.java | 2 +- .../java/com/masai/repository/DriverDao.java | 6 +++--- .../main/java/com/masai/repository/TripDao.java | 4 ++-- .../java/com/masai/service/AdminServiceImp.java | 9 ++++++--- .../java/com/masai/service/DriverService.java | 2 +- .../com/masai/service/DriverServiceImpl.java | 8 ++++---- .../java/com/masai/service/TripServiceImp.java | 6 ++++-- .../src/main/resources/application.properties | 3 +-- 15 files changed, 46 insertions(+), 56 deletions(-) diff --git a/Cab_booking/src/main/java/com/masai/controller/AdminController.java b/Cab_booking/src/main/java/com/masai/controller/AdminController.java index 36d4d2d..e3647ac 100644 --- a/Cab_booking/src/main/java/com/masai/controller/AdminController.java +++ b/Cab_booking/src/main/java/com/masai/controller/AdminController.java @@ -26,7 +26,7 @@ import com.masai.entity.TripBooking; import com.masai.service.AdminService; @RestController -@RequestMapping("/api/admin") +@RequestMapping("/admin") public class AdminController { @Autowired @@ -38,11 +38,7 @@ public ResponseEntity insertAdminHandler(@RequestBody Admin admin) { return new ResponseEntity(savedAdmin,HttpStatus.OK); } - @GetMapping("/") - public Admin deleteMappingHandler1() { - - return null; - } + @DeleteMapping("/{adminId}") public ResponseEntity deleteMappingHandler(@PathVariable("adminId") Integer adminId) { @@ -57,8 +53,8 @@ public ResponseEntity> getAllTripsHandler(@PathVariable("cust return new ResponseEntity>(trips,HttpStatus.OK); } - @GetMapping("trips/{cab}") - public ResponseEntity> getTripsDriverwiseHandler(@RequestBody Cab cab){ + @GetMapping("/trips/driverwise") + public ResponseEntity> getTripsDriverwiseHandler(){ List trips= adminService.getTripsDriverwise(); return new ResponseEntity>(trips,HttpStatus.OK); @@ -87,8 +83,9 @@ public List getTripsDatewiseHandler(){ } @GetMapping("trips/{customerId}/{date}") - public List getTripsDatewiseAndCustomerHandler(@PathVariable("customerId") Integer customerId, @PathVariable("date") LocalDate date){ - List list = adminService.getTripsDatewiseAndCustomer(customerId, date); + public List getTripsDatewiseAndCustomerHandler(@PathVariable("customerId") Integer customerId, @PathVariable("date") String date){ + LocalDate date1 = LocalDate.parse(date); + List list = adminService.getTripsDatewiseAndCustomer(customerId, date1); return list; } diff --git a/Cab_booking/src/main/java/com/masai/controller/CabController.java b/Cab_booking/src/main/java/com/masai/controller/CabController.java index 86e28e6..195e239 100644 --- a/Cab_booking/src/main/java/com/masai/controller/CabController.java +++ b/Cab_booking/src/main/java/com/masai/controller/CabController.java @@ -11,7 +11,6 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -20,7 +19,6 @@ import com.masai.service.CabService; @RestController -@RequestMapping("/api") public class CabController { @Autowired @@ -40,7 +38,7 @@ public ResponseEntity updateCabHandler(@RequestParam Integer id, } @GetMapping("/cabs") - public ResponseEntity> viewCabsHandler() + public ResponseEntity> viewCabsHandler(@RequestBody String carType) { List cabs = cService.viewCabsOfType(); diff --git a/Cab_booking/src/main/java/com/masai/controller/CustomerController.java b/Cab_booking/src/main/java/com/masai/controller/CustomerController.java index 630c074..7743ade 100644 --- a/Cab_booking/src/main/java/com/masai/controller/CustomerController.java +++ b/Cab_booking/src/main/java/com/masai/controller/CustomerController.java @@ -11,14 +11,12 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.masai.service.CustomerService; import com.masai.entity.Customer; @RestController -@RequestMapping("/api") public class CustomerController { @Autowired @@ -34,6 +32,11 @@ public List getAllCustomer() { return service.allCustomer(); } + @GetMapping("/customer/{Email}/{Password}") + public Customer getAllCustomer(@PathVariable("Email") String Email,@PathVariable("Password")String Password) + { + return service.vaildCustomer(Email, Password); + } @PostMapping(value = "/save",consumes = "application/json") public Customer SaveStudent(@Valid @RequestBody Customer customer) diff --git a/Cab_booking/src/main/java/com/masai/controller/DriverController.java b/Cab_booking/src/main/java/com/masai/controller/DriverController.java index e43a4a4..1027b7e 100644 --- a/Cab_booking/src/main/java/com/masai/controller/DriverController.java +++ b/Cab_booking/src/main/java/com/masai/controller/DriverController.java @@ -14,7 +14,6 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -22,7 +21,6 @@ import com.masai.service.DriverService; @RestController -@RequestMapping("/api") public class DriverController { @Autowired private DriverService dService; @@ -45,14 +43,8 @@ public ResponseEntity updateDriver(@RequestParam Integer id, return new ResponseEntity(driver,HttpStatus.ACCEPTED); } @DeleteMapping("/drivers/{id}") - -public ResponseEntity deleteDriverById(@PathVariable("id") Integer id) { - Driver driver=dService.deleteDriverById(id); - return new ResponseEntity(driver,HttpStatus.ACCEPTED); - - - - +public String deleteDriverById(@PathVariable("id") Integer id) { + return dService.deleteDriverById(id); } @GetMapping("/topDrivers") public ResponseEntity> viewBestDrivers(){ diff --git a/Cab_booking/src/main/java/com/masai/controller/LoginController.java b/Cab_booking/src/main/java/com/masai/controller/LoginController.java index 16ee632..f9afbe7 100644 --- a/Cab_booking/src/main/java/com/masai/controller/LoginController.java +++ b/Cab_booking/src/main/java/com/masai/controller/LoginController.java @@ -6,7 +6,6 @@ import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -14,7 +13,6 @@ import com.masai.service.UserLogInImpl; @RestController -@RequestMapping("/api") public class LoginController { @Autowired diff --git a/Cab_booking/src/main/java/com/masai/controller/TripbookingController.java b/Cab_booking/src/main/java/com/masai/controller/TripbookingController.java index a9ee654..d07f0b4 100644 --- a/Cab_booking/src/main/java/com/masai/controller/TripbookingController.java +++ b/Cab_booking/src/main/java/com/masai/controller/TripbookingController.java @@ -9,11 +9,11 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.masai.entity.Customer; @@ -21,7 +21,6 @@ import com.masai.service.TripService; @RestController -@RequestMapping("/api") public class TripbookingController { @Autowired @@ -35,12 +34,12 @@ public TripBooking Add( @Valid @RequestBody TripBooking trip) } @GetMapping("/trips") - public List getAlltrip() + public List getAllCustomer() { return service.alltrip() ; } @PutMapping("/tripupdate/{id}") - public TripBooking updatetrip(@Valid @RequestBody TripBooking trip,@PathVariable("id")Integer id) + public TripBooking updateStudent(@Valid @RequestBody TripBooking trip,@PathVariable("id")Integer id) { return service.updateTrip(trip,id); @@ -50,7 +49,7 @@ public String delete(@PathVariable("id")Integer id) { return service.deletetrip(id); } - @GetMapping("/tripend/{id}") + @PatchMapping("/tripend/{id}") public TripBooking end(@PathVariable("id")Integer id) { return service.tripEnd(id); diff --git a/Cab_booking/src/main/java/com/masai/entity/Driver.java b/Cab_booking/src/main/java/com/masai/entity/Driver.java index e0964a9..75cddc1 100644 --- a/Cab_booking/src/main/java/com/masai/entity/Driver.java +++ b/Cab_booking/src/main/java/com/masai/entity/Driver.java @@ -1,9 +1,12 @@ package com.masai.entity; +import java.util.List; + import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.PrimaryKeyJoinColumn; import javax.validation.constraints.Min; @@ -25,10 +28,6 @@ public class Driver extends Abstractuser { - @NotNull - @Min(value=1, message="id should be more than 1") - @PrimaryKeyJoinColumn(name="driverID") - @Min(value=1, message="id should be more than 1") private Integer licenseNo; @Min(value=1, message="id should be more than 1") @@ -40,8 +39,8 @@ public class Driver extends Abstractuser { private Cab cab; -@OneToOne(cascade = CascadeType.ALL,mappedBy = "driver",orphanRemoval = true) +@OneToMany(cascade = CascadeType.ALL,mappedBy = "driver",orphanRemoval = true) @JsonIgnore -private TripBooking tripBooking; +private List tripBooking; } diff --git a/Cab_booking/src/main/java/com/masai/entity/TripBooking.java b/Cab_booking/src/main/java/com/masai/entity/TripBooking.java index d09274b..7828afc 100644 --- a/Cab_booking/src/main/java/com/masai/entity/TripBooking.java +++ b/Cab_booking/src/main/java/com/masai/entity/TripBooking.java @@ -40,7 +40,7 @@ public class TripBooking { @NonNull private Integer CustomerId; - @OneToOne(cascade=CascadeType.ALL) + @ManyToOne(cascade=CascadeType.ALL) @JoinColumn(name="driver_id",referencedColumnName = "driverID") private Driver driver; diff --git a/Cab_booking/src/main/java/com/masai/repository/DriverDao.java b/Cab_booking/src/main/java/com/masai/repository/DriverDao.java index 3cae7cb..98bc02a 100644 --- a/Cab_booking/src/main/java/com/masai/repository/DriverDao.java +++ b/Cab_booking/src/main/java/com/masai/repository/DriverDao.java @@ -10,9 +10,9 @@ import com.masai.entity.Driver; @Repository public interface DriverDao extends JpaRepository { - @Query("from Driver d where d.rating>=4.5 AND d.available=true") + @Query("from Driver d where d.rating>=4.5 AND d.available='true'") public List viewBestDriver(); -// @Query("from Driver d where cab") -// public Optional findByCabId(Integer cabId); + @Query("from Driver d where d.available=true") + public List findByAvailable(); } diff --git a/Cab_booking/src/main/java/com/masai/repository/TripDao.java b/Cab_booking/src/main/java/com/masai/repository/TripDao.java index 4812e3c..0f93700 100644 --- a/Cab_booking/src/main/java/com/masai/repository/TripDao.java +++ b/Cab_booking/src/main/java/com/masai/repository/TripDao.java @@ -12,7 +12,7 @@ @Repository public interface TripDao extends JpaRepository { - @Query("from TripBooking order by Customerid") + @Query("from TripBooking order by CustomerId") public List findByCustomeridAsce(); @Query("from TripBooking order by fromdate_time") public List findByFromdate_timeAsce(); @@ -20,6 +20,6 @@ public interface TripDao extends JpaRepository { @Query("from TripBooking where CustomerId=:customerId AND Fromdate_time=:date") public List findByCustomerIdAndFromdate_time(Integer customerId, LocalDate date); - @Query("from TripBooking Group by DriverId") + @Query("from TripBooking Group by driver_id ORDER by driver_id") public List findByDriverAscs(); } diff --git a/Cab_booking/src/main/java/com/masai/service/AdminServiceImp.java b/Cab_booking/src/main/java/com/masai/service/AdminServiceImp.java index 60464be..8065b07 100644 --- a/Cab_booking/src/main/java/com/masai/service/AdminServiceImp.java +++ b/Cab_booking/src/main/java/com/masai/service/AdminServiceImp.java @@ -78,10 +78,13 @@ public List getAllTrips(Integer customerid) throws AdminExceptions @Override public List getTripsDriverwise() { + List list = tripDao.findByDriverAscs(); - System.out.println(list); - return list; - + + if(list.size() > 0) + return list; + else + throw new AdminExceptions("No trips found"); } diff --git a/Cab_booking/src/main/java/com/masai/service/DriverService.java b/Cab_booking/src/main/java/com/masai/service/DriverService.java index 215743a..6c625e9 100644 --- a/Cab_booking/src/main/java/com/masai/service/DriverService.java +++ b/Cab_booking/src/main/java/com/masai/service/DriverService.java @@ -10,6 +10,6 @@ public interface DriverService { public Driver insertDriver(Driver driver); public Driver viewDriverById(Integer id) throws InvalidId; public Driver updateDriver(Integer id,Integer license, Boolean available)throws DriverNotFoundException; -public Driver deleteDriverById(Integer id)throws DriverNotFoundException; +public String deleteDriverById(Integer id)throws DriverNotFoundException; public List viewBestDriver()throws DriverNotFoundException; } diff --git a/Cab_booking/src/main/java/com/masai/service/DriverServiceImpl.java b/Cab_booking/src/main/java/com/masai/service/DriverServiceImpl.java index 660b0b4..25a8dfd 100644 --- a/Cab_booking/src/main/java/com/masai/service/DriverServiceImpl.java +++ b/Cab_booking/src/main/java/com/masai/service/DriverServiceImpl.java @@ -26,8 +26,7 @@ public class DriverServiceImpl implements DriverService { @Override public Driver insertDriver(Driver driver) { - Cab cab= driver.getCab(); - cDao.save(cab); + return dDao.save(driver); } @@ -62,14 +61,15 @@ public Driver updateDriver(Integer id,Integer license, Boolean available) throws @Override - public Driver deleteDriverById(Integer id) throws DriverNotFoundException{ + public String deleteDriverById(Integer id) throws DriverNotFoundException{ Driver d1=dDao.findById(id).orElseThrow(()-> new DriverNotFoundException("No Driver found")); cDao.deleteById(d1.getCab().getCabId()); Adao.delete(d1.getAddress()); dDao.delete(d1); - return d1; + + return "Driver Id "+id+ " deleted "; } @Override diff --git a/Cab_booking/src/main/java/com/masai/service/TripServiceImp.java b/Cab_booking/src/main/java/com/masai/service/TripServiceImp.java index b4c9086..03db477 100644 --- a/Cab_booking/src/main/java/com/masai/service/TripServiceImp.java +++ b/Cab_booking/src/main/java/com/masai/service/TripServiceImp.java @@ -27,13 +27,15 @@ public class TripServiceImp implements TripService { public TripBooking AddTrip(TripBooking tb) throws InvalidId { cdao.findById(tb.getCustomerId()).orElseThrow(() -> new InvalidId("Customer with ID "+tb.getCustomerId()+" does not exit..")); - List drivers= ddao.viewBestDriver(); + List drivers= ddao.findByAvailable() ; if(drivers.size()==0) { throw new DriverNotFoundException("Sorry No driver Available just now..."); } +// drivers.forEach((e)->System.out.println(e.getUserId())); +// System.out.println(drivers.size()); drivers.get(0).setAvailable(false); - + ddao.save(drivers.get(0)); Integer km = tb.getKm(); Integer price=drivers.get(0).getCab().getRatePerKm(); tb.setTotalamount(km*price); diff --git a/Cab_booking/src/main/resources/application.properties b/Cab_booking/src/main/resources/application.properties index 6f7d839..9436b5f 100644 --- a/Cab_booking/src/main/resources/application.properties +++ b/Cab_booking/src/main/resources/application.properties @@ -1,5 +1,4 @@ - #changing the server port server.port=8888 @@ -9,7 +8,7 @@ spring.datasource.url=jdbc:mysql://localhost:3306/sb201db spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.username=root -spring.datasource.password=goosebumps7 +spring.datasource.password=ramsinha@32 #ORM s/w specific properties spring.jpa.hibernate.ddl-auto=update