Advertisement
Tsyklop

Spring RestController JSON

Jul 28th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. RestController
  2. @Secured("hasRole('ADMIN')")
  3. @RequestMapping(value = "/api/v1")
  4. public class ApiController {
  5.  
  6. @Autowired
  7. private PageService pageService;
  8.  
  9. @Autowired
  10. private ImageService imageService;
  11.  
  12. @Autowired
  13. private ConfigService configService;
  14.  
  15. @Autowired
  16. private CategoryService categoryService;
  17.  
  18. @Autowired
  19. private UploadFileService uploadFileService;
  20.  
  21. private static final Logger LOGGER = LogManager.getLogger(ApiController.class);
  22.  
  23. @PostMapping(value = "/categories/load", produces = MediaType.APPLICATION_JSON_VALUE)
  24. private Response categoriesLoad(Response response) {
  25. response.setSuccess("OK");
  26. response.addData("categories", categoryService.getAll());
  27. return response;
  28. }
  29.  
  30. @PostMapping(value = "/category/add", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
  31. private Response categoryAdd(Response response, CategoryAddForm categoryFormAdd) {
  32. categoryService.add(response, categoryFormAdd);
  33. return response;
  34. }
  35.  
  36. @PostMapping(value = "/category/info", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
  37. private Response categoryInfo(Response response, @RequestParam("categoryId") Integer categoryId) {
  38. categoryService.info(response, categoryId);
  39. return response;
  40. }
  41.  
  42. @PostMapping(value = "/category/save", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
  43. private Response categorySave(Response response, CategorySaveForm categorySaveForm) {
  44. categoryService.save(response, categorySaveForm);
  45. return response;
  46. }
  47.  
  48. @PostMapping(value = "/category/remove", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
  49. private Response categoryRemove(Response response, @RequestParam("categoryId") Integer categoryId) {
  50. categoryService.remove(response, categoryId);
  51. return response;
  52. }
  53.  
  54. @PostMapping(value = "/category/load", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
  55. private Response categoryLoad(Response response, CategoryLoadForm categoryLoad) {
  56. categoryService.load(response, categoryLoad);
  57. return response;
  58. }
  59.  
  60. @PostMapping(value = "/image/add", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
  61. private Response imageAdd(Response response, ImageAddForm imageAddForm) {
  62. imageService.add(response, imageAddForm);
  63. return response;
  64. }
  65.  
  66. @PostMapping(value = "/page/add", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
  67. private Response pageAdd(Response response, PageAddForm pageAddForm) {
  68. pageService.add(response, pageAddForm);
  69. return response;
  70. }
  71.  
  72. @PostMapping(value = "/upload/image", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
  73. private Response uploadImage(Response response, @RequestParam("file") MultipartFile file, HttpServletRequest request) {
  74. uploadFileService.upload(response, file);
  75. return response;
  76. }
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement