package es.uv.saic.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

import es.uv.saic.domain.Proces;
import es.uv.saic.dto.ProcesDTO;
import es.uv.saic.service.ProcesService;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;


@RestController
public class ProcesController {
    @Autowired
    private ProcesService procesService;

    @PostMapping("/proces/{id}")
    public ResponseEntity<?> findById(@PathVariable Integer id) {
        try {
            Proces proces = procesService.findByID(id);
            ProcesDTO procesDTO = new ProcesDTO(proces);

            return (procesDTO != null) ? ResponseEntity.ok(procesDTO) : ResponseEntity.badRequest().body("El proces con id " + id + " esta vacio");
        } catch (Exception e) {
             e.printStackTrace();
            return ResponseEntity.badRequest().body("Error al obtener el proces por el id:" +  e.getMessage());
        }
    }    
}
