| 34859 |
vikas |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import com.spice.profitmandi.common.util.StringUtils;
|
|
|
4 |
import com.spice.profitmandi.dao.entity.Page;
|
|
|
5 |
import com.spice.profitmandi.dao.entity.dtr.WebListing;
|
|
|
6 |
import com.spice.profitmandi.dao.repository.dtr.WebListingRepository;
|
|
|
7 |
import com.spice.profitmandi.service.page.PageModel;
|
|
|
8 |
import com.spice.profitmandi.service.page.PageRepository;
|
|
|
9 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
10 |
import org.springframework.beans.factory.annotation.Value;
|
|
|
11 |
import org.springframework.http.ResponseEntity;
|
|
|
12 |
import org.springframework.stereotype.Controller;
|
|
|
13 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
14 |
|
|
|
15 |
import org.apache.logging.log4j.LogManager;
|
|
|
16 |
import org.apache.logging.log4j.Logger;
|
|
|
17 |
import org.springframework.ui.Model;
|
|
|
18 |
import org.springframework.web.bind.annotation.*;
|
|
|
19 |
|
|
|
20 |
import java.util.List;
|
|
|
21 |
import java.util.Optional;
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
@Controller
|
|
|
25 |
@RequestMapping("/pages")
|
|
|
26 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
27 |
public class PagesController {
|
|
|
28 |
private static final Logger LOGGER = LogManager.getLogger(PagesController.class);
|
|
|
29 |
|
|
|
30 |
@Value("${media.document.url}")
|
|
|
31 |
String imgURL;
|
|
|
32 |
|
|
|
33 |
@Autowired
|
|
|
34 |
PageRepository pageRepository;
|
|
|
35 |
|
|
|
36 |
@Autowired
|
|
|
37 |
WebListingRepository webListingRepository;
|
|
|
38 |
|
|
|
39 |
@GetMapping
|
|
|
40 |
public String pagesList(Model model){
|
|
|
41 |
try {
|
|
|
42 |
List<Page> pages = pageRepository.selectAll();
|
|
|
43 |
List<WebListing> webListing = webListingRepository.selectAllWebListing(Optional.ofNullable(null));
|
|
|
44 |
model.addAttribute("pages", pages);
|
|
|
45 |
model.addAttribute("imgURL", imgURL);
|
|
|
46 |
model.addAttribute("webListing", webListing);
|
|
|
47 |
} catch (Exception e) {
|
|
|
48 |
LOGGER.error("Catches Error", e);
|
|
|
49 |
model.addAttribute("pages", e.getMessage());
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
return "pages/index";
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
@GetMapping("/{id}")
|
|
|
56 |
public ResponseEntity<?> pageDetail(@PathVariable int id) throws Exception {
|
|
|
57 |
return ResponseEntity.ok(pageRepository.selectPageById(id));
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
@PostMapping
|
|
|
61 |
public ResponseEntity<?> createOrUpdate(@RequestBody PageModel pageModel) throws Exception {
|
|
|
62 |
Page page = pageModel.getId() > 0 ? pageRepository.selectPageById(pageModel.getId()) : new Page();
|
|
|
63 |
|
|
|
64 |
page.setTitle(pageModel.getTitle());
|
|
|
65 |
page.setVisibleOn(pageModel.getVisibleOn());
|
|
|
66 |
page.setSectionData(pageModel.getSectionData());
|
|
|
67 |
page.setSectionOrder(pageModel.getSectionOrder());
|
|
|
68 |
page.setSectionBelow(pageModel.getSectionBelow());
|
|
|
69 |
page.setSectionGroup(pageModel.getSectionGroup());
|
|
|
70 |
page.setTabTitle(pageModel.getTabTitle());
|
|
|
71 |
page.setStatus(pageModel.isStatus());
|
|
|
72 |
|
|
|
73 |
if (pageModel.getId() == 0){
|
|
|
74 |
page.setSlug(StringUtils.toSlug(pageModel.getTitle()));
|
|
|
75 |
pageRepository.persist(page);
|
|
|
76 |
}
|
|
|
77 |
return ResponseEntity.ok(true);
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
@DeleteMapping("/{id}")
|
|
|
81 |
public String deleteSuperCatalog(@PathVariable int id, Model model) throws Exception {
|
|
|
82 |
pageRepository.deleteById(id);
|
|
|
83 |
model.addAttribute("response1", true);
|
|
|
84 |
return "response";
|
|
|
85 |
}
|
|
|
86 |
}
|