feat: finished creating services from controllers, continued implementing entrepreneurServiceApi with some validation
This commit is contained in:
@ -4,9 +4,10 @@ import enseirb.myinpulse.model.Entrepreneur;
|
||||
import enseirb.myinpulse.model.Project;
|
||||
import enseirb.myinpulse.repository.EntrepreneurRepository;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.util.Optional;
|
||||
@ -14,6 +15,8 @@ import java.util.Optional;
|
||||
@Service
|
||||
public class EntrepreneurService {
|
||||
|
||||
protected static final Logger logger = LogManager.getLogger();
|
||||
|
||||
private final EntrepreneurRepository entrepreneurRepository;
|
||||
|
||||
EntrepreneurService(EntrepreneurRepository entrepreneurRepository) {
|
||||
@ -27,6 +30,7 @@ public class EntrepreneurService {
|
||||
public Entrepreneur getEntrepreneurById(Long id) {
|
||||
Optional<Entrepreneur> entrepreneur = entrepreneurRepository.findById(id);
|
||||
if (entrepreneur.isEmpty()) {
|
||||
logger.error("getEntrepreneurById : No entrepreneur found with id {}", id);
|
||||
throw new ResponseStatusException(
|
||||
HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas");
|
||||
}
|
||||
@ -41,6 +45,7 @@ public class EntrepreneurService {
|
||||
Long id, String school, String course, Boolean sneeStatus) {
|
||||
Optional<Entrepreneur> entrepreneur = entrepreneurRepository.findById(id);
|
||||
if (entrepreneur.isEmpty()) {
|
||||
logger.error("updateEntrepreneur : No entrepreneur found with id {}", id);
|
||||
throw new ResponseStatusException(
|
||||
HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas");
|
||||
}
|
||||
|
Reference in New Issue
Block a user