feat: added most of shared API calls
This commit is contained in:
@ -1,28 +1,30 @@
|
||||
package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services;
|
||||
package enseirb.myinpulse.service.database;
|
||||
|
||||
import enseirb.myinpulse.model.Entrepreneur;
|
||||
import enseirb.myinpulse.model.Project;
|
||||
import enseirb.myinpulse.repository.EntrepreneurRepository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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;
|
||||
|
||||
@RestController
|
||||
public class EntrepreneurController {
|
||||
@Service
|
||||
public class EntrepreneurService {
|
||||
|
||||
@Autowired EntrepreneurRepository entrepreneurRepository;
|
||||
private final EntrepreneurRepository entrepreneurRepository;
|
||||
|
||||
@GetMapping("/Entrepreneur")
|
||||
@ResponseBody
|
||||
public Iterable<Entrepreneur> allEntrepreneurs() {
|
||||
EntrepreneurService(EntrepreneurRepository entrepreneurRepository) {
|
||||
this.entrepreneurRepository = entrepreneurRepository;
|
||||
}
|
||||
|
||||
public Iterable<Entrepreneur> getAllEntrepreneurs() {
|
||||
return this.entrepreneurRepository.findAll();
|
||||
}
|
||||
|
||||
@GetMapping("/Entrepreneur/{id}")
|
||||
public Entrepreneur getEntrepreneurById(@PathVariable Long id) {
|
||||
public Entrepreneur getEntrepreneurById(Long id) {
|
||||
Optional<Entrepreneur> entrepreneur = entrepreneurRepository.findById(id);
|
||||
if (entrepreneur.isEmpty()) {
|
||||
throw new ResponseStatusException(
|
||||
@ -31,14 +33,12 @@ public class EntrepreneurController {
|
||||
return entrepreneur.get();
|
||||
}
|
||||
|
||||
@PostMapping("/Entrepreneur")
|
||||
public Entrepreneur addEntrepreneur(@RequestBody Entrepreneur entrepreneur) {
|
||||
public Entrepreneur addEntrepreneur(Entrepreneur entrepreneur) {
|
||||
return this.entrepreneurRepository.save(entrepreneur);
|
||||
}
|
||||
|
||||
@PostMapping("/Entrepreneur/{id}")
|
||||
public Entrepreneur updateEntrepreneur(
|
||||
@PathVariable Long id, String school, String course, Boolean sneeStatus) {
|
||||
Long id, String school, String course, Boolean sneeStatus) {
|
||||
Optional<Entrepreneur> entrepreneur = entrepreneurRepository.findById(id);
|
||||
if (entrepreneur.isEmpty()) {
|
||||
throw new ResponseStatusException(
|
||||
@ -55,4 +55,8 @@ public class EntrepreneurController {
|
||||
}
|
||||
return this.entrepreneurRepository.save(entrepreneur.get());
|
||||
}
|
||||
|
||||
public Iterable<Entrepreneur> GetEntrepreneurByProject(Project project) {
|
||||
return this.entrepreneurRepository.getEntrepreneurByProjectParticipation(project);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user