2024-09-25 11:03:47 +00:00
|
|
|
package de.szut.lf8_starter.project;
|
|
|
|
|
2024-10-02 07:04:08 +00:00
|
|
|
import de.szut.lf8_starter.exceptionHandling.ResourceNotFoundException;
|
2024-09-25 11:03:47 +00:00
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
2024-09-25 11:38:31 +00:00
|
|
|
import java.util.List;
|
2024-10-02 07:04:08 +00:00
|
|
|
import java.util.Optional;
|
2024-09-25 11:38:31 +00:00
|
|
|
|
2024-09-25 11:03:47 +00:00
|
|
|
@Service
|
|
|
|
public class ProjectService {
|
|
|
|
private final ProjectRepository projectRepository;
|
|
|
|
|
|
|
|
public ProjectService(ProjectRepository projectRepository) {
|
|
|
|
this.projectRepository = projectRepository;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ProjectEntity create(ProjectEntity projectEntity) {
|
|
|
|
return this.projectRepository.save(projectEntity);
|
|
|
|
}
|
2024-09-25 11:38:31 +00:00
|
|
|
|
|
|
|
public List<ProjectEntity> readAll() {
|
|
|
|
return this.projectRepository.findAll();
|
|
|
|
}
|
2024-10-02 07:04:08 +00:00
|
|
|
|
|
|
|
public ProjectEntity findById(Long id) {
|
|
|
|
Optional<ProjectEntity> articleEntity = projectRepository.findById(id);
|
|
|
|
|
|
|
|
if (articleEntity.isEmpty()) {
|
|
|
|
throw new ResourceNotFoundException("Project with id " + id + " not found");
|
|
|
|
}
|
|
|
|
|
|
|
|
return articleEntity.get();
|
|
|
|
}
|
2024-09-25 11:03:47 +00:00
|
|
|
}
|