Skip to content
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
@@ -1,5 +1,31 @@
package com.example.ead_backend.controller;

import com.example.ead_backend.dto.AppointmentDTO;
import com.example.ead_backend.service.DashboardService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/appointments")
@CrossOrigin(origins = "*")
@RequiredArgsConstructor
public class AppointmentController {

private final DashboardService dashboardService;

@GetMapping("/customer/{customerId}")
public ResponseEntity<List<AppointmentDTO>> getCustomerAppointments(@PathVariable Long customerId) {
// This returns all appointments for the customer
List<AppointmentDTO> appointments = dashboardService.getAllAppointments(customerId);
return ResponseEntity.ok(appointments);
}

@DeleteMapping("/{appointmentId}")
public ResponseEntity<String> deleteAppointment(@PathVariable String appointmentId) {
// TODO: Implement delete appointment logic
return ResponseEntity.ok("Appointment deleted successfully");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.example.ead_backend.controller;

import com.example.ead_backend.dto.AppointmentDTO;
import com.example.ead_backend.dto.CustomerDTO;
import com.example.ead_backend.dto.DashboardStatsDTO;
import com.example.ead_backend.dto.ProjectDTO;
import com.example.ead_backend.service.DashboardService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/dashboard")
@CrossOrigin(origins = "*")
@RequiredArgsConstructor
public class DashboardController {

private final DashboardService dashboardService;

@GetMapping("/stats/{customerId}")
public ResponseEntity<DashboardStatsDTO> getDashboardStats(@PathVariable Long customerId) {
DashboardStatsDTO stats = dashboardService.getDashboardStats(customerId);
return ResponseEntity.ok(stats);
}

@GetMapping("/profile/{customerId}")
public ResponseEntity<CustomerDTO> getCustomerProfile(@PathVariable Long customerId) {
CustomerDTO customer = dashboardService.getCustomerProfile(customerId);
return ResponseEntity.ok(customer);
}

@GetMapping("/appointments/upcoming/{customerId}")
public ResponseEntity<List<AppointmentDTO>> getUpcomingAppointments(@PathVariable Long customerId) {
List<AppointmentDTO> appointments = dashboardService.getUpcomingAppointments(customerId);
return ResponseEntity.ok(appointments);
}

@GetMapping("/projects/ongoing/{customerId}")
public ResponseEntity<List<ProjectDTO>> getOngoingProjects(@PathVariable Long customerId) {
List<ProjectDTO> projects = dashboardService.getOngoingProjects(customerId);
return ResponseEntity.ok(projects);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
package com.example.ead_backend.controller;

import com.example.ead_backend.dto.ProjectDTO;
import com.example.ead_backend.service.DashboardService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/projects")
@CrossOrigin(origins = "*")
@RequiredArgsConstructor
public class ProjectController {

private final DashboardService dashboardService;

@GetMapping("/customer/{customerId}")
public ResponseEntity<List<ProjectDTO>> getCustomerProjects(@PathVariable Long customerId) {
// This returns all projects for the customer
List<ProjectDTO> projects = dashboardService.getAllProjects(customerId);
return ResponseEntity.ok(projects);
}

@GetMapping("/customer/{customerId}/completed")
public ResponseEntity<List<ProjectDTO>> getCompletedProjects(@PathVariable Long customerId) {
List<ProjectDTO> projects = dashboardService.getCompletedProjects(customerId);
return ResponseEntity.ok(projects);
}

@DeleteMapping("/{projectId}")
public ResponseEntity<String> deleteProject(@PathVariable String projectId) {
// TODO: Implement delete project logic
return ResponseEntity.ok("Project deleted successfully");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public ResponseEntity<?> createVehicleWithImage(
}

@GetMapping("/{id}")
public VehicleDTO getVehicleById(@PathVariable String id) {
public VehicleDTO getVehicleById(@PathVariable Long id) {
return vehicleService.getVehicleById(id);
}

Expand All @@ -64,7 +64,7 @@ public List<VehicleDTO> getVehiclesByCustomerId(@PathVariable Long customerId) {
}

@PutMapping("/{id}")
public VehicleDTO updateVehicle(@PathVariable String id, @RequestBody VehicleDTO vehicleDTO) {
public VehicleDTO updateVehicle(@PathVariable Long id, @RequestBody VehicleDTO vehicleDTO) {
return vehicleService.updateVehicle(id, vehicleDTO);
}

Expand Down
28 changes: 27 additions & 1 deletion src/main/java/com/example/ead_backend/dto/AppointmentDTO.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
package com.example.ead_backend.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class AppointmentDTO {

private String id;
private Long customerId;
private String customerName;
private Long vehicleId;
private String vehicleNumber;
private String vehicleModel;
private Long employeeId;
private String employeeName;
private LocalDateTime appointmentTime;
private String status;
private List<String> tasks;
private String serviceName;
private String customerNotes;
private Integer estimatedDurationMinutes;
private LocalDateTime createdAt;
}
18 changes: 17 additions & 1 deletion src/main/java/com/example/ead_backend/dto/CustomerDTO.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
package com.example.ead_backend.dto;

public class CustomerDTO {
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CustomerDTO {
private Long id;
private String name;
private String email;
private String phoneNumber;
private String address;
private LocalDateTime createdAt;
}
16 changes: 16 additions & 0 deletions src/main/java/com/example/ead_backend/dto/DashboardStatsDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.example.ead_backend.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class DashboardStatsDTO {
private Integer totalVehicles;
private Integer upcomingAppointments;
private Integer ongoingProjects;
}
36 changes: 35 additions & 1 deletion src/main/java/com/example/ead_backend/dto/ProjectDTO.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
package com.example.ead_backend.dto;

public class ProjectDTO {
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ProjectDTO {
private String id;
private Long customerId;
private String customerName;
private Long vehicleId;
private String vehicleNumber;
private String vehicleModel;
private String vehicleType;
private Long employeeId;
private String employeeName;
private String assignedEmployee;
private String serviceDescription;
private String taskName;
private String description;
private String status;
private String adminNotes;
private String employeeNotes;
private Double estimatedCost;
private Integer estimatedDurationDays;
private LocalDateTime startDate;
private String time;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
private LocalDateTime assignedAt;
private LocalDateTime completedAt;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public class AppointmentMapper {
public AppointmentResponse toResponse(Appointment appointment) {
AppointmentResponse response = new AppointmentResponse();
response.setAppointmentId(appointment.getAppointmentId());
response.setCustomerName(appointment.getCustomer().getFirstName() + " " +
appointment.getCustomer().getLastName());
response.setCustomerId(appointment.getCustomer().getCustomerId());
response.setCustomerName(appointment.getCustomer().getUser().getFirstName() + " " +
appointment.getCustomer().getUser().getLastName());
response.setCustomerId(String.valueOf(appointment.getCustomer().getId()));

if (appointment.getVehicle() != null) {
response.setVehicleMake(appointment.getVehicle().getMake());
Expand All @@ -21,9 +21,9 @@ public AppointmentResponse toResponse(Appointment appointment) {
}

if (appointment.getEmployee() != null) {
response.setEmployeeName(appointment.getEmployee().getFirstName() + " " +
appointment.getEmployee().getLastName());
response.setEmployeeId(appointment.getEmployee().getEmployeeId());
response.setEmployeeName(appointment.getEmployee().getUser().getFirstName() + " " +
appointment.getEmployee().getUser().getLastName());
response.setEmployeeId(String.valueOf(appointment.getEmployee().getId()));
}

response.setAppointmentTime(appointment.getAppointmentTime());
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/example/ead_backend/mapper/ProjectMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public class ProjectMapper {
public ProjectResponse toResponse(Project project) {
ProjectResponse response = new ProjectResponse();
response.setProjectId(project.getProjectId());
response.setCustomerName(project.getCustomer().getFirstName() + " " +
project.getCustomer().getLastName());
response.setCustomerId(project.getCustomer().getCustomerId());
response.setCustomerName(project.getCustomer().getUser().getFirstName() + " " +
project.getCustomer().getUser().getLastName());
response.setCustomerId(String.valueOf(project.getCustomer().getId()));

if (project.getVehicle() != null) {
response.setVehicleMake(project.getVehicle().getMake());
Expand All @@ -23,9 +23,9 @@ public ProjectResponse toResponse(Project project) {
response.setServiceDescription(project.getServiceDescription());

if (project.getEmployee() != null) {
response.setEmployeeName(project.getEmployee().getFirstName() + " " +
project.getEmployee().getLastName());
response.setEmployeeId(project.getEmployee().getEmployeeId());
response.setEmployeeName(project.getEmployee().getUser().getFirstName() + " " +
project.getEmployee().getUser().getLastName());
response.setEmployeeId(String.valueOf(project.getEmployee().getId()));
}

response.setStatus(project.getStatus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
public interface VehicleMapper {
VehicleMapper INSTANCE = Mappers.getMapper(VehicleMapper.class);

@Mapping(source = "customer.id", target = "customerId")
@Mapping(source = "owner.id", target = "customerId")
VehicleDTO toDTO(Vehicle vehicle);

@Mapping(target = "customer", ignore = true)
@Mapping(target = "owner", ignore = true)
@Mapping(target = "imagePublicId", ignore = true)
Vehicle toEntity(VehicleDTO dto);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Vehicle {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "customer_id", nullable = false)
private Customer customer;
private Customer owner;

@Column(nullable = false)
private String model;
Expand All @@ -37,10 +37,6 @@ public class Vehicle {

@Column(nullable = false)
private int year;

@ManyToOne
@JoinColumn(name = "customer_id", nullable = false)
private Customer owner;

@Column(length = 500)
private String imageUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
public interface AppointmentRepository extends JpaRepository<Appointment, String> {

// Find appointments by customer
List<Appointment> findByCustomer_CustomerId(String customerId);
List<Appointment> findByCustomer_Id(Long customerId);

// Find appointments by employee
List<Appointment> findByEmployee_EmployeeId(String employeeId);
List<Appointment> findByEmployee_Id(Long employeeId);

// Find appointments by status
List<Appointment> findByStatus(AppointmentStatus status);
Expand All @@ -33,9 +33,9 @@ List<Appointment> findByDateRange(@Param("startDate") LocalDateTime startDate,
List<Appointment> findConflictingAppointments(@Param("appointmentTime") LocalDateTime appointmentTime);

// Find employee appointments at specific time
@Query("SELECT a FROM Appointment a WHERE a.employee.employeeId = :employeeId " +
@Query("SELECT a FROM Appointment a WHERE a.employee.id = :employeeId " +
"AND a.appointmentTime = :appointmentTime " +
"AND a.status IN ('CONFIRMED', 'IN_PROGRESS')")
List<Appointment> findEmployeeAppointmentsAtTime(@Param("employeeId") String employeeId,
List<Appointment> findEmployeeAppointmentsAtTime(@Param("employeeId") Long employeeId,
@Param("appointmentTime") LocalDateTime appointmentTime);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@
import java.util.Optional;

@Repository
public interface CustomerRepository extends JpaRepository<Customer, String> {
Optional<Customer> findByEmail(String email);
boolean existsByEmail(String email);

public interface CustomerRepository extends JpaRepository<Customer, Long> {
Optional<Customer> findByUser(User user);
Optional<Customer> findByUserId(Long userId);
Optional<Customer> findByEmail(String email);
boolean existsByEmail(String email);
Optional<Customer> findByUserEmail(String email);
boolean existsByUserEmail(String email);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;


import java.util.List;
import java.util.Optional;

@Repository
public interface EmployeeRepository extends JpaRepository<Employee, Long> {
Optional<Employee> findByUser(User user);
Optional<Employee> findByUserId(Long userId);
Optional<Employee> findByEmail(String email);
Optional<Employee> findByUserEmail(String email);
List<Employee> findByIsAvailable(boolean isAvailable);

}
Loading