Search in sources :

Example 1 with PersonAllDTO

use of com.bigcrowd.noticeBoard.dto.PersonAllDTO in project Notice-Board by FulvioFPimentel.

the class PersonController method savePerson.

@PostMapping(value = "/create")
public ResponseEntity<PersonAllDTO> savePerson(@RequestBody PersonSaveDTO dto) {
    PersonAllDTO entity = personService.savePerson(dto);
    URI uri = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(entity.getId()).toUri();
    return ResponseEntity.created(uri).body(entity);
}
Also used : PersonAllDTO(com.bigcrowd.noticeBoard.dto.PersonAllDTO) URI(java.net.URI) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 2 with PersonAllDTO

use of com.bigcrowd.noticeBoard.dto.PersonAllDTO in project Notice-Board by FulvioFPimentel.

the class PersonService method savePerson.

@Transactional
public PersonAllDTO savePerson(PersonSaveDTO dto) {
    Person person = new Person();
    person.setName(dto.getName());
    person.setCellPhone(dto.getCellPhone());
    person.setPassword(passwordEncoder.encode(dto.getPassword()));
    Role role = roleRepository.getById(3L);
    person.getRoles().add(role);
    person = personRepository.saveAndFlush(person);
    return new PersonAllDTO(person, person.getRoles());
}
Also used : Role(com.bigcrowd.noticeBoard.entities.Role) PersonAllDTO(com.bigcrowd.noticeBoard.dto.PersonAllDTO) Person(com.bigcrowd.noticeBoard.entities.Person) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

PersonAllDTO (com.bigcrowd.noticeBoard.dto.PersonAllDTO)2 Person (com.bigcrowd.noticeBoard.entities.Person)1 Role (com.bigcrowd.noticeBoard.entities.Role)1 URI (java.net.URI)1 Transactional (org.springframework.transaction.annotation.Transactional)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1