- Timestamp:
- 02/04/24 17:12:57 (9 months ago)
- Branches:
- master
- Children:
- a226bc3
- Parents:
- cab1b7d
- Location:
- src/main
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/cookbook/controller/VrabotenController.java
rcab1b7d ree27685 3 3 4 4 import com.example.cookbook.model.Naracka; 5 import com.example.cookbook.model.Recept; 6 import com.example.cookbook.model.Stavka; 5 7 import com.example.cookbook.service.NarackiService; 6 8 import org.springframework.stereotype.Controller; 7 9 import org.springframework.ui.Model; 8 10 import org.springframework.web.bind.annotation.GetMapping; 11 import org.springframework.web.bind.annotation.PostMapping; 12 import org.springframework.web.bind.annotation.RequestParam; 9 13 10 14 import java.sql.SQLException; 15 import java.time.LocalDateTime; 11 16 import java.util.List; 12 17 … … 33 38 return "naracki"; 34 39 } 40 41 @GetMapping("/naracki/naracka") 42 public String getNarackaPage(@RequestParam String telefon, 43 @RequestParam LocalDateTime vreme, 44 Model model){ 45 46 List<Stavka> stavkiVoNaracka = null; 47 try { 48 stavkiVoNaracka = narcakiService.findByTelAndVreme(telefon, vreme); 49 } catch (SQLException e) { 50 return "redirect:/error-page/SQL%20Exception"; 51 } 52 53 model.addAttribute("stavki", stavkiVoNaracka); 54 55 return "stavka"; 56 } 35 57 } -
src/main/java/com/example/cookbook/model/Komentar.java
rcab1b7d ree27685 87 87 88 88 public String getDataFormatirana(){ 89 return komData.format(DateTimeFormatter.ofPattern("yyyy-MM -dd HH:mm"));89 return komData.format(DateTimeFormatter.ofPattern("yyyy-MMM-dd HH:mm")); 90 90 } 91 91 } -
src/main/java/com/example/cookbook/repository/NarackiRepository.java
rcab1b7d ree27685 4 4 import com.example.cookbook.dbConfig.DB; 5 5 import com.example.cookbook.model.Naracka; 6 import com.example.cookbook.model.Recept; 7 import com.example.cookbook.model.Stavka; 6 8 import org.springframework.stereotype.Repository; 7 9 8 import java.sql.Connection; 9 import java.sql.ResultSet; 10 import java.sql.SQLException; 11 import java.sql.Statement; 10 import java.sql.*; 12 11 import java.time.LocalDateTime; 13 12 import java.util.ArrayList; … … 39 38 return naracki; 40 39 } 40 41 public List<Stavka> findByTelAndVreme(String telefon, LocalDateTime vreme) throws SQLException { 42 43 Connection connection = DB.getConnection(); 44 String query = "select sk.vreme, sk.telefon, r.rec_ime, nacin from so_koi sk\n" + 45 " left join recepti r on r.rec_id = sk.rec_id\n" + 46 "where vreme = ? and telefon = ?;"; 47 PreparedStatement prepStm = connection.prepareStatement(query); 48 49 prepStm.setObject(1, vreme); 50 prepStm.setString(2, telefon); 51 52 ResultSet result = prepStm.executeQuery(); 53 List<Stavka> stavki = new ArrayList<>(); 54 while (result.next()){ 55 Stavka stavka = new Stavka(); 56 stavka.setRecIme(result.getString("rec_ime")); 57 stavka.setTelefon(result.getString("telefon")); 58 stavka.setNacin(result.getString("nacin")); 59 stavka.setVreme(result.getObject("vreme", LocalDateTime.class)); 60 stavki.add(stavka); 61 } 62 DB.closeConnection(); 63 result.close(); 64 prepStm.close(); 65 return stavki; 66 } 41 67 } -
src/main/java/com/example/cookbook/service/NarackiService.java
rcab1b7d ree27685 2 2 3 3 import com.example.cookbook.model.Naracka; 4 import com.example.cookbook.model.Recept; 5 import com.example.cookbook.model.Stavka; 4 6 5 7 import java.sql.SQLException; 8 import java.time.LocalDateTime; 6 9 import java.util.List; 7 10 … … 9 12 10 13 List<Naracka> listAll() throws SQLException; 14 15 List<Stavka> findByTelAndVreme(String telefon, LocalDateTime vreme) throws SQLException; 11 16 } -
src/main/java/com/example/cookbook/service/impl/NarackiServiceImpl.java
rcab1b7d ree27685 3 3 4 4 import com.example.cookbook.model.Naracka; 5 import com.example.cookbook.model.Recept; 6 import com.example.cookbook.model.Stavka; 5 7 import com.example.cookbook.repository.NarackiRepository; 6 8 import com.example.cookbook.service.NarackiService; … … 8 10 9 11 import java.sql.SQLException; 12 import java.time.LocalDateTime; 10 13 import java.util.List; 11 14 … … 23 26 return narackiRepository.findAll(); 24 27 } 28 29 @Override 30 public List<Stavka> findByTelAndVreme(String telefon, LocalDateTime vreme) throws SQLException { 31 return narackiRepository.findByTelAndVreme(telefon, vreme); 32 } 25 33 } -
src/main/resources/templates/naracki.html
rcab1b7d ree27685 48 48 <td th:text="${naracka.telefon}"></td> 49 49 <td> 50 <form th:method=" POST" th:action="@{/naracki/naracka}">50 <form th:method="GET" th:action="@{/naracki/naracka}"> 51 51 <input type="datetime-local" hidden th:value="${naracka.vreme}" th:name="vreme"> 52 52 <input type="text" hidden th:value="${naracka.telefon}" th:name="telefon">
Note:
See TracChangeset
for help on using the changeset viewer.