Commit f42b1e89 by Mihailo Sebek

delete komentar by korisnikId i oglasId

parent 5d8aa8df
......@@ -2,10 +2,7 @@ package com.example.SkuciSe.controller;
import com.example.SkuciSe.model.korisnik.Korisnik;
import com.example.SkuciSe.model.korisnik.KorisnikDetails;
import com.example.SkuciSe.repository.KorisnikRepository;
import com.example.SkuciSe.repository.LokacijaRepository;
import com.example.SkuciSe.repository.OglasRepository;
import com.example.SkuciSe.repository.ZahtevRepository;
import com.example.SkuciSe.repository.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller;
......@@ -22,6 +19,8 @@ import java.util.List;
public class AdminController
{
@Autowired
KomentarRepository komRepo;
@Autowired
KorisnikRepository kRepo;
@Autowired
LokacijaRepository lRepo;
......@@ -50,6 +49,7 @@ public class AdminController
@PostMapping ("/delete-user/{id}")
public String deleteUser(@PathVariable("id") Integer id, @AuthenticationPrincipal KorisnikDetails loggedUser, Model model, RedirectAttributes redirectAttributes)
{
komRepo.deleteKomentariByKorisnikId(id);
zRepo.deleteZahteviByKorisnikId(id);
oRepo.deleteOglasi(id);
kRepo.deleteUser(id);
......
......@@ -57,4 +57,28 @@ public class KomentarRepository {
return( komentari);
}
public void deleteKomentariByKorisnikId(Integer id) throws RuntimeException
{
String sql = "{call deleteKomentarByKorisnikId(?)}";
CallableStatement stmt = null;
try {
stmt = dataBase.connection.prepareCall(sql);
stmt.setInt(1,id);
stmt.execute();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public void deleteKomentariByOglasId(Integer id) throws RuntimeException
{
String sql = "{call deleteKomentarByOglasId(?)}";
CallableStatement stmt = null;
try {
stmt = dataBase.connection.prepareCall(sql);
stmt.setInt(1,id);
stmt.execute();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
......@@ -15,6 +15,8 @@ import java.util.List;
public class OglasRepository
{
@Autowired
KomentarRepository komRepo;
@Autowired
DataBase dataBase;
public int insert( int korisnikId, Oglas newOglas, MultipartFile[] files)
......@@ -91,6 +93,7 @@ public class OglasRepository
while( rs.next())
{
int oglasid = rs.getInt("oglasid");
komRepo.deleteKomentariByOglasId(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