Commit 49c26675 by Bogdan Andjelkovic

lista-oglasa - controller i repository

parent dc175993
......@@ -42,4 +42,12 @@ public class OglasController
oRepo.insert( loggedUser.getKorisnik().getKorisnikId(), newOglas, files);
return("redirect:/profile");
}
@GetMapping("/lista-oglasa")
public String getListaOglasa( Model model, @AuthenticationPrincipal KorisnikDetails loggedUser)
{
model.addAttribute("loggedUser", loggedUser);
model.addAttribute("oglasi", oRepo.findAll());
return "/lista-oglasa";
}
}
......@@ -7,7 +7,9 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.sql.*;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
@Component
public class OglasRepository
......@@ -56,4 +58,23 @@ public class OglasRepository
}
public List<Oglas> findAll( )
{
List<Oglas> list = new ArrayList<Oglas>();
String sql = "select * from oglas";
ResultSet rs = null;
try {
rs = dataBase.statement.executeQuery( sql);
while( rs.next())
{
Oglas oglas = new Oglas( rs.getInt("oglasId"), rs.getInt("korisnikId"), rs.getString("naslov"),rs.getString("opis"),rs.getInt("lokacijaId"),rs.getDouble("cena"),rs.getInt("vrstaOglasaId"),rs.getDouble("kvadratura"),rs.getInt("brojSoba"),rs.getBoolean("namesten"),rs.getBoolean("grejanje"),rs.getBoolean("lift"),rs.getString("lokacija"));
System.out.println( oglas.toString());
list.add( oglas);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return( list);
}
}
\ 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