PromotionController.java 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package com.oms.controller;
  2. import com.oms.dto.PromotionDTO;
  3. import com.oms.entity.Promotion;
  4. import com.oms.service.PromotionService;
  5. import lombok.RequiredArgsConstructor;
  6. import org.springframework.web.bind.annotation.*;
  7. import java.util.List;
  8. @RestController
  9. @RequestMapping("/marketing/promotions")
  10. @RequiredArgsConstructor
  11. public class PromotionController {
  12. private final PromotionService promotionService;
  13. @GetMapping
  14. public List<Promotion> getPromotions(
  15. @RequestParam(defaultValue = "1") int page,
  16. @RequestParam(defaultValue = "20") int size) {
  17. return promotionService.getPage(page, size).getRecords();
  18. }
  19. @GetMapping("/all")
  20. public List<Promotion> getAll() {
  21. return promotionService.getAll();
  22. }
  23. @GetMapping("/{id}")
  24. public PromotionDTO getById(@PathVariable Long id) {
  25. return promotionService.getDtoById(id);
  26. }
  27. @PostMapping
  28. public Long create(@RequestBody Promotion promotion) {
  29. return promotionService.save(promotion);
  30. }
  31. @PutMapping("/{id}")
  32. public void update(@PathVariable Long id, @RequestBody Promotion promotion) {
  33. promotion.setId(id);
  34. promotionService.update(promotion);
  35. }
  36. @DeleteMapping("/{id}")
  37. public void delete(@PathVariable Long id) {
  38. promotionService.delete(id);
  39. }
  40. @PostMapping("/{id}/activate")
  41. public void activate(@PathVariable Long id) {
  42. promotionService.activate(id);
  43. }
  44. @PostMapping("/{id}/deactivate")
  45. public void deactivate(@PathVariable Long id) {
  46. promotionService.deactivate(id);
  47. }
  48. }