package com.red.circle.console.adapter.app.sys;


import com.red.circle.console.app.service.app.sys.SysGiftPackService;
import com.red.circle.console.infra.annotations.OpsOperationReqLog;
import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.other.inner.model.cmd.sys.GiftPackQryCmd;
import com.red.circle.other.inner.model.dto.sys.SysGiftPackDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 礼包 前端控制器.
 * </p>
 *
 * @author houyong
 * @since 2021-03-10
 */
@RestController
@RequestMapping("/sys/gift/pack")
@RequiredArgsConstructor
public class SysGiftPackRestController extends BaseController {

  private final SysGiftPackService sysGiftPackService;

  /**
   * 获取礼包信息.
   */
  @GetMapping
  public PageResult<SysGiftPackDTO> getGiftPackInfo(GiftPackQryCmd query) {
    return sysGiftPackService.getGiftPackInfo(query);
  }

  @OpsOperationReqLog(value = "新增礼包")
  @PostMapping
  public void addGiftPack(@RequestBody SysGiftPackDTO sysGiftPackDTO) {
    sysGiftPackDTO.setCreateUser(getReqUserId());
    sysGiftPackService.addGiftPack(sysGiftPackDTO);
  }

  @OpsOperationReqLog(value = "修改礼包")
  @PutMapping
  public void updateGiftPack(@RequestBody SysGiftPackDTO sysGiftPackDTO) {
    sysGiftPackDTO.setUpdateUser(getReqUserId());
    sysGiftPackService.updateGiftPack(sysGiftPackDTO);
  }

  /**
   * 删除礼包.
   */
  @GetMapping("/delete/{id}")
  public void deleteGiftPack(@PathVariable("id") Long id) {
    sysGiftPackService.deleteGiftPack(id);
  }
}
