/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.coupon.multishop.controller;

import javax.validation.Valid;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yami.shop.coupon.comment.model.CouponUser;
import com.yami.shop.coupon.comment.service.CouponUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.yami.shop.common.util.PageParam;
import com.baomidou.mybatisplus.core.metadata.IPage;


/**
 *
 * @author lgh on 2018/12/27.
 */
@RestController
@RequestMapping("/admin/couponUser")
public class CouponUserController {

    @Autowired
    private CouponUserService couponUserService;

	/**
	 * 分页获取
	 */
    @GetMapping("/page")
	public ResponseEntity<IPage<CouponUser>> page(CouponUser couponUser,PageParam<CouponUser> page){
		IPage<CouponUser> couponUsers = couponUserService.page(page,new LambdaQueryWrapper<CouponUser>());
		return ResponseEntity.ok(couponUsers);
	}

    /**
	 * 获取信息
	 */
	@GetMapping("/info/{id}")
	public ResponseEntity<CouponUser> info(@PathVariable("id") Long id){
		CouponUser couponUser = couponUserService.getById(id);
		return ResponseEntity.ok(couponUser);
	}

	/**
	 * 保存
	 */
	@PostMapping
	public ResponseEntity<Void> save(@RequestBody @Valid CouponUser couponUser){
		couponUserService.save(couponUser);
		return ResponseEntity.ok().build();
	}

	/**
	 * 修改
	 */
	@PutMapping
	public ResponseEntity<Void> update(@RequestBody @Valid CouponUser couponUser){
		couponUserService.updateById(couponUser);
		return ResponseEntity.ok().build();
	}

	/**
	 * 删除
	 */
	@DeleteMapping("/{id}")
	public ResponseEntity<Void> delete(@PathVariable Long id){
		couponUserService.removeById(id);
		return ResponseEntity.ok().build();
	}
}
