Commit 83152be3 by Mihailo Sebek

Merge remote-tracking branch 'origin/master'

parents 4dd31514 6fcfbc14
package com.example.SkuciSe.configuration;
public class AktivanZahtevPostoji extends Exception
{
}
package com.example.SkuciSe.controller;
import com.example.SkuciSe.configuration.AktivanZahtevPostoji;
import com.example.SkuciSe.model.korisnik.KorisnikDetails;
import com.example.SkuciSe.model.oglas.Oglas;
import com.example.SkuciSe.model.zahtev.StanjeZahteva;
import com.example.SkuciSe.model.zahtev.Zahtev;
import com.example.SkuciSe.repository.OglasRepository;
import com.example.SkuciSe.repository.ZahtevRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
......@@ -14,27 +17,42 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Controller
public class ZahtevController {
@Autowired
ZahtevRepository zRepo;
@Autowired
OglasRepository oRepo;
@GetMapping("/profile/moji-zahtevi")
public String getMojiZahtevi(Model model, @AuthenticationPrincipal KorisnikDetails loggedUser)
{
List<Zahtev> mojiZahtevi = zRepo.findAllByKorisnikId( loggedUser.getKorisnik().getKorisnikId());
List<Oglas> mojiOglasi = new ArrayList<Oglas>();
for( Zahtev zahtev: mojiZahtevi)
mojiOglasi.add( oRepo.findById( zahtev.getOglasId()));
model.addAttribute("loggedUser", loggedUser);
model.addAttribute("zahtevi", zRepo.findAllByKorisnikId( loggedUser.getKorisnik().getKorisnikId()));
model.addAttribute("zahtevi", mojiZahtevi);
model.addAttribute("oglasi", mojiOglasi);
return "moji-zahtevi";
}
@PostMapping("/obradi-zahtev/{id}")
public String postObradizahtev(Model model, @AuthenticationPrincipal KorisnikDetails loggedUser, @ModelAttribute Zahtev noviZahtev, @ModelAttribute("datumIVreme") String datumIVreme, @PathVariable("id") int oglasId, RedirectAttributes redirectAttributes)
{
try {
zRepo.insert( loggedUser.getKorisnik().getKorisnikId(), oglasId, noviZahtev, datumIVreme);
redirectAttributes.addFlashAttribute("zakazan",true);
} catch (AktivanZahtevPostoji e) {
redirectAttributes.addFlashAttribute("aktivanZahtevPostoji",true);
}
return "redirect:/lista-oglasa/"+oglasId;
}
......@@ -57,4 +75,10 @@ public class ZahtevController {
return ("redirect:/lista-oglasa/" + oglasId);
}
@GetMapping("/oglas-edit/{oglasId}/obrisi-zahtev/{zahtevId}")
public String getObrisiZahtev( Model model, @PathVariable("oglasId") int oglasId, @PathVariable("zahtevId") int zahtevId)
{
zRepo.deleteZahtev( zahtevId);
return ("redirect:/lista-oglasa/" + oglasId);
}
}
package com.example.SkuciSe.repository;
import com.example.SkuciSe.configuration.AktivanZahtevPostoji;
import com.example.SkuciSe.model.zahtev.StanjeZahteva;
import com.example.SkuciSe.model.zahtev.Zahtev;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -16,8 +17,22 @@ import java.util.*;
public class ZahtevRepository {
@Autowired
DataBase dataBase;
public void insert( int korisnikId, int oglasId, Zahtev noviZahtev, String datumIVreme)
public void insert( int korisnikId, int oglasId, Zahtev noviZahtev, String datumIVreme) throws AktivanZahtevPostoji
{
this.postaviFinishedZahteve();
try {
CallableStatement provera = dataBase.connection.prepareCall( "{ call daLiPostojiAktivanZahtev(?,?)}");
provera.setInt( 1, korisnikId);
provera.setInt( 2, oglasId);
ResultSet rs = provera.executeQuery();
while( rs.next()) {
System.out.println(rs.getString("stanje"));
throw new AktivanZahtevPostoji();
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
String datum = datumIVreme.split(" ")[0];
LocalDate datumFormatiran = LocalDate.parse(datum, DateTimeFormatter.ofPattern("MM/dd/yyyy"));
String vreme = datumIVreme.split(" ")[1];
......@@ -44,6 +59,7 @@ public class ZahtevRepository {
public List<Zahtev> findAllByKorisnikId( int korisnikId)
{
this.postaviFinishedZahteve();
List<Zahtev> list = new ArrayList<Zahtev>();
String sql = "call findAllZahtevByKorisnikId(?)";
CallableStatement stmt = null;
......@@ -65,6 +81,7 @@ public class ZahtevRepository {
public List<Zahtev> findAllByOglasId( int oglasId)
{
this.postaviFinishedZahteve();
List<Zahtev> list = new ArrayList<Zahtev>();
String sql = "call findAllZahtevByOglasId(?)";
CallableStatement stmt = null;
......@@ -109,5 +126,31 @@ public class ZahtevRepository {
} catch (SQLException e) {
throw new RuntimeException(e);
}
this.postaviFinishedZahteve();
}
public void postaviFinishedZahteve()
{
String sql = "{ call postaviFinishedZahteve()}";
CallableStatement cs = null;
try {
cs = dataBase.connection.prepareCall(sql);
cs.execute();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public void deleteZahtev(int zahtevId)
{
String sql = "{ call deleteZahtev(?)}";
CallableStatement cs = null;
try {
cs = dataBase.connection.prepareCall(sql);
cs.setInt( 1, zahtevId);
cs.execute();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
......@@ -203,7 +203,7 @@
class="fa fa-envelope" aria-hidden="true"></i></span><a href="mailto:someone@yoursite.com" style="text-decoration: none;color:#627482;" onmouseover="this.style.color='#989c9e'" onMouseOut="this.style.color='#627482'"> skucise@gmail.com</a> </small></div>
</div>
</div>
</div>
</div></div>
</footer>
</div>
<!-- JavaScript Bundle with Popper -->
......
......@@ -185,6 +185,7 @@
</div>
</div>
</div>
</div>
</footer>
</div>
<!-- JavaScript Bundle with Popper -->
......
......@@ -379,7 +379,7 @@
class="fa fa-envelope" aria-hidden="true"></i></span><a href="mailto:someone@yoursite.com" style="text-decoration: none;color:#627482;" onmouseover="this.style.color='#989c9e'" onMouseOut="this.style.color='#627482'"> skucise@gmail.com</a> </small></div>
</div>
</div>
</div>
</div></div>
</footer>
</div>
......
......@@ -161,7 +161,7 @@
class="fa fa-envelope" aria-hidden="true"></i></span><a href="mailto:someone@yoursite.com" style="text-decoration: none;color:#627482;" onmouseover="this.style.color='#989c9e'" onMouseOut="this.style.color='#627482'"> skucise@gmail.com</a> </small></div>
</div>
</div>
</div>
</div></div>
</footer>
</div>
<!-- JavaScript Bundle with Popper -->
......
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<html lang="en" xmlns="http://www.w3.org/1999/html" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
......@@ -103,10 +103,6 @@
</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">
......@@ -139,6 +135,7 @@
</div>
</div>
</div>
</div>
</footer>
</div>
......
......@@ -287,7 +287,7 @@
class="fa fa-envelope" aria-hidden="true"></i></span><a href="mailto:someone@yoursite.com" style="text-decoration: none;color:#627482;" onmouseover="this.style.color='#989c9e'" onMouseOut="this.style.color='#627482'"> skucise@gmail.com</a> </small></div>
</div>
</div>
</div>
</div></div>
</footer>
</div>
<!-- JavaScript Bundle with Popper -->
......
......@@ -107,6 +107,11 @@
<div><strong>Uspesno!</strong> Uspesno ste poslali zahtev za obilazak!</div>
<button type="button" class="btn-close" data-dismiss="alert"></button>
</div>
<div class="alert alert-warning d-flex justify-content-between align-items-center" th:object="${aktivanZahtevPostoji}"
th:if="${aktivanZahtevPostoji == true}" style="width: 96%">
<div><strong>Greška!</strong> Vec postoji aktivan zahtev za ovaj oglas!</div>
<button type="button" class="btn-close" data-dismiss="alert"></button>
</div>
<div class="row mb-5 flex-row">
<div class="col-lg-6 col-md-6 col-sm-6">
<div id="custCarousel" class="carousel slide" data-ride="carousel" align="center">
......@@ -221,7 +226,8 @@
</div>
</div>
<div class="container container-main d-flex align-items-center justify-content-center flex-column"
th:object="${korisnici}">
th:object="${korisnici}"
th:if="${(loggedUser!=null)&&(loggedUser.korisnik.korisnikId == oglas.korisnikId)}">
<h1>Spisak zahteva za obilazak</h1>
<div class="row w-100 h-50" style="margin-top:50px;">
<div>
......@@ -236,19 +242,25 @@
<div th:if="${zahtevi[korisnikStat.count - 1].status.toString() == 'ZAVRSEN'}" class="col-md-4 h-100" style="background-color: blue;border-radius: 5px"></div>
<div th:if="${zahtevi[korisnikStat.count - 1].status.toString() == 'ODBIJEN'}" class="col-md-4 h-100" style="background-color: red;border-radius: 5px"></div>
</div>
<div class="col-md-3 d-flex justify-content-center align-items-center">
<div class="col-md-2 d-flex justify-content-center align-items-center">
<img
th:src="@{'data:image/png;charset=utf-8;base64,'+${korisnik.getSlika()}}"
alt="slika korisnika" style="width: 150px;height: 150px;border-radius: 50%;object-fit: cover;">
</div>
<div class="col-md-6">
<div class="col-md-4">
<div class="card-body">
<h5 class="card-title"
th:text="${korisnik.getIme() + ' ' + korisnik.getPrezime()}"></h5>
<p class="card-text">
<p class="card-text" th:if="${zahtevi[korisnikStat.count - 1].status.toString()=='POTVRDJEN'}">
Email:<span th:text="${korisnik.getEmail()}"></span><br>
Telefon:<span th:text="${korisnik.getTelefon()}"></span><br>
Datum i Vreme: <span th:text="${zahtevi[korisnikStat.count - 1].datum + ' ' + zahtevi[korisnikStat.count - 1].vreme}"></span>
Telefon:<span th:text="${korisnik.getTelefon()}"></span>
</p>
</div>
</div>
<div class="col-md-3 d-flex flex-column justify-content-around align-items-center">
<div class="card-body">
<p class="card-text">
<span th:text="${zahtevi[korisnikStat.count - 1].datum + ' ' + zahtevi[korisnikStat.count - 1].vreme}"></span>
</p>
</div>
</div>
......@@ -309,7 +321,7 @@
class="fa fa-envelope" aria-hidden="true"></i></span><a href="mailto:someone@yoursite.com" style="text-decoration: none;color:#627482;" onmouseover="this.style.color='#989c9e'" onMouseOut="this.style.color='#627482'"> skucise@gmail.com</a> </small></div>
</div>
</div>
</div>
</div></div>
</footer>
</div>
......
......@@ -169,7 +169,7 @@
class="fa fa-envelope" aria-hidden="true"></i></span><a href="mailto:someone@yoursite.com" style="text-decoration: none;color:#627482;" onmouseover="this.style.color='#989c9e'" onMouseOut="this.style.color='#627482'"> skucise@gmail.com</a> </small></div>
</div>
</div>
</div>
</div></div>
</footer>
</div>
<!-- JavaScript Bundle with Popper -->
......
......@@ -192,7 +192,7 @@
class="fa fa-envelope" aria-hidden="true"></i></span><a href="mailto:someone@yoursite.com" style="text-decoration: none;color:#627482;" onmouseover="this.style.color='#989c9e'" onMouseOut="this.style.color='#627482'"> skucise@gmail.com</a> </small></div>
</div>
</div>
</div>
</div></div>
</footer>
</div>
<!-- JavaScript Bundle with Popper -->
......
......@@ -194,7 +194,7 @@
class="fa fa-envelope" aria-hidden="true"></i></span><a href="mailto:someone@yoursite.com" style="text-decoration: none;color:#627482;" onmouseover="this.style.color='#989c9e'" onMouseOut="this.style.color='#627482'"> skucise@gmail.com</a> </small></div>
</div>
</div>
</div>
</div></div>
</footer>
</div>
<!-- JavaScript Bundle with Popper -->
......
......@@ -207,6 +207,7 @@
</div>
</div>
</div>
</div>
</footer>
</div>
<!-- JavaScript Bundle with Popper -->
......
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