Ignore:
Timestamp:
02/03/24 18:08:44 (9 months ago)
Author:
Blazho <aleksandar.blazhevski@…>
Branches:
master
Children:
cab1b7d
Parents:
aea04dd
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/cookbook/controller/HomeController.java

    raea04dd rd4d8fb9  
    22
    33
    4 import com.example.cookbook.model.Komentar;
    5 import com.example.cookbook.model.Recept;
    6 import com.example.cookbook.model.Slika;
    7 import com.example.cookbook.model.Sostojka;
     4import com.example.cookbook.model.*;
    85import com.example.cookbook.model.exception.ReceptNeEPronajdenException;
    9 import com.example.cookbook.service.KomentariService;
    10 import com.example.cookbook.service.ReceptService;
    11 import com.example.cookbook.service.SlikiService;
    12 import com.example.cookbook.service.SostojkiService;
     6import com.example.cookbook.service.*;
    137import org.springframework.stereotype.Controller;
    148import org.springframework.ui.Model;
    159import org.springframework.web.bind.annotation.GetMapping;
    1610import org.springframework.web.bind.annotation.PathVariable;
     11import org.springframework.web.bind.annotation.PostMapping;
     12import org.springframework.web.bind.annotation.RequestParam;
    1713
    1814import java.sql.SQLException;
     15import java.time.LocalDateTime;
    1916import java.util.List;
    2017
     
    2926    private final KomentariService komentariService;
    3027
     28    private final KorisniciService korisniciService;
     29
    3130    public HomeController(ReceptService receptService,
    3231                          SlikiService slikiService,
    33                           SostojkiService sostojkiService, KomentariService komentariService) {
     32                          SostojkiService sostojkiService, KomentariService komentariService, KorisniciService korisniciService) {
    3433
    3534        this.receptService = receptService;
     
    3736        this.sostojkiService = sostojkiService;
    3837        this.komentariService = komentariService;
     38        this.korisniciService = korisniciService;
    3939    }
    4040
     
    5959        List<Sostojka> sostojki;
    6060        List<Komentar> komentari;
     61        List<Korisnik> posetiteli;
    6162        try {
    6263            recept = receptService.findById(id);
     
    6465            sostojki = sostojkiService.findAllById(id);
    6566            komentari = komentariService.findAllById(id);
     67            posetiteli = korisniciService.findAllByRole(TipKorisnik.Posetitel);
    6668        } catch (SQLException e) {
    6769            return "redirect:/error-page/SQL%20Exception";
     
    7375        model.addAttribute("sostojki", sostojki);
    7476        model.addAttribute("komentari", komentari);
     77        model.addAttribute("posetiteli", posetiteli);
    7578        return "recept";
     79    }
     80
     81    @PostMapping("/komentar/{id}")
     82    public String processKomentar(@PathVariable Long id,
     83                                  @RequestParam Integer ocena,
     84                                  @RequestParam String komentar,
     85                                  @RequestParam String telefon){
     86        if (id == null){
     87            return "redirect:/error-page/Ne%20dodavanje%20komentar(Identifikatorot%20na%20receptot%20ne%20postoi)";
     88        }
     89        try {
     90            komentariService.add(telefon, id, ocena, komentar);
     91        } catch (SQLException e) {
     92            return "redirect:/error-page/SQL%20Exception";
     93        }catch (IllegalArgumentException e){
     94            return "redirect:/error-page/Illegal%20Arguments";
     95        }
     96        return "redirect:/recept/" + id;
    7697    }
    7798
Note: See TracChangeset for help on using the changeset viewer.