feat: added color in logs
All checks were successful
Format / formatting (push) Successful in 6s
CI / build (push) Successful in 11s

This commit is contained in:
Pierre Tellier
2025-02-26 15:29:55 +01:00
parent 3890aed158
commit 1a6db7c953
3 changed files with 1 additions and 14 deletions

View File

@ -0,0 +1,58 @@
package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services;
import enseirb.myinpulse.model.Entrepreneur;
import enseirb.myinpulse.repository.EntrepreneurRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;
import java.util.Optional;
@RestController
public class EntrepreneurController {
@Autowired EntrepreneurRepository entrepreneurRepository;
@GetMapping("/Entrepreneur")
@ResponseBody
public Iterable<Entrepreneur> allEntrepreneurs() {
return this.entrepreneurRepository.findAll();
}
@GetMapping("/Entrepreneur/{id}")
public Entrepreneur getEntrepreneurById(@PathVariable Long id) {
Optional<Entrepreneur> entrepreneur = entrepreneurRepository.findById(id);
if (entrepreneur.isEmpty()) {
throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas");
}
return entrepreneur.get();
}
@PostMapping("/Entrepreneur")
public Entrepreneur addEntrepreneur(@RequestBody Entrepreneur entrepreneur) {
return this.entrepreneurRepository.save(entrepreneur);
}
@PostMapping("/Entrepreneur/{id}")
public Entrepreneur updateEntrepreneur(
@PathVariable Long id, String school, String course, Boolean sneeStatus) {
Optional<Entrepreneur> entrepreneur = entrepreneurRepository.findById(id);
if (entrepreneur.isEmpty()) {
throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas");
}
if (school != null) {
entrepreneur.get().setSchool(school);
}
if (course != null) {
entrepreneur.get().setCourse(course);
}
if (sneeStatus != null) {
entrepreneur.get().setSneeStatus(sneeStatus);
}
return this.entrepreneurRepository.save(entrepreneur.get());
}
}