source: Git/src/main/java/com/wediscussmovies/project/web/controller/ReplyController.java@ 3ded84d

main
Last change on this file since 3ded84d was 3ded84d, checked in by Test <matonikolov77@…>, 2 years ago

Model-database resolved bugs for mapping

  • Property mode set to 100644
File size: 1.5 KB
Line 
1package com.wediscussmovies.project.web.controller;
2
3import com.wediscussmovies.project.model.*;
4import com.wediscussmovies.project.service.ReplyService;
5import org.springframework.stereotype.Controller;
6import org.springframework.ui.Model;
7import org.springframework.web.bind.annotation.GetMapping;
8import org.springframework.web.bind.annotation.PathVariable;
9import org.springframework.web.bind.annotation.PostMapping;
10import org.springframework.web.bind.annotation.RequestParam;
11
12import java.util.Optional;
13
14@Controller
15public class ReplyController {
16 private final ReplyService replyService;
17
18 public ReplyController(ReplyService replyService) {
19 this.replyService = replyService;
20 }
21
22 @GetMapping("/edit/{id}")
23 public String getReplyEdit(@PathVariable Long id, Model model){
24 Optional<Reply> reply = replyService.findById(id);
25 if(reply.isEmpty())
26 return "redirect:/movies";
27 model.addAttribute("reply", reply.get());
28 model.addAttribute("templateContext", "replyEdit");
29 return "template";
30 }
31
32 @PostMapping("/edit/confirm/{id}")
33 public String getReplyEdit(@PathVariable Long id, @RequestParam String text){
34 Optional<Reply> replyOp = replyService.findById(id);
35 if(replyOp.isEmpty())
36 return "redirect:/discussions";
37 Reply reply = replyOp.get();
38 replyService.delete(reply);
39 reply.setText(text);
40 replyService.save(reply);
41 return "redirect:/discussions/"+reply.getDiscussionId();
42 }
43}
Note: See TracBrowser for help on using the repository browser.