package cn.ysk.cashier.controller;


import cn.ysk.cashier.annotation.rest.AnonymousPostMapping;
import cn.ysk.cashier.dto.TbShopShareRecordQueryCriteria;
import cn.ysk.cashier.mybatis.entity.TbShopShare;
import cn.ysk.cashier.mybatis.service.TbShopShareRecordService;
import cn.ysk.cashier.mybatis.service.TbShopShareService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * 店铺分享(TbShopShare)表控制层
 *
 * @author ww
 * @since 2024-11-06 15:47:37
 */
@Api(tags = "分享")
@RestController
@RequestMapping("tbShopShare")
public class TbShopShareController {

    @Resource
    private TbShopShareService tbShopShareService;

    /**
     * 服务对象
     */
    @Resource
    private TbShopShareRecordService tbShopShareRecordService;

    @PostMapping("byShare")
    @ApiOperation("分页查询")
    public ResponseEntity<Object> selectAllByShare(@RequestBody TbShopShareRecordQueryCriteria criteria) {
        return new ResponseEntity<>(tbShopShareRecordService.selectAllByShare(criteria), HttpStatus.OK);
    }

    @GetMapping("byShopId")
    @ApiOperation("通过shopId查询详情")
    public ResponseEntity<?> getByShopId(@RequestParam Integer shopId) {
        return ResponseEntity.ok(tbShopShareService.getByShopId(shopId));
    }

    @PostMapping
    @ApiOperation("新增")
    public ResponseEntity<Object> insert(@RequestBody TbShopShare tbShopShare) {
        return new ResponseEntity<>(tbShopShareService.save(tbShopShare), HttpStatus.CREATED);
    }

    @PutMapping
    @ApiOperation("通过id修改")
    public ResponseEntity<Object> update(@RequestBody TbShopShare tbShopShare) {
        tbShopShareService.updateById(tbShopShare);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }



    @DeleteMapping
    @ApiOperation("删除")
    public ResponseEntity<Object> delete(@RequestBody Integer[] ids) {
        tbShopShareService.removeByIds(Arrays.asList(ids));
        return new ResponseEntity<>(HttpStatus.OK);
    }
}

