Added person and group methods to Controller and services.
This commit is contained in:
parent
d8c0698713
commit
0eade63e61
@ -7,7 +7,10 @@ import com.example.demo.service.StudentsGroupService;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
public class Controller {
|
||||
|
||||
private final PersonService personService;
|
||||
@ -22,6 +25,11 @@ public class Controller {
|
||||
this.importExportService = importExportService;
|
||||
}
|
||||
|
||||
@GetMapping("/person")
|
||||
List<PersonDto> getAllPeople() {
|
||||
return personService.getAll();
|
||||
}
|
||||
|
||||
@GetMapping("/person/{id}")
|
||||
PersonDto getPerson(@PathVariable Long id) {
|
||||
return personService.get(id);
|
||||
@ -42,6 +50,10 @@ public class Controller {
|
||||
personService.delete(id);
|
||||
}
|
||||
|
||||
@GetMapping("/group")
|
||||
List<GroupDto> getAllGroups() {
|
||||
return studentsGroupService.getAll();
|
||||
}
|
||||
@GetMapping("/group/{id}")
|
||||
GroupDto getGroup(@PathVariable Long id) {
|
||||
return studentsGroupService.get(id);
|
||||
|
@ -12,8 +12,10 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
@ -102,4 +104,8 @@ public class PersonService {
|
||||
logger.info("Usuwam osobę");
|
||||
personRepository.deleteById(id);
|
||||
}
|
||||
|
||||
public List<PersonDto> getAll() {
|
||||
return personRepository.findAll().stream().map(Person::toDto).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,8 @@ import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackOn = Exception.class)
|
||||
@ -149,4 +151,8 @@ public class StudentsGroupService {
|
||||
logger.info("Usuwam lidera grupy. {}", groupLeader);
|
||||
studentsGroup.removeGroupLeader(groupLeader);
|
||||
}
|
||||
|
||||
public List<GroupDto> getAll() {
|
||||
return this.studentsGroupRepository.findAll().stream().map(StudentsGroup::toDto).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user