Commit 87a78ca1 by Bogdan Andjelkovic

findAllZahtev po korisniku i oglasu i slanje na listu mojih zahteva

parent 4c90b7d7
......@@ -25,6 +25,7 @@ public class ZahtevController {
public String getMojiZahtevi(Model model, @AuthenticationPrincipal KorisnikDetails loggedUser)
{
model.addAttribute("loggedUser", loggedUser);
model.addAttribute("zahtevi", zRepo.findAllByKorisnikId( loggedUser.getKorisnik().getKorisnikId()));
return "moji-zahtevi";
}
......
package com.example.SkuciSe.repository;
import com.example.SkuciSe.model.zahtev.StanjeZahteva;
import com.example.SkuciSe.model.zahtev.Zahtev;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.sql.ResultSet;
import java.sql.CallableStatement;
import java.sql.SQLException;
import java.util.*;
@Component
public class ZahtevRepository {
......@@ -34,4 +37,42 @@ public class ZahtevRepository {
throw new RuntimeException(e);
}
}
public List<Zahtev> findAllByKorisnikId( int korisnikId)
{
List<Zahtev> list = new ArrayList<Zahtev>();
String sql = "select * from zahtev where korisnikid = " + korisnikId;
ResultSet rs = null;
try {
rs = dataBase.statement.executeQuery( sql);
while( rs.next())
{
Zahtev zahtev = new Zahtev( rs.getInt(1), rs.getInt(2), rs.getInt(3), rs.getString(4), rs.getString(5), StanjeZahteva.valueOf(rs.getString(6)));
System.out.println( zahtev.toString());
list.add( zahtev);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return( list);
}
public List<Zahtev> findAllByOglasId( int oglasId)
{
List<Zahtev> list = new ArrayList<Zahtev>();
String sql = "select * from zahtev where oglasid = " + oglasId;
ResultSet rs = null;
try {
rs = dataBase.statement.executeQuery( sql);
while( rs.next())
{
Zahtev zahtev = new Zahtev( rs.getInt(1), rs.getInt(2), rs.getInt(3), rs.getString(4), rs.getString(5), StanjeZahteva.valueOf(rs.getString(6)));
System.out.println( zahtev.toString());
list.add( zahtev);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return( list);
}
}
......@@ -45,7 +45,7 @@
</a>
</li>
<li class="nav-item active">
<a class="nav-link" th:href="@{/lista-oglasa}">
<a class="nav-link" href="/lista-oglasa">
<i class="fa fa-poll-h"></i>
Lista oglasa
<span class="sr-only">(current)</span>
......
......@@ -88,7 +88,9 @@
</ul>
</div>
</nav>
<div th:object="${zahtevi}">
<p th:each="zahtev: ${zahtevi}" th:text="${zahtev.toString()}"></p>
</div>
<div class="container-fluid pb-0 mb-0 justify-content-center text-light ">
<footer>
<div class="row my-5 justify-content-center py-5">
......
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