Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 2.O #47

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.masai.entity.TripBooking;
import com.masai.service.AdminService;
@RestController
@RequestMapping("/api/admin")
@RequestMapping("/admin")
public class AdminController {

@Autowired
Expand All @@ -38,11 +38,7 @@ public ResponseEntity<Admin> insertAdminHandler(@RequestBody Admin admin) {
return new ResponseEntity<Admin>(savedAdmin,HttpStatus.OK);
}

@GetMapping("/")
public Admin deleteMappingHandler1() {

return null;
}


@DeleteMapping("/{adminId}")
public ResponseEntity<Admin> deleteMappingHandler(@PathVariable("adminId") Integer adminId) {
Expand All @@ -57,8 +53,8 @@ public ResponseEntity<List<TripBooking>> getAllTripsHandler(@PathVariable("cust
return new ResponseEntity<List<TripBooking>>(trips,HttpStatus.OK);
}

@GetMapping("trips/{cab}")
public ResponseEntity<List<TripBooking>> getTripsDriverwiseHandler(@RequestBody Cab cab){
@GetMapping("/trips/driverwise")
public ResponseEntity<List<TripBooking>> getTripsDriverwiseHandler(){

List<TripBooking> trips= adminService.getTripsDriverwise();
return new ResponseEntity<List<TripBooking>>(trips,HttpStatus.OK);
Expand Down Expand Up @@ -87,8 +83,9 @@ public List<TripBooking> getTripsDatewiseHandler(){
}

@GetMapping("trips/{customerId}/{date}")
public List<TripBooking> getTripsDatewiseAndCustomerHandler(@PathVariable("customerId") Integer customerId, @PathVariable("date") LocalDate date){
List<TripBooking> list = adminService.getTripsDatewiseAndCustomer(customerId, date);
public List<TripBooking> getTripsDatewiseAndCustomerHandler(@PathVariable("customerId") Integer customerId, @PathVariable("date") String date){
LocalDate date1 = LocalDate.parse(date);
List<TripBooking> list = adminService.getTripsDatewiseAndCustomer(customerId, date1);
return list;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -20,7 +19,6 @@
import com.masai.service.CabService;

@RestController
@RequestMapping("/api")
public class CabController {

@Autowired
Expand All @@ -40,7 +38,7 @@ public ResponseEntity<Cab> updateCabHandler(@RequestParam Integer id,
}

@GetMapping("/cabs")
public ResponseEntity<List<String>> viewCabsHandler()
public ResponseEntity<List<String>> viewCabsHandler(@RequestBody String carType)
{

List<String> cabs = cService.viewCabsOfType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,6 +32,11 @@ public List<Customer> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
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;

import com.masai.entity.Driver;
import com.masai.service.DriverService;

@RestController
@RequestMapping("/api")
public class DriverController {
@Autowired
private DriverService dService;
Expand All @@ -45,14 +43,8 @@ public ResponseEntity<Driver> updateDriver(@RequestParam Integer id,
return new ResponseEntity<Driver>(driver,HttpStatus.ACCEPTED);
}
@DeleteMapping("/drivers/{id}")

public ResponseEntity<Driver> deleteDriverById(@PathVariable("id") Integer id) {
Driver driver=dService.deleteDriverById(id);
return new ResponseEntity<Driver>(driver,HttpStatus.ACCEPTED);




public String deleteDriverById(@PathVariable("id") Integer id) {
return dService.deleteDriverById(id);
}
@GetMapping("/topDrivers")
public ResponseEntity<List<Driver>> viewBestDrivers(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
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;

import com.masai.entity.CustomerDTO;
import com.masai.service.UserLogInImpl;

@RestController
@RequestMapping("/api")
public class LoginController {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@
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;
import com.masai.entity.TripBooking;
import com.masai.service.TripService;

@RestController
@RequestMapping("/api")
public class TripbookingController {

@Autowired
Expand All @@ -35,12 +34,12 @@ public TripBooking Add( @Valid @RequestBody TripBooking trip)
}

@GetMapping("/trips")
public List<TripBooking> getAlltrip()
public List<TripBooking> 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);
Expand All @@ -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);
Expand Down
11 changes: 5 additions & 6 deletions Cab_booking/src/main/java/com/masai/entity/Driver.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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")
Expand All @@ -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> tripBooking;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions Cab_booking/src/main/java/com/masai/repository/DriverDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import com.masai.entity.Driver;
@Repository
public interface DriverDao extends JpaRepository<Driver,Integer> {
@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<Driver> viewBestDriver();

// @Query("from Driver d where cab")
// public Optional<Driver> findByCabId(Integer cabId);
@Query("from Driver d where d.available=true")
public List<Driver> findByAvailable();
}
4 changes: 2 additions & 2 deletions Cab_booking/src/main/java/com/masai/repository/TripDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

@Repository
public interface TripDao extends JpaRepository<TripBooking,Integer> {
@Query("from TripBooking order by Customerid")
@Query("from TripBooking order by CustomerId")
public List<TripBooking> findByCustomeridAsce();
@Query("from TripBooking order by fromdate_time")
public List<TripBooking> findByFromdate_timeAsce();

@Query("from TripBooking where CustomerId=:customerId AND Fromdate_time=:date")
public List<TripBooking> 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<TripBooking> findByDriverAscs();
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ public List<TripBooking> getAllTrips(Integer customerid) throws AdminExceptions
@Override

public List<TripBooking> getTripsDriverwise() {

List<TripBooking> list = tripDao.findByDriverAscs();
System.out.println(list);
return list;


if(list.size() > 0)
return list;
else
throw new AdminExceptions("No trips found");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Driver> viewBestDriver()throws DriverNotFoundException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Driver> drivers= ddao.viewBestDriver();
List<Driver> 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);
Expand Down
3 changes: 1 addition & 2 deletions Cab_booking/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


#changing the server port
server.port=8888

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ 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)

# Functions of Admin, Cutomer, Driver
. 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, Customer, Driver
## Through admin we can :
1. Can Log in/Log out of the system.<br>
2. Admin can View/Edit/Delete taxis into the system.<br>
Expand Down