package cn.lihongjie.coal.syslog.controller;

import cn.lihongjie.coal.annotation.SysLog;
import cn.lihongjie.coal.base.dto.CommonQuery;
import cn.lihongjie.coal.base.dto.IdRequest;
import cn.lihongjie.coal.syslog.dto.CreateSysLogDto;
import cn.lihongjie.coal.syslog.dto.SysLogDto;
import cn.lihongjie.coal.syslog.dto.UpdateSysLogDto;
import cn.lihongjie.coal.syslog.service.SysLogService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
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;

@RequestMapping("/sysLog")
@RestController
@SysLog(module = "系统日志")
public class SysLogController {

    @Autowired SysLogService service;

    @PostMapping("/create")
    @SysLog(action = "新增")
    public SysLogDto create(@RequestBody CreateSysLogDto dto) {
        return this.service.create(dto);
    }

    @PostMapping("/update")
    @SysLog(action = "编辑")
    public SysLogDto update(@RequestBody UpdateSysLogDto dto) {
        return this.service.update(dto);
    }

    @PostMapping("/delete")
    @SysLog(action = "删除")
    public Object delete(@RequestBody IdRequest dto) {
        this.service.delete(dto);
        return true;
    }

    @PostMapping("/list")
    public Page<SysLogDto> list(@RequestBody CommonQuery dto) {
        return this.service.list(dto);
    }

    @PostMapping("/getById")
    public SysLogDto getById(@RequestBody IdRequest dto) {
        return this.service.getById(dto.getId());
    }
}
