Commit bf33d929 by Mihailo Sebek

countOglas

parent a7bea246
...@@ -64,6 +64,7 @@ public class OglasController ...@@ -64,6 +64,7 @@ public class OglasController
public String getOglas(Model model, @PathVariable("oglasId") int oglasId, @AuthenticationPrincipal KorisnikDetails loggedUser) public String getOglas(Model model, @PathVariable("oglasId") int oglasId, @AuthenticationPrincipal KorisnikDetails loggedUser)
{ {
Oglas oglas = oRepo.findById( oglasId); Oglas oglas = oRepo.findById( oglasId);
model.addAttribute("avgOcena",komentarRepository.averageOcenaByOglasId(oglasId));
model.addAttribute("oglas", oglas); model.addAttribute("oglas", oglas);
model.addAttribute("oglasId", oglasId); model.addAttribute("oglasId", oglasId);
model.addAttribute("loggedUser", loggedUser); model.addAttribute("loggedUser", loggedUser);
......
...@@ -94,6 +94,7 @@ public class ProfileController ...@@ -94,6 +94,7 @@ public class ProfileController
@GetMapping("/korisnik/{korisnikId}") @GetMapping("/korisnik/{korisnikId}")
public String getKorisnik(Model model, @AuthenticationPrincipal KorisnikDetails loggedUser, @PathVariable("korisnikId") int korisnikId) public String getKorisnik(Model model, @AuthenticationPrincipal KorisnikDetails loggedUser, @PathVariable("korisnikId") int korisnikId)
{ {
model.addAttribute("countOglas",oRepo.countOglasByKorisnikId(korisnikId));
model.addAttribute("loggedUser", loggedUser); model.addAttribute("loggedUser", loggedUser);
model.addAttribute("korisnik", kRepo.findById( korisnikId)); model.addAttribute("korisnik", kRepo.findById( korisnikId));
List<Oglas> oglasi = oRepo.findAllByKorisnikId(korisnikId,null,null,null,null,null,null,null,null,null,null,null); List<Oglas> oglasi = oRepo.findAllByKorisnikId(korisnikId,null,null,null,null,null,null,null,null,null,null,null);
......
...@@ -239,4 +239,23 @@ public class OglasRepository ...@@ -239,4 +239,23 @@ public class OglasRepository
} }
return( list); return( list);
} }
public int countOglasByKorisnikId(int korisnikId)
{
CallableStatement stmt=null;
ResultSet rs=null;
try {
String sql = "{call countOglasByKorisnikId(?)}";
stmt = dataBase.connection.prepareCall( sql);
stmt.setInt(1,korisnikId);
rs=stmt.executeQuery();
while(rs.next())
{
return(rs.getInt(1));
}
} catch (SQLException e) {
System.out.println(e.getMessage());
}
return 0;
}
} }
\ No newline at end of file
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