-
Notifications
You must be signed in to change notification settings - Fork 0
/
JobService.java
31 lines (25 loc) · 895 Bytes
/
JobService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class JobService {
@Autowired
private JobRepository jobRepository;
public List<Job> getAllJobs() {
return jobRepository.findAll();
}
public Job saveJob(Job job) {
return jobRepository.save(job);
}
public Job updateJob(String id, Job job) {
Job existingJob = jobRepository.findById(id).orElseThrow(() -> new RuntimeException("Job not found"));
existingJob.setTitle(job.getTitle());
existingJob.setDescription(job.getDescription());
existingJob.setLocation(job.getLocation());
existingJob.setCompany(job.getCompany());
return jobRepository.save(existingJob);
}
public void deleteJob(String id) {
jobRepository.deleteById(id);
}
}