Commit 9a5e5b42 by Bogdan Andjelkovic

kreiran oglas vodi na taj oglas

parent 60e95c38
...@@ -45,8 +45,10 @@ public class OglasController ...@@ -45,8 +45,10 @@ public class OglasController
@PostMapping("/novi-oglas/save") @PostMapping("/novi-oglas/save")
public String postSaveNoviOglas( @ModelAttribute("newOglas") Oglas newOglas, @RequestParam("images") MultipartFile[] files, @AuthenticationPrincipal KorisnikDetails loggedUser) public String postSaveNoviOglas( @ModelAttribute("newOglas") Oglas newOglas, @RequestParam("images") MultipartFile[] files, @AuthenticationPrincipal KorisnikDetails loggedUser)
{ {
oRepo.insert( loggedUser.getKorisnik().getKorisnikId(), newOglas, files); int oglasId = oRepo.insert( loggedUser.getKorisnik().getKorisnikId(), newOglas, files);
return("redirect:/profile"); if( oglasId == -1)
return("redirect:/novi-oglas");
return("redirect:/lista-oglasa/"+oglasId);
} }
@GetMapping("/lista-oglasa") @GetMapping("/lista-oglasa")
......
...@@ -17,7 +17,7 @@ public class OglasRepository ...@@ -17,7 +17,7 @@ public class OglasRepository
@Autowired @Autowired
DataBase dataBase; DataBase dataBase;
public void insert( int korisnikId, Oglas newOglas, MultipartFile[] files) public int insert( int korisnikId, Oglas newOglas, MultipartFile[] files)
{ {
int oglasId; int oglasId;
//String sql = "{ call insertOglas(?,?,?,?,?,?,?,?,?,?,?,?)}"; //String sql = "{ call insertOglas(?,?,?,?,?,?,?,?,?,?,?,?)}";
...@@ -49,14 +49,14 @@ public class OglasRepository ...@@ -49,14 +49,14 @@ public class OglasRepository
sql += " values ("+oglasId+",'"+filename+"')"; sql += " values ("+oglasId+",'"+filename+"')";
dataBase.statement.executeUpdate( sql); dataBase.statement.executeUpdate( sql);
} }
return( oglasId);
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
return( -1);
} }
public Oglas findById(int oglasId) public Oglas findById(int oglasId)
......
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