Skip to content

Commit

Permalink
tests for JobApplicationService
Browse files Browse the repository at this point in the history
  • Loading branch information
cankurttekin committed Oct 15, 2024
1 parent caaacf1 commit e6f5edf
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public Optional<JobApplication> 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);
}

Expand All @@ -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);
Expand All @@ -64,6 +70,9 @@ public Map<String, Integer> getJobApplicationStats(Long userId) {
Map<String, Integer> stats = new HashMap<>();

List<JobApplication> 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
Expand Down

0 comments on commit e6f5edf

Please sign in to comment.