Commit 68d2153b by Bogdan Andjelkovic

filtriranje oglasa - back

parent f044fe2e
......@@ -64,7 +64,7 @@ public class OglasController
@RequestParam(value = "namesten", required=false) Boolean namesten)
{
model.addAttribute("loggedUser", loggedUser);
List<Oglas> listaOglasa = oRepo.findAll();
List<Oglas> listaOglasa = oRepo.findAll( vrstaOglasaId, lokacijaId, cenaMin, cenaMax, brojSoba, kvadratura, lift, grejanje, namesten);
while(listaOglasa.size() % 3 != 0){
Oglas o = new Oglas();
listaOglasa.add(o);
......
......@@ -143,4 +143,31 @@ public class OglasRepository
throw new RuntimeException(e);
}
}
public List<Oglas> findAll(Integer vrstaOglasaId, Integer lokacijaId, Double cenaMin, Double cenaMax, Integer brojSoba, Double kvadratura, Boolean lift, Boolean grejanje, Boolean namesten)
{
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"));
if(!( vrstaOglasaId == null || ( vrstaOglasaId != null && vrstaOglasaId == oglas.getVrstaOglasaId() ) ) ) continue;
if(!( lokacijaId == null || ( lokacijaId != null && lokacijaId == oglas.getLokacijaId() ) ) ) continue;
if(!( cenaMin == null || ( cenaMin != null && cenaMin <= oglas.getCena() ) ) ) continue;
if(!( cenaMax == null || ( cenaMax != null && cenaMax >= oglas.getCena() ) ) ) continue;
if(!( brojSoba == null || ( brojSoba != null && brojSoba == oglas.getBrojSoba() ) ) ) continue;
if(!( kvadratura == null || ( kvadratura != null && kvadratura == oglas.getKvadratura() ) ) ) continue;
if(!( lift == null || ( lift != null && lift == oglas.isLift() ) ) ) continue;
if(!( grejanje == null || ( grejanje != null && grejanje == oglas.isGrejanje() ) ) ) continue;
if(!( namesten == null || ( namesten != null && namesten == oglas.isNamesten() ) ) ) continue;
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