Search in sources :

Example 1 with SupportDTO

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

the class SupportController method save.

@PostMapping
public ResponseEntity<SupportDTO> save(@RequestBody SupportSaveDTO dto) {
    try {
        SupportDTO entity = supportService.saveSupport(dto);
        URI uri = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(entity.getId()).toUri();
        return ResponseEntity.created(uri).body(entity);
    } catch (RuntimeException e) {
        throw new ControllerNotFoundException("Not Found");
    }
}
Also used : ControllerNotFoundException(com.bigcrowd.noticeBoard.services.exceptions.ControllerNotFoundException) SupportDTO(com.bigcrowd.noticeBoard.dto.SupportDTO) URI(java.net.URI) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 2 with SupportDTO

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

the class SupportService method saveSupport.

@Transactional
public SupportDTO saveSupport(SupportSaveDTO dto) {
    Meeting meeting = meetingRepository.getById(dto.getMeetingId());
    Support support = new Support();
    support.setMeeting(meeting);
    for (DesignationSaveDTO desg : dto.getDesignations()) {
        Assignment Assignment = assignmentRepository.getById(desg.getAssignment().getId());
        Person person = personRepository.getById(desg.getPerson().getId());
        Designation designation = new Designation();
        designation.setAssignment(Assignment);
        designation.setPerson(person);
        designation = designationRepository.saveAndFlush(designation);
        support.getDesignations().add(designation);
    }
    support = supportRepository.saveAndFlush(support);
    return new SupportDTO(support, support.getDesignations());
}
Also used : Assignment(com.bigcrowd.noticeBoard.entities.Assignment) Designation(com.bigcrowd.noticeBoard.entities.Designation) DesignationSaveDTO(com.bigcrowd.noticeBoard.dto.savesDTO.DesignationSaveDTO) Support(com.bigcrowd.noticeBoard.entities.Support) Meeting(com.bigcrowd.noticeBoard.entities.Meeting) SupportDTO(com.bigcrowd.noticeBoard.dto.SupportDTO) Person(com.bigcrowd.noticeBoard.entities.Person) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SupportDTO (com.bigcrowd.noticeBoard.dto.SupportDTO)2 DesignationSaveDTO (com.bigcrowd.noticeBoard.dto.savesDTO.DesignationSaveDTO)1 Assignment (com.bigcrowd.noticeBoard.entities.Assignment)1 Designation (com.bigcrowd.noticeBoard.entities.Designation)1 Meeting (com.bigcrowd.noticeBoard.entities.Meeting)1 Person (com.bigcrowd.noticeBoard.entities.Person)1 Support (com.bigcrowd.noticeBoard.entities.Support)1 ControllerNotFoundException (com.bigcrowd.noticeBoard.services.exceptions.ControllerNotFoundException)1 URI (java.net.URI)1 Transactional (org.springframework.transaction.annotation.Transactional)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1