diff --git a/backend/src/main/java/com/kurttekin/can/job_track/application/JobApplicationServiceImpl.java b/backend/src/main/java/com/kurttekin/can/job_track/application/JobApplicationServiceImpl.java index e22f9b814..3b024e8e0 100644 --- a/backend/src/main/java/com/kurttekin/can/job_track/application/JobApplicationServiceImpl.java +++ b/backend/src/main/java/com/kurttekin/can/job_track/application/JobApplicationServiceImpl.java @@ -41,6 +41,11 @@ public Optional findById(Long id) { @Override public JobApplication updateJobApplication(JobApplication jobApplication) { + // Check if the job application exists + jobApplicationRepository.findById(jobApplication.getId()) + .orElseThrow(() -> new JobApplicationNotFoundException("Job Application not found")); + + // If it exists, save and return the updated application return jobApplicationRepository.save(jobApplication); } @@ -51,9 +56,10 @@ public void deleteJobApplication(Long id) { .orElseThrow(() -> new JobApplicationNotFoundException("Job Application not found for ID: " + id)); // If found, proceed with deletion - jobApplicationRepository.delete(jobApplication); + jobApplicationRepository.deleteById(id); } + @Override public void deleteAllByUserId(Long userId) { jobApplicationRepository.deleteByUserId(userId); @@ -64,6 +70,9 @@ public Map getJobApplicationStats(Long userId) { Map stats = new HashMap<>(); List applications = jobApplicationRepository.findByUserId(userId); + + stats.put("totalApplications", applications.size()); + for (JobApplication application : applications) { String date = application.getApplicationDate().toString(); stats.put(date, stats.getOrDefault(date, 0) + 1); // Increment the count for the date