feat: finished creating services from controllers, continued implementing entrepreneurServiceApi with some validation
Some checks failed
Format / formatting (push) Failing after 6s
CI / build (push) Successful in 11s

This commit is contained in:
Théo Le Lez
2025-02-26 17:35:52 +01:00
parent e75a5c9d2c
commit f9de5ed6bf
11 changed files with 219 additions and 125 deletions

View File

@ -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");
}