package com.tashow.cloud.system.api.logger;

import com.tashow.cloud.common.pojo.CommonResult;
import com.tashow.cloud.common.pojo.PageResult;
import com.tashow.cloud.common.util.object.BeanUtils;
import com.tashow.cloud.systemapi.api.logger.OperateLogApi;
import com.tashow.cloud.systemapi.api.logger.dto.OperateLogCreateReqDTO;
import com.tashow.cloud.systemapi.api.logger.dto.OperateLogPageReqDTO;
import com.tashow.cloud.systemapi.api.logger.dto.OperateLogRespDTO;
import com.tashow.cloud.system.dal.dataobject.logger.OperateLogDO;
import com.tashow.cloud.system.service.logger.OperateLogService;
import com.tashow.cloud.systemapi.api.logger.dto.OperateLogCreateReqDTO;
import com.tashow.cloud.systemapi.api.logger.dto.OperateLogPageReqDTO;
import com.tashow.cloud.systemapi.api.logger.dto.OperateLogRespDTO;
import com.tashow.cloud.system.dal.dataobject.logger.OperateLogDO;
import com.tashow.cloud.system.service.logger.OperateLogService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import static com.tashow.cloud.common.pojo.CommonResult.success;

@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
public class OperateLogApiImpl implements OperateLogApi {

    @Resource
    private OperateLogService operateLogService;

    @Override
    public CommonResult<Boolean> createOperateLog(OperateLogCreateReqDTO createReqDTO) {
        operateLogService.createOperateLog(createReqDTO);
        return success(true);
    }

    @Override
    public CommonResult<PageResult<OperateLogRespDTO>> getOperateLogPage(OperateLogPageReqDTO pageReqDTO) {
        PageResult<OperateLogDO> operateLogPage = operateLogService.getOperateLogPage(pageReqDTO);
        return success(BeanUtils.toBean(operateLogPage, OperateLogRespDTO.class));
    }

}
