Commit 75be4f70 by Bogdan Andjelkovic

dosta toga

parent 75ec918a
...@@ -4,6 +4,7 @@ import com.example.SkuciSe.model.korisnik.Korisnik; ...@@ -4,6 +4,7 @@ import com.example.SkuciSe.model.korisnik.Korisnik;
import com.example.SkuciSe.model.korisnik.KorisnikDetails; import com.example.SkuciSe.model.korisnik.KorisnikDetails;
import com.example.SkuciSe.repository.KorisnikRepository; import com.example.SkuciSe.repository.KorisnikRepository;
import com.example.SkuciSe.repository.LokacijaRepository; import com.example.SkuciSe.repository.LokacijaRepository;
import com.example.SkuciSe.repository.OglasRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
...@@ -23,6 +24,8 @@ public class AdminController ...@@ -23,6 +24,8 @@ public class AdminController
KorisnikRepository kRepo; KorisnikRepository kRepo;
@Autowired @Autowired
LokacijaRepository lRepo; LokacijaRepository lRepo;
@Autowired
OglasRepository oRepo;
@GetMapping("/lista-korisnika") @GetMapping("/lista-korisnika")
public String getListaKorisnika(Model model, @AuthenticationPrincipal KorisnikDetails loggedUser) public String getListaKorisnika(Model model, @AuthenticationPrincipal KorisnikDetails loggedUser)
...@@ -43,6 +46,7 @@ public class AdminController ...@@ -43,6 +46,7 @@ public class AdminController
@PostMapping ("/delete-user/{id}") @PostMapping ("/delete-user/{id}")
public String deleteUser(@PathVariable("id") Integer id, @AuthenticationPrincipal KorisnikDetails loggedUser, Model model, RedirectAttributes redirectAttributes){ public String deleteUser(@PathVariable("id") Integer id, @AuthenticationPrincipal KorisnikDetails loggedUser, Model model, RedirectAttributes redirectAttributes){
oRepo.deleteOglasi(id);
kRepo.deleteUser(id); kRepo.deleteUser(id);
redirectAttributes.addFlashAttribute("deleted", true); redirectAttributes.addFlashAttribute("deleted", true);
return "redirect:/lista-korisnika"; return "redirect:/lista-korisnika";
......
...@@ -74,4 +74,21 @@ public class OglasController ...@@ -74,4 +74,21 @@ public class OglasController
model.addAttribute("slike", sRepo.findAllById( oglasId)); model.addAttribute("slike", sRepo.findAllById( oglasId));
return("oglas"); return("oglas");
} }
@GetMapping("/profile/moji-oglasi")
public String getMojiOglasa( Model model, @AuthenticationPrincipal KorisnikDetails loggedUser)
{
model.addAttribute("loggedUser", loggedUser);
List<Oglas> listaOglasa = oRepo.findAllByKorisnikId( loggedUser.getKorisnik().getKorisnikId());
while(listaOglasa.size() % 3 != 0){
Oglas o = new Oglas();
listaOglasa.add(o);
}
model.addAttribute("oglasi",listaOglasa);
List<String> list = new ArrayList<String>();
for (Oglas o:listaOglasa) {
list.add(kRepo.findCity(o.getLokacijaId()));
}
model.addAttribute("gradovi",list);
return "/lista-oglasa";
}
} }
...@@ -37,7 +37,7 @@ public class ProfileController ...@@ -37,7 +37,7 @@ public class ProfileController
return("profile"); return("profile");
} }
@GetMapping("/profile-edit") @GetMapping("/profile/edit")
public String getProfileEdit(Model model, @ModelAttribute Korisnik korisnik, @AuthenticationPrincipal KorisnikDetails loggedUser) public String getProfileEdit(Model model, @ModelAttribute Korisnik korisnik, @AuthenticationPrincipal KorisnikDetails loggedUser)
{ {
model.addAttribute("loggedUser", loggedUser); model.addAttribute("loggedUser", loggedUser);
...@@ -45,7 +45,7 @@ public class ProfileController ...@@ -45,7 +45,7 @@ public class ProfileController
model.addAttribute("lokacije", lRepo.findAll()); model.addAttribute("lokacije", lRepo.findAll());
return "/profile-edit"; return "/profile-edit";
} }
@PostMapping("/profile-edit-save") @PostMapping("/profile/edit-save")
public String postProfileEditSave(Model model, @ModelAttribute Korisnik korisnik, @AuthenticationPrincipal KorisnikDetails loggedUser) public String postProfileEditSave(Model model, @ModelAttribute Korisnik korisnik, @AuthenticationPrincipal KorisnikDetails loggedUser)
{ {
kRepo.update( korisnik); kRepo.update( korisnik);
...@@ -53,7 +53,7 @@ public class ProfileController ...@@ -53,7 +53,7 @@ public class ProfileController
return "redirect:/profile"; return "redirect:/profile";
} }
@PostMapping("/profile-picture-update") @PostMapping("/profile/picture-update")
public String izmeniSliku(@AuthenticationPrincipal KorisnikDetails loggedUser,@RequestParam("image") MultipartFile file) { public String izmeniSliku(@AuthenticationPrincipal KorisnikDetails loggedUser,@RequestParam("image") MultipartFile file) {
kRepo.updateSlika(loggedUser.getKorisnik(),file); kRepo.updateSlika(loggedUser.getKorisnik(),file);
try { try {
...@@ -64,19 +64,19 @@ public class ProfileController ...@@ -64,19 +64,19 @@ public class ProfileController
return "redirect:/profile"; return "redirect:/profile";
} }
@GetMapping("/password-edit") @GetMapping("/profile/password-edit")
public String getProfilePasswordEdit(Model model, @ModelAttribute Korisnik korisnik, @AuthenticationPrincipal KorisnikDetails loggedUser) public String getProfilePasswordEdit(Model model, @ModelAttribute Korisnik korisnik, @AuthenticationPrincipal KorisnikDetails loggedUser)
{ {
model.addAttribute("loggedUser", loggedUser); model.addAttribute("loggedUser", loggedUser);
model.addAttribute("editUser", loggedUser.getKorisnik()); model.addAttribute("editUser", loggedUser.getKorisnik());
return "/password-edit"; return "/password-edit";
} }
@PostMapping("/password-edit-save") @PostMapping("/profile/password-edit-save")
public String postPasswordEditSave(Model model, @ModelAttribute Korisnik korisnik, @AuthenticationPrincipal KorisnikDetails loggedUser) public String postPasswordEditSave(Model model, @ModelAttribute Korisnik korisnik, @AuthenticationPrincipal KorisnikDetails loggedUser)
{ {
System.out.println(korisnik.toString()); System.out.println(korisnik.toString());
kRepo.updateSifra( korisnik, loggedUser.getKorisnik().getKorisnikId()); kRepo.updateSifra( korisnik, loggedUser.getKorisnik().getKorisnikId());
loggedUser.setKorisnikSifra( korisnik.getSifra()); loggedUser.setKorisnikSifra( korisnik.getSifra());
return "redirect:/index"; return "redirect:/profile";
} }
} }
...@@ -93,4 +93,54 @@ public class OglasRepository ...@@ -93,4 +93,54 @@ public class OglasRepository
} }
return( null); return( null);
} }
public List<Oglas> findAllByKorisnikId( int korisnikId)
{
List<Oglas> list = new ArrayList<Oglas>();
String sql = "select * from oglas where korisnikid = " + korisnikId;
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"));
list.add( oglas);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return( list);
}
public void deleteOglasi(Integer id)
{
String sql = "select * from oglas where korisnikid = " + id;
ResultSet rs = null;
try {
rs = dataBase.statement.executeQuery( sql);
while( rs.next())
{
int oglasid = rs.getInt("oglasid");
this.deleteSlike( oglasid);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
sql = "delete from oglas where KorisnikId = "+id;
try {
dataBase.statement.execute(sql);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public void deleteSlike(Integer id)
{
String sql = "delete from slike where oglasid = "+id;
try {
dataBase.statement.execute(sql);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
} }
\ No newline at end of file
...@@ -32,4 +32,6 @@ public class SlikeRepository ...@@ -32,4 +32,6 @@ public class SlikeRepository
return list; return list;
} }
} }
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
</button> </button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton"> <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" th:href="@{/profile}">Moj Profil</a> <a class="dropdown-item" th:href="@{/profile}">Moj Profil</a>
<a class="dropdown-item" th:href="@{/mojioglasi}">Moji Oglasi</a> <a class="dropdown-item" th:href="@{/profile/moji-oglasi}">Moji Oglasi</a>
<a class="dropdown-item" th:href="@{/mojizahtevi}">Moji Zahtevi</a> <a class="dropdown-item" th:href="@{/mojizahtevi}">Moji Zahtevi</a>
<a th:if="${loggedUser.getKorisnik().getTipId() == 2}" class="dropdown-item" <a th:if="${loggedUser.getKorisnik().getTipId() == 2}" class="dropdown-item"
th:href="@{/lista-korisnika}">Lista Profila</a> th:href="@{/lista-korisnika}">Lista Profila</a>
......
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
</button> </button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton"> <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" th:href="@{/profile}">Moj Profil</a> <a class="dropdown-item" th:href="@{/profile}">Moj Profil</a>
<a class="dropdown-item" th:href="@{/mojioglasi}">Moji Oglasi</a> <a class="dropdown-item" th:href="@{/profile/moji-oglasi}">Moji Oglasi</a>
<a class="dropdown-item" th:href="@{/mojizahtevi}">Moji Zahtevi</a> <a class="dropdown-item" th:href="@{/mojizahtevi}">Moji Zahtevi</a>
<a th:if="${loggedUser.getKorisnik().getTipId() == 2}" class="dropdown-item" <a th:if="${loggedUser.getKorisnik().getTipId() == 2}" class="dropdown-item"
th:href="@{/lista-korisnika}">Lista Profila</a> th:href="@{/lista-korisnika}">Lista Profila</a>
......
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
</button> </button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton"> <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" th:href="@{/profile}">Moj Profil</a> <a class="dropdown-item" th:href="@{/profile}">Moj Profil</a>
<a class="dropdown-item" th:href="@{/mojioglasi}">Moji Oglasi</a> <a class="dropdown-item" th:href="@{/profile/moji-oglasi}">Moji Oglasi</a>
<a class="dropdown-item" th:href="@{/mojizahtevi}">Moji Zahtevi</a> <a class="dropdown-item" th:href="@{/mojizahtevi}">Moji Zahtevi</a>
<a th:if="${loggedUser.getKorisnik().getTipId() == 2}" class="dropdown-item" <a th:if="${loggedUser.getKorisnik().getTipId() == 2}" class="dropdown-item"
th:href="@{/lista-korisnika}">Lista Profila</a> th:href="@{/lista-korisnika}">Lista Profila</a>
......
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
</button> </button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton"> <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" th:href="@{/profile}">Moj Profil</a> <a class="dropdown-item" th:href="@{/profile}">Moj Profil</a>
<a class="dropdown-item" th:href="@{/mojioglasi}">Moji Oglasi</a> <a class="dropdown-item" th:href="@{/profile/moji-oglasi}">Moji Oglasi</a>
<a class="dropdown-item" th:href="@{/mojizahtevi}">Moji Zahtevi</a> <a class="dropdown-item" th:href="@{/mojizahtevi}">Moji Zahtevi</a>
<a th:if="${loggedUser.getKorisnik().getTipId() == 2}" class="dropdown-item" <a th:if="${loggedUser.getKorisnik().getTipId() == 2}" class="dropdown-item"
th:href="@{/lista-korisnika}">Lista Profila</a> th:href="@{/lista-korisnika}">Lista Profila</a>
......
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
</button> </button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton"> <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" th:href="@{/profile}">Moj Profil</a> <a class="dropdown-item" th:href="@{/profile}">Moj Profil</a>
<a class="dropdown-item" th:href="@{/mojioglasi}">Moji Oglasi</a> <a class="dropdown-item" th:href="@{/profile/moji-oglasi}">Moji Oglasi</a>
<a class="dropdown-item" th:href="@{/mojizahtevi}">Moji Zahtevi</a> <a class="dropdown-item" th:href="@{/mojizahtevi}">Moji Zahtevi</a>
<a th:if="${loggedUser.getKorisnik().getTipId() == 2}" class="dropdown-item" <a th:if="${loggedUser.getKorisnik().getTipId() == 2}" class="dropdown-item"
th:href="@{/lista-korisnika}">Lista Profila</a> th:href="@{/lista-korisnika}">Lista Profila</a>
......
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
</button> </button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton"> <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" th:href="@{/profile}">Moj Profil</a> <a class="dropdown-item" th:href="@{/profile}">Moj Profil</a>
<a class="dropdown-item" th:href="@{/mojioglasi}">Moji Oglasi</a> <a class="dropdown-item" th:href="@{/profile/moji-oglasi}">Moji Oglasi</a>
<a class="dropdown-item" th:href="@{/mojizahtevi}">Moji Zahtevi</a> <a class="dropdown-item" th:href="@{/mojizahtevi}">Moji Zahtevi</a>
<a th:if="${loggedUser.getKorisnik().getTipId() == 2}" class="dropdown-item" <a th:if="${loggedUser.getKorisnik().getTipId() == 2}" class="dropdown-item"
th:href="@{/lista-korisnika}">Lista Profila</a> th:href="@{/lista-korisnika}">Lista Profila</a>
...@@ -92,6 +92,7 @@ ...@@ -92,6 +92,7 @@
<h1 th:text="${oglas.toString()}"></h1> <h1 th:text="${oglas.toString()}"></h1>
</div> </div>
<div class="container" th:object="${slike}"> <div class="container" th:object="${slike}">
<h1 th:text="${slike.size()}"></h1>
</div> </div>
<div class="container-fluid pb-0 mb-0 justify-content-center text-light "> <div class="container-fluid pb-0 mb-0 justify-content-center text-light ">
......
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
</button> </button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton"> <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" th:href="@{/profile}">Moj Profil</a> <a class="dropdown-item" th:href="@{/profile}">Moj Profil</a>
<a class="dropdown-item" th:href="@{/mojioglasi}">Moji Oglasi</a> <a class="dropdown-item" th:href="@{/profile/moji-oglasi}">Moji Oglasi</a>
<a class="dropdown-item" th:href="@{/mojizahtevi}">Moji Zahtevi</a> <a class="dropdown-item" th:href="@{/mojizahtevi}">Moji Zahtevi</a>
<a th:if="${loggedUser.getKorisnik().getTipId() == 2}" class="dropdown-item" <a th:if="${loggedUser.getKorisnik().getTipId() == 2}" class="dropdown-item"
th:href="@{/lista-korisnika}">Lista Profila</a> th:href="@{/lista-korisnika}">Lista Profila</a>
...@@ -91,7 +91,7 @@ ...@@ -91,7 +91,7 @@
<div class="form-content"> <div class="form-content">
<div class="form-items"> <div class="form-items">
<form class="requires-validation" novalidate th:object="${editUser}" method="POST" <form class="requires-validation" novalidate th:object="${editUser}" method="POST"
th:action="@{/password-edit-save}" enctype="multipart/form-data" th:action="@{/profile/password-edit-save}" enctype="multipart/form-data"
onsubmit="return validateForm()"> onsubmit="return validateForm()">
<div class="col-md-12"> <div class="col-md-12">
......
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
</button> </button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton"> <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" th:href="@{/profile}">Moj Profil</a> <a class="dropdown-item" th:href="@{/profile}">Moj Profil</a>
<a class="dropdown-item" th:href="@{/mojioglasi}">Moji Oglasi</a> <a class="dropdown-item" th:href="@{/profile/moji-oglasi}">Moji Oglasi</a>
<a class="dropdown-item" th:href="@{/mojizahtevi}">Moji Zahtevi</a> <a class="dropdown-item" th:href="@{/mojizahtevi}">Moji Zahtevi</a>
<a th:if="${loggedUser.getKorisnik().getTipId() == 2}" class="dropdown-item" <a th:if="${loggedUser.getKorisnik().getTipId() == 2}" class="dropdown-item"
th:href="@{/lista-korisnika}">Lista Profila</a> th:href="@{/lista-korisnika}">Lista Profila</a>
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
<div class="form-content"> <div class="form-content">
<div class="form-items"> <div class="form-items">
<form class="requires-validation" novalidate th:object="${editUser}" method="POST" <form class="requires-validation" novalidate th:object="${editUser}" method="POST"
th:action="@{/profile-edit-save}" enctype="multipart/form-data"> th:action="@{/profile/edit-save}" enctype="multipart/form-data">
<div class="col-md-12"> <div class="col-md-12">
<input th:field="${editUser.ime}" class="form-control" type="text" <input th:field="${editUser.ime}" class="form-control" type="text"
name="name" placeholder="Ime" required> name="name" placeholder="Ime" required>
......
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
</button> </button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton"> <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" th:href="@{/profile}">Moj Profil</a> <a class="dropdown-item" th:href="@{/profile}">Moj Profil</a>
<a class="dropdown-item" th:href="@{/mojioglasi}">Moji Oglasi</a> <a class="dropdown-item" th:href="@{/profile/moji-oglasi}">Moji Oglasi</a>
<a class="dropdown-item" th:href="@{/mojizahtevi}">Moji Zahtevi</a> <a class="dropdown-item" th:href="@{/mojizahtevi}">Moji Zahtevi</a>
<a th:if="${loggedUser.getKorisnik().getTipId() == 2}" class="dropdown-item" <a th:if="${loggedUser.getKorisnik().getTipId() == 2}" class="dropdown-item"
th:href="@{/lista-korisnika}">Lista Profila</a> th:href="@{/lista-korisnika}">Lista Profila</a>
...@@ -107,10 +107,10 @@ ...@@ -107,10 +107,10 @@
<p class="fw-bold h4 mt-3"><span th:text="${loggedUser.getKorisnik().getIme()}"></span></p> <p class="fw-bold h4 mt-3"><span th:text="${loggedUser.getKorisnik().getIme()}"></span></p>
<p class="text-muted" th:object="${profileRole}" th:text="${profileRole}"></p> <p class="text-muted" th:object="${profileRole}" th:text="${profileRole}"></p>
<div class="d-flex justify-content-around w-75"> <div class="d-flex justify-content-around w-75">
<a th:href="@{/profile-edit}"> <a th:href="@{/profile/edit}">
<button type="button" class="btn btn-secondary m-10" id="fade">Izmeni podatke</button> <button type="button" class="btn btn-secondary m-10" id="fade">Izmeni podatke</button>
</a> </a>
<a th:href="@{/password-edit}"> <a th:href="@{/profile/password-edit}">
<button type="button" class="btn btn-secondary m-10">Promeni sifru</button> <button type="button" class="btn btn-secondary m-10">Promeni sifru</button>
</a> </a>
</div> </div>
...@@ -118,7 +118,7 @@ ...@@ -118,7 +118,7 @@
</div> </div>
</div> </div>
</div> </div>
<form id="formaSlika" method="POST" th:object="${loggedUser}" th:action="@{/profile-picture-update}" <form id="formaSlika" method="POST" th:object="${loggedUser}" th:action="@{/profile/picture-update}"
style="display: none" enctype="multipart/form-data"> style="display: none" enctype="multipart/form-data">
<input type="file" name="image" accept="image/png, image/jpeg" id="inputSlika" style="display: none" <input type="file" name="image" accept="image/png, image/jpeg" id="inputSlika" style="display: none"
onchange="document.getElementById('formaSlika').submit();return false;"/> onchange="document.getElementById('formaSlika').submit();return false;"/>
......
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
</button> </button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton"> <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" th:href="@{/profile}">Moj Profil</a> <a class="dropdown-item" th:href="@{/profile}">Moj Profil</a>
<a class="dropdown-item" th:href="@{/mojioglasi}">Moji Oglasi</a> <a class="dropdown-item" th:href="@{/profile/moji-oglasi}">Moji Oglasi</a>
<a class="dropdown-item" th:href="@{/mojizahtevi}">Moji Zahtevi</a> <a class="dropdown-item" th:href="@{/mojizahtevi}">Moji Zahtevi</a>
<a th:if="${loggedUser.getKorisnik().getTipId() == 2}" class="dropdown-item" <a th:if="${loggedUser.getKorisnik().getTipId() == 2}" class="dropdown-item"
th:href="@{/lista-korisnika}">Lista Profila</a> th:href="@{/lista-korisnika}">Lista Profila</a>
......
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