package com.diagbot.web;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.diagbot.annotation.SysLogger;
import com.diagbot.dto.RespDTO;
import com.diagbot.entity.ServiceInfo;
import com.diagbot.facade.ServiceInfoFacade;
import com.diagbot.vo.ServiceSaveVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * <p>
 * 用户服务表 前端控制器
 * </p>
 *
 * @author zhaops
 * @since 2018-09-17
 */
@RestController
@Api(value="用户服务API", tags={"用户服务API"})
@RequestMapping("/serviceInfo")
@SuppressWarnings("unchecked")
public class ServiceInfoController {

    @Autowired
    private ServiceInfoFacade serviceInfoFacade;

    @ApiOperation(value = "新增服务[by:zhaops]",
            notes = "name：产品名称，必填<br>" +
                    "description：产品简介，必填<br> ")
    @PostMapping("/createService")
    @SysLogger("createService")
    @Transactional
    public RespDTO<ServiceInfo> createService(@RequestBody @Valid ServiceSaveVO serviceSaveVO) {
        ServiceInfo serviceInfo = serviceInfoFacade.createService(serviceSaveVO);
        return RespDTO.onSuc(serviceInfo);
    }

    @ApiOperation(value = "修改服务[by:zhaops]",
            notes = "id：id，必填<br>" +
                    "name：产品名称，必填<br>" +
                    "description：产品简介，必填<br> " +
                    "userId：用户id，必填<br> ")
    @PostMapping("/updateService")
    @SysLogger("updateService")
    @Transactional
    public RespDTO<Boolean> updateService(@RequestBody @Valid ServiceInfo serviceInfo) {
        Boolean isSuccess = serviceInfoFacade.updateService(serviceInfo);
        return RespDTO.onSuc(isSuccess);
    }

    @ApiOperation(value = "获取当前登录用户的服务列表[by:zhaops]")
    @PostMapping("/getServiceListByCurrentUser")
    @SysLogger("getServiceListByCurrentUser")
    @Transactional
    public RespDTO<List<ServiceInfo>> getServiceListByCurrentUser() {
        List<ServiceInfo> list = serviceInfoFacade.getServiceListByCurrentUser();
        return RespDTO.onSuc(list);
    }

    @ApiOperation(value = "获取当前登录用户的服务分页列表[by:zhaops]")
    @PostMapping("/getServiceListPageByCurrentUser")
    @SysLogger("getServiceListPageByCurrentUser")
    @Transactional
    public RespDTO getServiceListPageByCurrentUser(Page<ServiceInfo> page) {
        IPage<ServiceInfo> list = serviceInfoFacade.getServiceListPageByCurrentUser(page);
        return RespDTO.onSuc(list);
    }
}

