package cn.lihongjie.coal.loginUser.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.loginUser.dto.CreateLoginUserDto;
import cn.lihongjie.coal.loginUser.dto.LoginUserDto;
import cn.lihongjie.coal.loginUser.dto.UpdateLoginUserDto;
import cn.lihongjie.coal.loginUser.service.LoginUserService;

import lombok.extern.slf4j.Slf4j;

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;

@RestController
@RequestMapping("/loginUser")
@SysLog(module = "登录用户")
@Slf4j
public class LoginUserController {
    @Autowired private LoginUserService service;

    @PostMapping("/create")
    public LoginUserDto create(@RequestBody CreateLoginUserDto request) {
        return this.service.create(request);
    }

    @PostMapping("/update")
    public LoginUserDto update(@RequestBody UpdateLoginUserDto request) {
        return this.service.update(request);
    }

    @PostMapping("/delete")
    public Object delete(@RequestBody IdRequest request) {
        this.service.delete(request);
        return true;
    }

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

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

    @PostMapping("/logout")
    public Boolean logout(@RequestBody IdRequest request) {
        this.service.adminLogout(request);
        return true;
    }
}
