Commit d23f1a44 by Bogdan Andjelkovic

brisanje korisnika brise zahteve

parent a8158d86
......@@ -41,7 +41,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/profile/**","/moji-oglasi/**","/profile/moji-zahtevi/**","/lista-korisnika","/novi-oglas/**").authenticated()
.antMatchers("/profile/**","/moji-oglasi/**","/login-zahtev/**","/lista-korisnika","/novi-oglas/**").authenticated()
.anyRequest().permitAll()
.and().formLogin().loginPage("/login").permitAll()
.usernameParameter("email")
......
......@@ -5,6 +5,7 @@ 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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller;
......@@ -26,6 +27,8 @@ public class AdminController
LokacijaRepository lRepo;
@Autowired
OglasRepository oRepo;
@Autowired
ZahtevRepository zRepo;
@GetMapping("/lista-korisnika")
public String getListaKorisnika(Model model, @AuthenticationPrincipal KorisnikDetails loggedUser)
......@@ -45,7 +48,9 @@ public class AdminController
}
@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)
{
zRepo.deleteZahteviByKorisnikId(id);
oRepo.deleteOglasi(id);
kRepo.deleteUser(id);
redirectAttributes.addFlashAttribute("deleted", true);
......
......@@ -35,4 +35,11 @@ public class ZahtevController {
zRepo.insert( loggedUser.getKorisnik().getKorisnikId(), oglasId, noviZahtev, datumIVreme);
return "redirect:/lista-oglasa/"+oglasId;
}
@GetMapping("/login-zahtev/{oglasId}")
public String getLoginZahtev( @PathVariable("oglasId") int oglasId)
{
return "redirect:/lista-oglasa/"+oglasId;
}
}
......@@ -92,6 +92,7 @@ public class OglasRepository
{
int oglasid = rs.getInt("oglasid");
this.deleteSlike( oglasid);
this.deleteZahteviByOglasId( oglasid);
}
} catch (SQLException e) {
throw new RuntimeException(e);
......@@ -120,6 +121,19 @@ public class OglasRepository
}
}
public void deleteZahteviByOglasId(Integer id)
{
String sql = "{call deleteZahteviByOglasId(?)}";
CallableStatement cs = null;
try {
cs = dataBase.connection.prepareCall(sql);
cs.setInt(1, id);
cs.execute();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public List<Oglas> findAll(Integer vrstaOglasaId, Integer lokacijaId, Integer brojSoba, Double cenaMin, Double cenaMax, Double kvadraturaMin, Double kvadraturaMax, Boolean lift, Boolean grejanje, Boolean namesten, String pretraga)
{
List<Oglas> list = new ArrayList<Oglas>();
......
......@@ -19,7 +19,6 @@ public class ZahtevRepository {
public void insert( int korisnikId, int oglasId, Zahtev noviZahtev, String datumIVreme)
{
String datum = datumIVreme.split(" ")[0];
System.out.println(datum);
LocalDate datumFormatiran = LocalDate.parse(datum, DateTimeFormatter.ofPattern("MM/dd/yyyy"));
String vreme = datumIVreme.split(" ")[1];
noviZahtev.setDatum( datumFormatiran.toString());
......@@ -56,7 +55,6 @@ public class ZahtevRepository {
while( rs.next())
{
Zahtev zahtev = new Zahtev( rs.getInt(1), rs.getInt(2), rs.getInt(3), rs.getString(4), rs.getString(5), StanjeZahteva.valueOf(rs.getString(6)));
System.out.println( zahtev.toString());
list.add( zahtev);
}
} catch (SQLException e) {
......@@ -78,7 +76,6 @@ public class ZahtevRepository {
while( rs.next())
{
Zahtev zahtev = new Zahtev( rs.getInt(1), rs.getInt(2), rs.getInt(3), rs.getString(4), rs.getString(5), StanjeZahteva.valueOf(rs.getString(6)));
System.out.println( zahtev.toString());
list.add( zahtev);
}
} catch (SQLException e) {
......@@ -86,4 +83,17 @@ public class ZahtevRepository {
}
return( list);
}
public void deleteZahteviByKorisnikId(Integer id)
{
String sql = "{call deleteZahteviByKorisnikId(?)}";
CallableStatement cs = null;
try {
cs = dataBase.connection.prepareCall(sql);
cs.setInt(1, id);
cs.execute();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
......@@ -186,7 +186,7 @@
</div>
<button type="submit" class="btn btn-primary w-25">POSALJI ZAHTEV</button>
</form>
<h3 th:if="${loggedUser == null}" class="text-center"><a th:href="@{/login}" style="text-decoration: none;color:#495056;">Prijavite se</a></h3>
<h3 th:if="${loggedUser == null}" class="text-center"><a th:href="@{/login-zahtev/{oglasId}(oglasId=${oglasId})}" style="text-decoration: none;color:#495056;">Prijavite se</a></h3>
</div>
</div>
</div>
......
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