source: src/main/java/com/example/cookbook/repository/KorisniciRepository.java

Last change on this file was d4d8fb9, checked in by Blazho <aleksandar.blazhevski@…>, 9 months ago

Posetitelot komentira i dava ocena za recept(https://develop.finki.ukim.mk/projects/cbdb/wiki/useCase11)

  • Property mode set to 100644
File size: 1.6 KB
Line 
1package com.example.cookbook.repository;
2
3
4import com.example.cookbook.dbConfig.DB;
5import com.example.cookbook.model.Komentar;
6import com.example.cookbook.model.Korisnik;
7import com.example.cookbook.model.TipKorisnik;
8import org.springframework.stereotype.Repository;
9
10import java.sql.*;
11import java.time.LocalDateTime;
12import java.util.ArrayList;
13import java.util.List;
14
15@Repository
16public class KorisniciRepository {
17 public List<Korisnik> findAllByRole(TipKorisnik tipKorisnik) throws SQLException {
18 Connection connection = DB.getConnection();
19
20 String query;
21
22 if (tipKorisnik == TipKorisnik.Posetitel){
23 query = "select p.telefon, k.kor_ime, k.prezime\n" +
24 "from posetiteli p\n" +
25 " left join korisnici k on p.telefon = k.telefon";
26 } else {
27 query = "select v.telefon, k.kor_ime, k.prezime\n" +
28 "from vraboteni v\n" +
29 " left join korisnici k on v.telefon = k.telefon";
30 }
31
32 Statement stm = connection.createStatement();
33
34
35 ResultSet result = stm.executeQuery(query);
36 List<Korisnik> korisnici = new ArrayList<>();
37
38 while (result.next()){
39 Korisnik korisnik = new Korisnik();
40 korisnik.setTelefon(result.getString("telefon"));
41 korisnik.setIme(result.getString("kor_ime"));
42 korisnik.setPrezime(result.getString("prezime"));
43 korisnik.setTipKorisnik(tipKorisnik);
44 korisnici.add(korisnik);
45 }
46
47 result.close();
48 stm.close();
49 DB.closeConnection();
50
51 return korisnici;
52 }
53
54
55}
Note: See TracBrowser for help on using the repository browser.