feat: added color in logs
This commit is contained in:
@ -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());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user