
package com.tmerclub.cloud.user.controller.app;

import com.tmerclub.cloud.common.database.dto.PageDTO;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.util.BeanUtil;
import com.tmerclub.cloud.user.dto.UserRechargeCouponDTO;
import com.tmerclub.cloud.user.model.UserRechargeCoupon;
import com.tmerclub.cloud.user.service.UserRechargeCouponService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 余额优惠券关联表
 *
 * @author tmerclub
 * @date 2021-04-27 15:51:36
 */
@RestController("appUserRechargeCouponController")
@RequestMapping("/userRechargeCoupon")
@Tag(name = "余额优惠券关联表")
public class UserRechargeCouponController {

    @Autowired
    private UserRechargeCouponService userRechargeCouponService;


    @GetMapping("/page")
    @Operation(summary = "获取余额优惠券关联表列表", description = "分页获取余额优惠券关联表列表")
    public ServerResponseEntity<PageVO<UserRechargeCoupon>> page(@Valid PageDTO pageDTO) {
        PageVO<UserRechargeCoupon> userRechargeCouponPage = userRechargeCouponService.page(pageDTO);
        return ServerResponseEntity.success(userRechargeCouponPage);
    }

    @GetMapping
    @Operation(summary = "获取余额优惠券关联表", description = "根据rechargeId获取余额优惠券关联表")
    public ServerResponseEntity<UserRechargeCoupon> getByRechargeId(@RequestParam Long rechargeId) {
        return ServerResponseEntity.success(userRechargeCouponService.getByRechargeId(rechargeId));
    }

    @PostMapping
    @Operation(summary = "保存余额优惠券关联表", description = "保存余额优惠券关联表")
    public ServerResponseEntity<Void> save(@Valid @RequestBody UserRechargeCouponDTO userRechargeCouponDTO) {
        UserRechargeCoupon userRechargeCoupon = BeanUtil.map(userRechargeCouponDTO, UserRechargeCoupon.class);
        userRechargeCouponService.save(userRechargeCoupon);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新余额优惠券关联表", description = "更新余额优惠券关联表")
    public ServerResponseEntity<Void> update(@Valid @RequestBody UserRechargeCouponDTO userRechargeCouponDTO) {
        UserRechargeCoupon userRechargeCoupon = BeanUtil.map(userRechargeCouponDTO, UserRechargeCoupon.class);
        userRechargeCouponService.update(userRechargeCoupon);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除余额优惠券关联表", description = "根据余额优惠券关联表id删除余额优惠券关联表")
    public ServerResponseEntity<Void> delete(@RequestParam Long rechargeId) {
        userRechargeCouponService.deleteById(rechargeId);
        return ServerResponseEntity.success();
    }
}
