package br.gov.servicos.editor.servicos;

import br.gov.servicos.editor.cartas.Carta;
import br.gov.servicos.editor.cartas.RepositorioGit;
import lombok.experimental.FieldDefaults;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.FileNotFoundException;
import java.io.IOException;

import static lombok.AccessLevel.PRIVATE;
import static org.springframework.web.bind.annotation.RequestMethod.DELETE;

@Slf4j
@Controller
@FieldDefaults(level = PRIVATE, makeFinal = true)
class RemoverCartaController {

    RepositorioGit repositorio;

    @Autowired
    RemoverCartaController(RepositorioGit repositorio) {
        this.repositorio = repositorio;
    }

    @ResponseStatus(value = HttpStatus.OK)
    @RequestMapping(value = "/editar/api/servico/{id}", method = DELETE)
    void remover(
            @PathVariable("id") Carta carta,
            @AuthenticationPrincipal User usuario
    ) throws IOException {
        repositorio.comRepositorioAbertoNoBranch(carta.getBranchRef(), () -> {
            repositorio.pull();

            try {
                repositorio.remove(carta.getCaminhoRelativo());
                repositorio.commit("Remove '" + carta.getId() + "'", usuario, carta.getCaminhoRelativo());
            } finally {
                repositorio.push(carta.getBranchRef());
            }

            return null;
        });
    }

    @ResponseBody
    @ExceptionHandler(FileNotFoundException.class)
    @ResponseStatus(HttpStatus.NOT_FOUND)
    public void naoEncontrado() {
    }

}

@@ -552,76 +552,146 @@
 ion.
-*;%0A%0Aimport java.io.FileNotFoundException;%0Aimport java.io.IOException
+PathVariable;%0Aimport org.springframework.web.bind.annotation.RequestMapping;%0Aimport org.springframework.web.bind.annotation.ResponseStatus
 ;%0A%0Ai
@@ -1299,27 +1299,8 @@
    )
- throws IOException
  %7B%0A 
@@ -1719,16 +1719,16 @@
 n null;%0A
+
         
@@ -1742,158 +1742,6 @@
  %7D%0A%0A
-    @ResponseBody%0A    @ExceptionHandler(FileNotFoundException.class)%0A    @ResponseStatus(HttpStatus.NOT_FOUND)%0A    public void naoEncontrado() %7B%0A    %7D%0A%0A
 %7D%0A

Remove método morto