Commit 8f6bc11a by Bogdan Andjelkovic

dodat AdminController

parent 8bb28e9c
package com.example.SkuciSe.controller;
import com.example.SkuciSe.model.korisnik.KorisnikDetails;
import com.example.SkuciSe.repository.KorisnikRepository;
import com.example.SkuciSe.repository.LokacijaRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class AdminController
{
@Autowired
KorisnikRepository kRepo;
@Autowired
LokacijaRepository lRepo;
@GetMapping("/lista-korisnika")
public String getListaKorisnika(Model model, @AuthenticationPrincipal KorisnikDetails loggedUser)
{
if( !kRepo.findRoleById( loggedUser.getKorisnik().getTipId()).equals( "Administrator") )
{
return "redirect:/index";
}
model.addAttribute("korisnici", kRepo.findAll());
model.addAttribute("loggedUser", loggedUser);
return "/lista-korisnika";
}
}
......@@ -7,7 +7,7 @@ import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.sql.*;
import java.util.Base64;
import java.util.*;
@Component
public class KorisnikRepository
......@@ -110,4 +110,21 @@ public class KorisnikRepository
}
return( null);
}
public List<Korisnik> findAll()
{
String sql = "select * from korisnik";
List<Korisnik> list = new ArrayList<Korisnik>();
ResultSet rs = null;
try {
rs = dataBase.statement.executeQuery(sql);
while (rs.next()) {
list.add(new Korisnik(rs.getInt("korisnikId"), rs.getString("ime"), rs.getString("prezime"), rs.getString("email"), rs.getString("sifra"), rs.getString("telefon"), rs.getString("slika"), rs.getInt("tipid"), rs.getInt("gradid")));
}
return list;
}
catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
......@@ -72,7 +72,7 @@
</div>
div class="col-md-12">
<div class="col-md-12">
<select th:field="${newUser.gradId}">
<option th:each="lokacija: ${lokacije}" th:value="${lokacija.getLokacijaId()}" th:text="${lokacija.getNaziv()}">
</option>
......
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