Commit 31087ef7 by Mihailo Sebek

brisanje oglasa

parent 8bc5d7bc
......@@ -158,4 +158,13 @@ public class OglasController
model.addAttribute("slikeOglasa", sRepo.findAllFirstPics(listaOglasa));
return "lista-oglasa";
}
@PostMapping("/obrisi-oglas/{oglasId}")
public String postObrisiOglas(@AuthenticationPrincipal KorisnikDetails loggedUser, @PathVariable("oglasId") int oglasId)
{
if (loggedUser.getKorisnik().getTipId()==1 || oRepo.findById(oglasId).getKorisnikId()==loggedUser.getKorisnik().getKorisnikId()) {
oRepo.deleteOglas(oglasId);
}
return "redirect:/lista-oglasa";
}
}
......@@ -83,6 +83,19 @@ public class OglasRepository
return( null);
}
public void deleteOglas(int oglasId)
{
String sql = "{ call deleteOglas(?)}";
CallableStatement stmt = null;
try {
stmt = dataBase.connection.prepareCall(sql);
stmt.setInt( 1, oglasId);
stmt.execute();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public void deleteOglasi(Integer id)
{
String sql = "{call findAllByKorisnikId(?)}";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment