package com.fzm.mall.server.admin.opration.controller;


import com.fzm.mall.server.admin.annotation.AdminLog;
import com.fzm.mall.server.admin.enums.log.OperateModuleEnum;
import com.fzm.mall.server.admin.enums.log.OperateTypeEnum;
import com.fzm.mall.server.admin.opration.entity.dto.FloorDTO;
import com.fzm.mall.server.admin.opration.entity.dto.FloorSaveDTO;
import com.fzm.mall.server.admin.opration.service.IFloorService;
import com.fzm.mall.server.admin.repo.ResponseFactory;
import com.fzm.mall.server.admin.repo.ResponseVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 运营中心-首页楼层 前端控制器
 * </p>
 *
 * @author fzm
 * @since 2021-03-23
 */
@Api(tags = "运营中心")
@RestController
@RequestMapping("/floor/floorPermission")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class FloorController {

    private final IFloorService floorService;
    private final ResponseFactory resFac;

    @ApiOperation(value = "运营中心-楼层-新增")
    @ApiOperationSupport(order = 1)
    @AdminLog(description = "运营中心-楼层-新增", module = OperateModuleEnum.OPERATE_CENTER, opType = OperateTypeEnum.ADD)
    @PostMapping("/save")
    public ResponseVO save(@RequestBody @Valid FloorSaveDTO floorSaveDTO) {
        floorService.save(floorSaveDTO);
        return resFac.getSimpleSuccessResponse();
    }

    @ApiOperation(value = "运营中心-楼层-列表查询")
    @ApiOperationSupport(order = 5)
    @GetMapping("/list")
    public ResponseVO list() {

        List<FloorDTO> result = floorService.listAll();
        return resFac.getSuccessResponseWithData(result);
    }
}
