Changeset a226bc3 for src/main/java/com
- Timestamp:
- 02/04/24 17:48:29 (9 months ago)
- Branches:
- master
- Parents:
- ee27685
- Location:
- src/main/java/com/example/cookbook
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/cookbook/controller/VrabotenController.java
ree27685 ra226bc3 2 2 3 3 4 import com.example.cookbook.model.DostavaDTO; 4 5 import com.example.cookbook.model.Naracka; 5 6 import com.example.cookbook.model.Recept; … … 43 44 @RequestParam LocalDateTime vreme, 44 45 Model model){ 45 46 List<DostavaDTO> podatoci = null; 46 47 List<Stavka> stavkiVoNaracka = null; 47 48 try { 48 49 stavkiVoNaracka = narcakiService.findByTelAndVreme(telefon, vreme); 50 podatoci = narcakiService.findDataForDostava(telefon, vreme); 49 51 } catch (SQLException e) { 50 52 return "redirect:/error-page/SQL%20Exception"; … … 52 54 53 55 model.addAttribute("stavki", stavkiVoNaracka); 56 model.addAttribute("podatoci", podatoci); 54 57 55 58 return "stavka"; -
src/main/java/com/example/cookbook/model/DostavaDTO.java
ree27685 ra226bc3 3 3 import java.time.LocalDateTime; 4 4 5 public record DostavaDTO (String recIme, String adresa, String sostojka , LocalDateTime vreme, String telefon){6 public DostavaDTO(String recIme, String adresa, String sostojka , LocalDateTime vreme, String telefon) {5 public record DostavaDTO (String recIme, String adresa, String sostojka){ 6 public DostavaDTO(String recIme, String adresa, String sostojka) { 7 7 this.recIme = recIme; 8 8 this.adresa = adresa; 9 9 this.sostojka = sostojka; 10 this.vreme = vreme;11 this.telefon = telefon;12 10 } 13 11 } -
src/main/java/com/example/cookbook/repository/NarackiRepository.java
ree27685 ra226bc3 3 3 4 4 import com.example.cookbook.dbConfig.DB; 5 import com.example.cookbook.model.DostavaDTO; 5 6 import com.example.cookbook.model.Naracka; 6 7 import com.example.cookbook.model.Recept; … … 65 66 return stavki; 66 67 } 68 69 public List<DostavaDTO> findDataForDostava(String telefon, LocalDateTime vreme) throws SQLException { 70 Connection connection = DB.getConnection(); 71 String query = "select r.rec_ime, l.adresa, 'Готово' sostojka from so_koi sk\n" + 72 " left join recepti r on\n" + 73 " r.rec_id = sk.rec_id\n" + 74 " left join opsluzuva o on\n" + 75 " o.rec_id = r.rec_id\n" + 76 " left join restorani r2 on\n" + 77 " r2.res_id = o.res_id\n" + 78 " left join se_naogja1 sn on\n" + 79 " sn.res_id = r2.res_id\n" + 80 " left join lokacii l on\n" + 81 " l.l_id = sn.l_id\n" + 82 " where vreme = ? and telefon = ? and sk.nacin = 'Готово'\n" + 83 "union\n" + 84 "select r.rec_ime, l.adresa, s2.s_naziv sostojka from so_koi sk\n" + 85 " left join recepti r on\n" + 86 " r.rec_id = sk.rec_id\n" + 87 " left join sodrzi s on\n" + 88 " r.rec_id = s.rec_id\n" + 89 " left join sostojki s2 on\n" + 90 " s2.s_id = s.s_id\n" + 91 " left join ja_ima ji on\n" + 92 " ji.s_id = s2.s_id\n" + 93 " left join prodavnici p on\n" + 94 " p.pro_id = ji.pro_id\n" + 95 " left join se_naogja2 sn on\n" + 96 " sn.pro_id = p.pro_id\n" + 97 " left join lokacii l on\n" + 98 " l.l_id = sn.l_id\n" + 99 " where vreme = ? and telefon = ? and sk.nacin = 'Состојки'"; 100 PreparedStatement prepStm = connection.prepareStatement(query); 101 102 prepStm.setObject(1, vreme); 103 prepStm.setString(2, telefon); 104 prepStm.setObject(3, vreme); 105 prepStm.setString(4, telefon); 106 107 ResultSet result = prepStm.executeQuery(); 108 109 List<DostavaDTO> dostavaDTOS = new ArrayList<>(); 110 while (result.next()){ 111 DostavaDTO stavka = new DostavaDTO( 112 result.getString("rec_ime"), 113 result.getString("adresa"), 114 result.getString("sostojka") 115 ); 116 117 dostavaDTOS.add(stavka); 118 } 119 DB.closeConnection(); 120 result.close(); 121 prepStm.close(); 122 return dostavaDTOS; 123 } 67 124 } -
src/main/java/com/example/cookbook/service/NarackiService.java
ree27685 ra226bc3 1 1 package com.example.cookbook.service; 2 2 3 import com.example.cookbook.model.DostavaDTO; 3 4 import com.example.cookbook.model.Naracka; 4 5 import com.example.cookbook.model.Recept; … … 14 15 15 16 List<Stavka> findByTelAndVreme(String telefon, LocalDateTime vreme) throws SQLException; 17 18 List<DostavaDTO> findDataForDostava(String telefon, LocalDateTime vreme) throws SQLException; 16 19 } -
src/main/java/com/example/cookbook/service/impl/NarackiServiceImpl.java
ree27685 ra226bc3 2 2 3 3 4 import com.example.cookbook.model.DostavaDTO; 4 5 import com.example.cookbook.model.Naracka; 5 6 import com.example.cookbook.model.Recept; … … 31 32 return narackiRepository.findByTelAndVreme(telefon, vreme); 32 33 } 34 35 @Override 36 public List<DostavaDTO> findDataForDostava(String telefon, LocalDateTime vreme) throws SQLException { 37 return narackiRepository.findDataForDostava(telefon, vreme); 38 } 33 39 }
Note:
See TracChangeset
for help on using the changeset viewer.