Skip to content
Merged
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
@@ -0,0 +1,40 @@
package com.pentagon.Quicky_Backend.controller;

import com.pentagon.Quicky_Backend.dto.DeliveriesCountDto;
import com.pentagon.Quicky_Backend.dto.DeliveryRecordsDto;
import com.pentagon.Quicky_Backend.dto.DriverProfilesDto;
import com.pentagon.Quicky_Backend.service.DeliveryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin(origins = "http://localhost:5173")
public class DeliveryController {

@Autowired
private DeliveryService deliveryService;

@GetMapping("/delivery_records")
public ResponseEntity<List<DeliveryRecordsDto>> getDeliveryRecords() {
List<DeliveryRecordsDto> deliveries = deliveryService.getDeliveryRecords();
return new ResponseEntity<>(deliveries, HttpStatus.OK);
}

@GetMapping("/deliveries_count")
public ResponseEntity<List<DeliveriesCountDto>> getDeliveriesCount() {
List<DeliveriesCountDto> deliveries = deliveryService.getDeliveriesCount();
return new ResponseEntity<>(deliveries, HttpStatus.OK);
}

@GetMapping("/delivery_records/today")
public ResponseEntity<List<DeliveryRecordsDto>> getDeliveryRecordsToday() {
List<DeliveryRecordsDto> deliveries = deliveryService.getDeliveryRecordsToday();
return new ResponseEntity<>(deliveries, HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.pentagon.Quicky_Backend.controller;

import com.pentagon.Quicky_Backend.dto.DriverLocationDto;
import com.pentagon.Quicky_Backend.service.DriverLocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "http://localhost:5173")
public class DriverLocationController {

@Autowired
private DriverLocationService driverLocationService;

@GetMapping("/search-driver-location/{userId}")
public ResponseEntity<List<DriverLocationDto>> getDriverLocation(@PathVariable Integer userId) {
List<DriverLocationDto> drivers = driverLocationService.getDriverLocation(userId);
return new ResponseEntity<>(drivers, HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.pentagon.Quicky_Backend.dto;

import java.time.LocalDate;

public interface DeliveriesCountDto {
LocalDate getDeliveryDate();
Long getDeliveriesCount();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.pentagon.Quicky_Backend.dto;

import java.time.LocalDate;

public interface DeliveryRecordsDto {
Long getDeliveryId();
Double getDeliveryFee();
String getPickupLocation();
String getDropOffLocation();
String getDeliveryStatus();
LocalDate getDeliveryDate();
String getFirstName();
String getLastName();
Double getRating();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.pentagon.Quicky_Backend.dto;

public interface DriverLocationDto {
Double getCurrentLatitude();
Double getCurrentLongitude();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.pentagon.Quicky_Backend.repository;

import com.pentagon.Quicky_Backend.dto.DeliveriesCountDto;
import com.pentagon.Quicky_Backend.dto.DeliveryRecordsDto;
import com.pentagon.Quicky_Backend.entity.DeliveryOrder;
import com.pentagon.Quicky_Backend.entity.DriverDetails;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface DeliveryRepo extends JpaRepository<DeliveryOrder, Integer> {

@Query(value = """
SELECT
d.delivery_id AS deliveryId,
d.delivery_fee AS deliveryFee,
d.pick_up_location AS pickupLocation,
d.drop_off_location AS dropOffLocation,
d.delivery_status AS deliveryStatus,
CAST(d.start_time AS DATE) AS deliveryDate,
dd.first_name AS firstName,
dd.last_name AS lastName,
r.rating_count AS rating
FROM delivery_order d
LEFT JOIN driver_details dd ON d.user_details_id = dd.user_details_id
LEFT JOIN rating r ON d.delivery_id = r.delivery_id
ORDER BY d.delivery_id DESC
""", nativeQuery = true)
List<DeliveryRecordsDto> getDeliveryRecords();

@Query(value = """
SELECT
CAST(d.start_time AS DATE) AS deliveryDate,
COUNT(d.delivery_id) AS deliveriesCount
FROM
delivery_order d
GROUP BY
CAST(d.start_time AS DATE)
ORDER BY
deliveryDate
""", nativeQuery = true)
List<DeliveriesCountDto> getDeliveriesCount();

@Query(value = """
SELECT
d.delivery_id AS deliveryId,
d.delivery_fee AS deliveryFee,
d.pick_up_location AS pickupLocation,
d.drop_off_location AS dropOffLocation,
d.delivery_status AS deliveryStatus,
CAST(d.start_time AS DATE) AS deliveryDate,
dd.first_name AS firstName,
dd.last_name AS lastName,
r.rating_count AS rating
FROM delivery_order d
LEFT JOIN driver_details dd ON d.user_details_id = dd.user_details_id
LEFT JOIN rating r ON d.delivery_id = r.delivery_id
WHERE CAST(d.start_time AS DATE) = CURRENT_DATE
ORDER BY d.delivery_id DESC
""", nativeQuery = true)
List<DeliveryRecordsDto> getDeliveryRecordsToday();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.pentagon.Quicky_Backend.repository;

import com.pentagon.Quicky_Backend.entity.DriverLocation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.data.jpa.repository.Query;
import com.pentagon.Quicky_Backend.dto.*;

import java.util.List;

@Repository
public interface DriverLocationRepo extends JpaRepository<DriverLocation, Integer> {

@Query(value = """
SELECT
dl.current_latitude AS currentLatitude,
dl.current_longitude AS currentLongitude
FROM driver_location dl
WHERE dl.user_id = :userId
ORDER BY dl.driver_location_id
""", nativeQuery = true)
List<DriverLocationDto> getDriverLocation(@Param("userId") Integer userId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.pentagon.Quicky_Backend.service;

import com.pentagon.Quicky_Backend.dto.DeliveriesCountDto;
import com.pentagon.Quicky_Backend.dto.DeliveryRecordsDto;
import com.pentagon.Quicky_Backend.repository.DeliveryRepo;
import com.pentagon.Quicky_Backend.repository.DriverDetailsRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeliveryService {

@Autowired
private DeliveryRepo deliveryRepo;

public List<DeliveryRecordsDto> getDeliveryRecords() {
return deliveryRepo.getDeliveryRecords();
}

public List<DeliveriesCountDto> getDeliveriesCount() {
return deliveryRepo.getDeliveriesCount();
}

public List<DeliveryRecordsDto> getDeliveryRecordsToday() {
return deliveryRepo.getDeliveryRecordsToday();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.pentagon.Quicky_Backend.service;

import com.pentagon.Quicky_Backend.dto.DriverLocationDto;
import com.pentagon.Quicky_Backend.repository.DriverLocationRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DriverLocationService {

@Autowired
private DriverLocationRepo driverLocationRepo;

public List<DriverLocationDto> getDriverLocation(Integer userId) {
return driverLocationRepo.getDriverLocation(userId);
}
}