Commit 75ec918a by Bogdan Andjelkovic

dodate klase slika i slikarepository i slanje slika na front za oglas

parent 5babace6
...@@ -6,6 +6,7 @@ import com.example.SkuciSe.model.oglas.Oglas; ...@@ -6,6 +6,7 @@ import com.example.SkuciSe.model.oglas.Oglas;
import com.example.SkuciSe.repository.KorisnikRepository; import com.example.SkuciSe.repository.KorisnikRepository;
import com.example.SkuciSe.repository.LokacijaRepository; import com.example.SkuciSe.repository.LokacijaRepository;
import com.example.SkuciSe.repository.OglasRepository; import com.example.SkuciSe.repository.OglasRepository;
import com.example.SkuciSe.repository.SlikeRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
...@@ -28,6 +29,9 @@ public class OglasController ...@@ -28,6 +29,9 @@ public class OglasController
@Autowired @Autowired
OglasRepository oRepo; OglasRepository oRepo;
@Autowired
SlikeRepository sRepo;
@GetMapping("/novi-oglas") @GetMapping("/novi-oglas")
public String getNoviOglas(Model model, @AuthenticationPrincipal KorisnikDetails loggedUser) public String getNoviOglas(Model model, @AuthenticationPrincipal KorisnikDetails loggedUser)
{ {
...@@ -65,9 +69,9 @@ public class OglasController ...@@ -65,9 +69,9 @@ public class OglasController
@GetMapping("/lista-oglasa/{oglasId}") @GetMapping("/lista-oglasa/{oglasId}")
public String getOglas(Model model, @PathVariable("oglasId") int oglasId, @AuthenticationPrincipal KorisnikDetails loggedUser) public String getOglas(Model model, @PathVariable("oglasId") int oglasId, @AuthenticationPrincipal KorisnikDetails loggedUser)
{ {
System.out.println( oglasId);
model.addAttribute("loggedUser", loggedUser); model.addAttribute("loggedUser", loggedUser);
model.addAttribute("oglas", oRepo.findById( oglasId)); model.addAttribute("oglas", oRepo.findById( oglasId));
model.addAttribute("slike", sRepo.findAllById( oglasId));
return("oglas"); return("oglas");
} }
} }
package com.example.SkuciSe.model.slika;
import lombok.*;
@Getter
@Setter
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class Slika
{
int slikaId;
int oglasId;
String slikaCode;
}
package com.example.SkuciSe.repository;
import com.example.SkuciSe.model.slika.Slika;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@Component
public class SlikeRepository
{
@Autowired
DataBase dataBase;
public List<Slika> findAllById( int oglasId)
{
List<Slika> list = new ArrayList<Slika>();
String sql = "select * from slike where oglasid = " + oglasId;
ResultSet rs = null;
try {
rs = dataBase.statement.executeQuery( sql);
while( rs.next())
{
list.add( new Slika( rs.getInt("slikeId"), rs.getInt("oglasid"), rs.getString("slika") ));
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return list;
}
}
...@@ -91,6 +91,8 @@ ...@@ -91,6 +91,8 @@
<div class="container" th:object="${oglas}"> <div class="container" th:object="${oglas}">
<h1 th:text="${oglas.toString()}"></h1> <h1 th:text="${oglas.toString()}"></h1>
</div> </div>
<div class="container" th:object="${slike}">
</div>
<div class="container-fluid pb-0 mb-0 justify-content-center text-light "> <div class="container-fluid pb-0 mb-0 justify-content-center text-light ">
<footer> <footer>
......
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