Commit 64b58b16 by Bogdan Andjelkovic

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

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