| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- package com.oms.controller;
- import com.oms.dto.PromotionDTO;
- import com.oms.entity.Promotion;
- import com.oms.service.PromotionService;
- import lombok.RequiredArgsConstructor;
- import org.springframework.web.bind.annotation.*;
- import java.util.List;
- @RestController
- @RequestMapping("/marketing/promotions")
- @RequiredArgsConstructor
- public class PromotionController {
- private final PromotionService promotionService;
- @GetMapping
- public List<Promotion> getPromotions(
- @RequestParam(defaultValue = "1") int page,
- @RequestParam(defaultValue = "20") int size) {
- return promotionService.getPage(page, size).getRecords();
- }
- @GetMapping("/all")
- public List<Promotion> getAll() {
- return promotionService.getAll();
- }
- @GetMapping("/{id}")
- public PromotionDTO getById(@PathVariable Long id) {
- return promotionService.getDtoById(id);
- }
- @PostMapping
- public Long create(@RequestBody Promotion promotion) {
- return promotionService.save(promotion);
- }
- @PutMapping("/{id}")
- public void update(@PathVariable Long id, @RequestBody Promotion promotion) {
- promotion.setId(id);
- promotionService.update(promotion);
- }
- @DeleteMapping("/{id}")
- public void delete(@PathVariable Long id) {
- promotionService.delete(id);
- }
- @PostMapping("/{id}/activate")
- public void activate(@PathVariable Long id) {
- promotionService.activate(id);
- }
- @PostMapping("/{id}/deactivate")
- public void deactivate(@PathVariable Long id) {
- promotionService.deactivate(id);
- }
- }
|