Commit 12b14a2e by Bogdan Andjelkovic

komentari vlasnika, stranica korisnika sa njegovim oglasima i komentarima

parent beca7ae7
...@@ -30,7 +30,8 @@ public class AdminController ...@@ -30,7 +30,8 @@ public class AdminController
ZahtevRepository zRepo; ZahtevRepository zRepo;
@Autowired @Autowired
LajkRepository lajkRepo; LajkRepository lajkRepo;
@Autowired
KomentarVlasnikRepository komentarVlasnikRepo;
@GetMapping("/lista-korisnika") @GetMapping("/lista-korisnika")
public String getListaKorisnika(Model model, @AuthenticationPrincipal KorisnikDetails loggedUser) public String getListaKorisnika(Model model, @AuthenticationPrincipal KorisnikDetails loggedUser)
{ {
...@@ -38,12 +39,12 @@ public class AdminController ...@@ -38,12 +39,12 @@ public class AdminController
{ {
return "redirect:/index"; return "redirect:/index";
} }
model.addAttribute("korisnici", kRepo.findAll());
model.addAttribute("loggedUser", loggedUser);
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<String>();
for (Korisnik k:kRepo.findAll()) { for (Korisnik k:kRepo.findAll()) {
list.add(kRepo.findCity(k.getGradId())); list.add(kRepo.findCity(k.getGradId()));
} }
model.addAttribute("korisnici", kRepo.findAll());
model.addAttribute("loggedUser", loggedUser);
model.addAttribute("gradovi", list); model.addAttribute("gradovi", list);
return "lista-korisnika"; return "lista-korisnika";
} }
...@@ -51,6 +52,7 @@ public class AdminController ...@@ -51,6 +52,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)
{ {
komentarVlasnikRepo.deleteKomentarVlasnikByKorisnikId( id);
komRepo.deleteKomentariByKorisnikId(id); komRepo.deleteKomentariByKorisnikId(id);
zRepo.deleteZahteviByKorisnikId(id); zRepo.deleteZahteviByKorisnikId(id);
lajkRepo.deleteLajkByKorisnikId(id); lajkRepo.deleteLajkByKorisnikId(id);
......
package com.example.SkuciSe.controller; package com.example.SkuciSe.controller;
import com.example.SkuciSe.repository.KomentarRepository; import com.example.SkuciSe.repository.KomentarRepository;
import com.example.SkuciSe.repository.KomentarVlasnikRepository;
import com.example.SkuciSe.repository.ZahtevRepository; import com.example.SkuciSe.repository.ZahtevRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
...@@ -13,13 +14,15 @@ public class KomentarController { ...@@ -13,13 +14,15 @@ public class KomentarController {
KomentarRepository komentarRepo; KomentarRepository komentarRepo;
@Autowired @Autowired
ZahtevRepository zRepo; ZahtevRepository zRepo;
@Autowired
KomentarVlasnikRepository komentarVlasnikRepo;
@GetMapping("/profile/moji-zahtevi/sacuvaj-komentar") @GetMapping("/profile/moji-zahtevi/sacuvaj-komentar")
public String postSacuvajKomentar(@RequestParam("korisnikId") int korisnikId, public String postSacuvajKomentar(@RequestParam("korisnikId") int korisnikId,
@RequestParam("oglasId") int oglasId, @RequestParam("oglasId") int oglasId,
@RequestParam("zahtevId") int zahtevId, @RequestParam("zahtevId") int zahtevId,
@RequestParam("ocenaRadio") int ocenaRadio, @RequestParam("ocenaRadio") int ocenaRadio,
@RequestParam("komentar") String text) { @RequestParam("komentar") String text)
{
try { try {
komentarRepo.insert(korisnikId, oglasId, text, ocenaRadio); komentarRepo.insert(korisnikId, oglasId, text, ocenaRadio);
zRepo.deleteZahtev(zahtevId); zRepo.deleteZahtev(zahtevId);
...@@ -28,4 +31,18 @@ public class KomentarController { ...@@ -28,4 +31,18 @@ public class KomentarController {
} }
return ("redirect:/profile/moji-zahtevi"); return ("redirect:/profile/moji-zahtevi");
} }
@GetMapping("/oceni-korisnika")
public String getOceniKorisnika(@RequestParam("vlasnikId") int vlasnikId,
@RequestParam("korisnikId") int korisnikId,
@RequestParam("ocenaRadio") int ocenaRadio,
@RequestParam("komentar") String text)
{
try {
komentarVlasnikRepo.insert( vlasnikId, korisnikId, ocenaRadio, text);
} catch (Exception e) {
throw new RuntimeException(e);
}
return ("redirect:/profile/moji-zahtevi");
}
} }
...@@ -112,10 +112,6 @@ public class OglasController ...@@ -112,10 +112,6 @@ public class OglasController
{ {
model.addAttribute("loggedUser", loggedUser); model.addAttribute("loggedUser", loggedUser);
List<Oglas> listaOglasa = oRepo.findAll( vrstaOglasaId, lokacijaId, brojSoba, cenaMin, cenaMax, kvadraturaMin,kvadraturaMax, lift, grejanje, namesten, pretraga); List<Oglas> listaOglasa = oRepo.findAll( vrstaOglasaId, lokacijaId, brojSoba, cenaMin, cenaMax, kvadraturaMin,kvadraturaMax, lift, grejanje, namesten, pretraga);
while(listaOglasa.size() % 3 != 0){
Oglas o = new Oglas();
listaOglasa.add(o);
}
model.addAttribute("oglasi",listaOglasa); model.addAttribute("oglasi",listaOglasa);
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<String>();
for (Oglas o:listaOglasa) { for (Oglas o:listaOglasa) {
...@@ -144,10 +140,6 @@ public class OglasController ...@@ -144,10 +140,6 @@ public class OglasController
{ {
model.addAttribute("loggedUser", loggedUser); model.addAttribute("loggedUser", loggedUser);
List<Oglas> listaOglasa = oRepo.findAllByKorisnikId( loggedUser.getKorisnik().getKorisnikId(), vrstaOglasaId, lokacijaId, brojSoba, cenaMin, cenaMax, kvadraturaMin,kvadraturaMax, lift, grejanje, namesten, pretraga); List<Oglas> listaOglasa = oRepo.findAllByKorisnikId( loggedUser.getKorisnik().getKorisnikId(), vrstaOglasaId, lokacijaId, brojSoba, cenaMin, cenaMax, kvadraturaMin,kvadraturaMax, lift, grejanje, namesten, pretraga);
while(listaOglasa.size() % 3 != 0){
Oglas o = new Oglas();
listaOglasa.add(o);
}
model.addAttribute("oglasi",listaOglasa); model.addAttribute("oglasi",listaOglasa);
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<String>();
for (Oglas o:listaOglasa) { for (Oglas o:listaOglasa) {
......
package com.example.SkuciSe.controller; package com.example.SkuciSe.controller;
import com.example.SkuciSe.model.komentar.Komentar;
import com.example.SkuciSe.model.komentar.KomentarVlasnik;
import com.example.SkuciSe.model.korisnik.Korisnik; 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.model.oglas.Oglas;
import com.example.SkuciSe.repository.LokacijaRepository; import com.example.SkuciSe.repository.*;
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;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Base64; import java.util.Base64;
import java.util.List;
@Controller @Controller
public class ProfileController public class ProfileController
...@@ -26,6 +27,16 @@ public class ProfileController ...@@ -26,6 +27,16 @@ public class ProfileController
@Autowired @Autowired
LokacijaRepository lRepo; LokacijaRepository lRepo;
@Autowired
OglasRepository oRepo;
@Autowired
SlikeRepository sRepo;
@Autowired
KomentarRepository komRepo;
@Autowired
KomentarVlasnikRepository komentarVlasnikRepo;
@GetMapping("/profile") @GetMapping("/profile")
public String getProfile(Model model, @AuthenticationPrincipal KorisnikDetails loggedUser) public String getProfile(Model model, @AuthenticationPrincipal KorisnikDetails loggedUser)
{ {
...@@ -79,4 +90,24 @@ public class ProfileController ...@@ -79,4 +90,24 @@ public class ProfileController
loggedUser.setKorisnikSifra( korisnik.getSifra()); loggedUser.setKorisnikSifra( korisnik.getSifra());
return "redirect:/profile"; return "redirect:/profile";
} }
@GetMapping("/korisnik/{korisnikId}")
public String getKorisnik(Model model, @AuthenticationPrincipal KorisnikDetails loggedUser, @PathVariable("korisnikId") int korisnikId)
{
model.addAttribute("loggedUser", loggedUser);
model.addAttribute("korisnik", kRepo.findById( korisnikId));
List<Oglas> oglasi = oRepo.findAllByKorisnikId(korisnikId,null,null,null,null,null,null,null,null,null,null,null);
model.addAttribute("oglasi", oglasi);
model.addAttribute("slikeOglasa", sRepo.findAllFirstPics(oglasi));
model.addAttribute("korisniciKomentari", komentarVlasnikRepo.findAllKomentarVlasnikByKorisnikID( korisnikId));
List<KomentarVlasnik> komentari = komentarVlasnikRepo.findAllKomentarVlasnikByKorisnikID( korisnikId);
List<Korisnik> korisniciKomentari = new ArrayList<Korisnik>();
for( KomentarVlasnik komentar: komentari)
{
korisniciKomentari.add( kRepo.findById( komentar.getVlasnikId()));
}
model.addAttribute("komentari", komentari);
model.addAttribute("korisniciKomentari", korisniciKomentari);
return "korisnik";
}
} }
package com.example.SkuciSe.model.komentar;
import lombok.*;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class KomentarVlasnik
{
private int komentarVlasnikId;
private int vlasnikId;
private int korisnikId;
private int ocena;
private String komentar;
private String datum;
private String vreme;
}
package com.example.SkuciSe.repository;
import com.example.SkuciSe.model.komentar.Komentar;
import com.example.SkuciSe.model.komentar.KomentarVlasnik;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@Component
public class KomentarVlasnikRepository
{
@Autowired
DataBase dataBase;
public void insert(int vlasnikId, int korisnikId, int ocenaRadio, String text)
{
CallableStatement stmt = null;
ResultSet rs = null;
try {
String sql = "{call insertKomentarVlasnik(?,?,?,?)}";
stmt = dataBase.connection.prepareCall(sql);
stmt.setInt(1, vlasnikId);
stmt.setInt(2,korisnikId);
stmt.setInt(3,ocenaRadio);
stmt.setString(4,text);
stmt.execute();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public List<KomentarVlasnik> findAllKomentarVlasnikByKorisnikID(int korisnikId)
{
List<KomentarVlasnik> komentari = new ArrayList<KomentarVlasnik>();
CallableStatement cs = null;
String sql = "{ call findAllKomentarVlasnikByKorisnikID(?)}";
ResultSet rs = null;
try {
cs = dataBase.connection.prepareCall( sql);
cs.setInt( 1, korisnikId);
rs = cs.executeQuery();
while( rs.next())
{
komentari.add( new KomentarVlasnik( rs.getInt(1),rs.getInt(2),rs.getInt(3),rs.getInt(4),rs.getString(5),rs.getString(6),rs.getString(7)));
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return( komentari);
}
public void deleteKomentarVlasnikByKorisnikId(Integer id) throws RuntimeException
{
String sql = "{call deleteKomentarVlasnikByKorisnikId(?)}";
CallableStatement stmt = null;
try {
stmt = dataBase.connection.prepareCall(sql);
stmt.setInt(1,id);
stmt.execute();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
...@@ -188,6 +188,10 @@ public class OglasRepository ...@@ -188,6 +188,10 @@ public class OglasRepository
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
while(list.size() % 3 != 0){
Oglas o = new Oglas();
list.add(o);
}
return( list); return( list);
} }
...@@ -229,6 +233,10 @@ public class OglasRepository ...@@ -229,6 +233,10 @@ public class OglasRepository
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
while(list.size() % 3 != 0){
Oglas o = new Oglas();
list.add(o);
}
return( list); return( list);
} }
} }
\ No newline at end of file
...@@ -299,6 +299,15 @@ ...@@ -299,6 +299,15 @@
</p> </p>
</div> </div>
</div> </div>
<div class="col-md-3 d-flex flex-column justify-content-around align-items-center">
<form method="get" th:action="@{/oceni-korisnika}">
<input type="text" th:value="${loggedUser.korisnik.korisnikId}" name="vlasnikId" style="display: none">
<input type="text" th:value="${korisnik.korisnikId}" name="korisnikId" style="display: none">
<input type="number" name="ocenaRadio"><br>
<input type="text" name="komentar"><br>
<button type="submit">Oceni</button>
</form>
</div>
<div class="col-md-2 d-flex flex-column justify-content-around align-items-center" <div class="col-md-2 d-flex flex-column justify-content-around align-items-center"
th:if="${zahtevi[korisnikStat.count - 1].status.toString() == 'CEKANJE'}"> th:if="${zahtevi[korisnikStat.count - 1].status.toString() == 'CEKANJE'}">
<form method="GET" <form method="GET"
......
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