Commit 64b58b16 by Bogdan Andjelkovic

lajkovanje uradjeno, brisanje, cuvanje - back ( ostao jos front)

parent 38799f7a
......@@ -28,6 +28,8 @@ public class AdminController
OglasRepository oRepo;
@Autowired
ZahtevRepository zRepo;
@Autowired
LajkRepository lajkRepo;
@GetMapping("/lista-korisnika")
public String getListaKorisnika(Model model, @AuthenticationPrincipal KorisnikDetails loggedUser)
......@@ -51,6 +53,7 @@ public class AdminController
{
komRepo.deleteKomentariByKorisnikId(id);
zRepo.deleteZahteviByKorisnikId(id);
lajkRepo.deleteLajkByKorisnikId(id);
oRepo.deleteOglasi(id);
kRepo.deleteUser(id);
redirectAttributes.addFlashAttribute("deleted", true);
......
......@@ -4,10 +4,10 @@ import com.example.SkuciSe.model.komentar.Lajk;
import com.example.SkuciSe.model.korisnik.KorisnikDetails;
import com.example.SkuciSe.repository.LajkRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.Banner;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -16,7 +16,7 @@ public class LajkController
{
@Autowired
LajkRepository lajkRepo;
@PostMapping("/lista-oglasa/{oglasId}/lajkuj-oglas")
@GetMapping("/lista-oglasa/{oglasId}/lajkuj-oglas")
public String postLajkujOglas(Model model, @AuthenticationPrincipal KorisnikDetails loggedUser, @PathVariable("oglasId") int oglasId)
{
lajkRepo.updateLajk( new Lajk( oglasId, loggedUser.getKorisnik().getKorisnikId()));
......
......@@ -119,8 +119,11 @@ public class OglasController
}
model.addAttribute("korisniciKomentari", korisniciKomentari);
model.addAttribute("liked", lajkRepo.isLiked( new Lajk(oglasId, loggedUser.getKorisnik().getKorisnikId())));
model.addAttribute("likesCount", lajkRepo.countLajks(oglasId));
if( loggedUser!=null)
{
model.addAttribute("liked", lajkRepo.isLiked( new Lajk(oglasId, loggedUser.getKorisnik().getKorisnikId())));
model.addAttribute("likesCount", lajkRepo.countLajks(oglasId));
}
return("oglas");
}
@GetMapping("/profile/moji-oglasi")
......
......@@ -9,6 +9,6 @@ import lombok.*;
@ToString
public class Lajk
{
private int korisnikId;
private int oglasId;
private int korisnikId;
}
......@@ -25,10 +25,12 @@ public class LajkRepository {
{
if(this.isLiked(lajk))
{
System.out.println("delete "+ lajk.toString());
this.deleteLajk(lajk);
}
else
{
System.out.println("insert "+ lajk.toString());
this.insertLajk(lajk);
}
}
......
......@@ -18,6 +18,8 @@ public class OglasRepository
KomentarRepository komRepo;
@Autowired
DataBase dataBase;
@Autowired
LajkRepository lajkRepo;
public int insert( int korisnikId, Oglas newOglas, MultipartFile[] files)
{
......@@ -94,6 +96,7 @@ public class OglasRepository
{
int oglasid = rs.getInt("oglasid");
komRepo.deleteKomentariByOglasId(oglasid);
lajkRepo.deleteLajkByOglasId(oglasid);
this.deleteSlike( oglasid);
this.deleteZahteviByOglasId( oglasid);
}
......
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