Commit 40c39f00 by Milovan Samardzic

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	SkuciSe/src/main/java/com/example/SkuciSe/repository/ZahtevRepository.java
#	SkuciSe/src/main/resources/templates/oglas.html
parents 2be8e299 e1414ccd
......@@ -4,10 +4,7 @@ import com.example.SkuciSe.model.korisnik.Korisnik;
import com.example.SkuciSe.model.korisnik.KorisnikDetails;
import com.example.SkuciSe.model.oglas.Oglas;
import com.example.SkuciSe.model.zahtev.Zahtev;
import com.example.SkuciSe.repository.KorisnikRepository;
import com.example.SkuciSe.repository.LokacijaRepository;
import com.example.SkuciSe.repository.OglasRepository;
import com.example.SkuciSe.repository.SlikeRepository;
import com.example.SkuciSe.repository.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller;
......@@ -34,6 +31,9 @@ public class OglasController
@Autowired
SlikeRepository sRepo;
@Autowired
ZahtevRepository zRepo;
@GetMapping("/novi-oglas")
public String getNoviOglas(Model model, @AuthenticationPrincipal KorisnikDetails loggedUser)
{
......@@ -92,7 +92,8 @@ public class OglasController
model.addAttribute("loggedUser", loggedUser);
model.addAttribute("oglas", oRepo.findById( oglasId));
model.addAttribute("slike", sRepo.findAllById( oglasId));
model.addAttribute("grad",kRepo.findCity(oRepo.findById( oglasId).getLokacijaId()));
model.addAttribute("grad", kRepo.findCity(oRepo.findById( oglasId).getLokacijaId()));
model.addAttribute("zahtevi", zRepo.findAllByOglasId( oglasId));
return("oglas");
}
@GetMapping("/profile/moji-oglasi")
......
......@@ -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";
}
......
......@@ -9,12 +9,12 @@ import java.sql.*;
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class Zahtev
{
int terminId;
public class Zahtev {
int zahtevId;
int korisnikId;
int oglasId;
String datum;
String vreme;
StanjeZahteva status;
}
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.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.sql.ResultSet;
import java.sql.CallableStatement;
import java.sql.SQLException;
import java.util.*;
@Component
public class ZahtevRepository {
......@@ -14,19 +16,68 @@ public class ZahtevRepository {
DataBase dataBase;
public void insert(Zahtev noviZahtev, String datumIVreme)
{
String datum = datumIVreme.split(" ")[0];
System.out.println(datum);
LocalDate datumFormatiran = LocalDate.parse(datum, DateTimeFormatter.ofPattern("MM/dd/yyyy"));
String vreme = datumIVreme.split(" ")[1];
noviZahtev.setDatum( datumFormatiran.toString());
String datum = datumIVreme.split("T")[0];
String vreme = datumIVreme.split("T")[1];
noviZahtev.setDatum( datum);
noviZahtev.setVreme( vreme);
System.out.println( noviZahtev.toString());
String sql = "insert into zahtev( oglasid, korisnikid, datum, vreme, stanje) values ("+noviZahtev.getOglasId()+","+noviZahtev.getKorisnikId()+",'"+noviZahtev.getDatum()+"','"+noviZahtev.getDatum()+"','"+noviZahtev.getStatus()+"')";
String sql="{call insertZahtev(?,?,?,?,?)}";
CallableStatement stmt=null;
try {
dataBase.statement.executeUpdate( sql);
stmt=dataBase.connection.prepareCall(sql);
stmt.setInt(1,noviZahtev.getKorisnikId());
stmt.setInt(2,noviZahtev.getOglasId());
stmt.setString(3,noviZahtev.getDatum());
stmt.setString(4,noviZahtev.getVreme());
stmt.setString(5,noviZahtev.getStatus().toString());
stmt.executeUpdate();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public List<Zahtev> findAllByKorisnikId( int korisnikId)
{
List<Zahtev> list = new ArrayList<Zahtev>();
String sql = "call findAllZahtevByKorisnikId(?)";
CallableStatement stmt = null;
ResultSet rs = null;
try {
stmt = dataBase.connection.prepareCall( sql);
stmt.setInt( 1, korisnikId);
rs = stmt.executeQuery();
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 = "call findAllZahtevByOglasId(?)";
CallableStatement stmt = null;
ResultSet rs = null;
try {
stmt = dataBase.connection.prepareCall( sql);
stmt.setInt( 1, oglasId);
rs = stmt.executeQuery();
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>
......
......@@ -89,6 +89,10 @@
</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