package com.lottery.shop.controller;

import com.lottery.shop.entity.TaShop;
import com.lottery.shop.service.TaShopService;
import lombok.extern.slf4j.Slf4j;
import com.lottery.shop.param.TaShopPageParam;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.common.param.IdParam;
import io.geekidea.springbootplus.framework.log.annotation.Module;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.geekidea.springbootplus.framework.core.validator.groups.Add;
import io.geekidea.springbootplus.framework.core.validator.groups.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 店铺  控制器
 *
 * @author fxf
 * @since 2020-09-07
 */
@Slf4j
@RestController
@RequestMapping("/taShop")
@Module("shop")
@Api(value = "店铺 API", tags = {"店铺 "})
public class TaShopController extends BaseController {

    @Autowired
    private TaShopService taShopService;

    /**
     * 添加店铺 
     */
    @PostMapping("/add")
    @OperationLog(name = "添加店铺 ", type = OperationLogType.ADD)
    @ApiOperation(value = "添加店铺 ", response = ApiResult.class)
    public ApiResult<Boolean> addTaShop(@Validated(Add.class) @RequestBody TaShop taShop) throws Exception {
        boolean flag = taShopService.saveTaShop(taShop);
        return ApiResult.result(flag);
    }

    /**
     * 修改店铺 
     */
    @PostMapping("/update")
    @OperationLog(name = "修改店铺 ", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改店铺 ", response = ApiResult.class)
    public ApiResult<Boolean> updateTaShop(@Validated(Update.class) @RequestBody TaShop taShop) throws Exception {
        boolean flag = taShopService.updateTaShop(taShop);
        return ApiResult.result(flag);
    }

    /**
     * 删除店铺 
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除店铺 ", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除店铺 ", response = ApiResult.class)
    public ApiResult<Boolean> deleteTaShop(@PathVariable("id") Long id) throws Exception {
        boolean flag = taShopService.deleteTaShop(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取店铺 详情
     */
    @GetMapping("/info/{id}")
    @OperationLog(name = "店铺 详情", type = OperationLogType.INFO)
    @ApiOperation(value = "店铺 详情", response = TaShop.class)
    public ApiResult<TaShop> getTaShop(@PathVariable("id") Long id) throws Exception {
        TaShop taShop = taShopService.getById(id);
        return ApiResult.ok(taShop);
    }

    /**
     * 店铺 分页列表
     */
    @PostMapping("/getPageList")
    @OperationLog(name = "店铺 分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "店铺 分页列表", response = TaShop.class)
    public ApiResult<Paging<TaShop>> getTaShopPageList(@Validated @RequestBody TaShopPageParam taShopPageParam) throws Exception {
        Paging<TaShop> paging = taShopService.getTaShopPageList(taShopPageParam);
        return ApiResult.ok(paging);
    }

}

