package com.sqx.modules.appeal.controller;

import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.appeal.entity.Appeal;
import com.sqx.modules.appeal.service.AppealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Api(value = "用户-申诉", tags = {"用户-申诉"})
@RequestMapping("/app/appeal")
public class AppealController {

    @Resource
    private AppealService appealService;

    @Login
    @GetMapping("/getAppeal")
    @ApiOperation("获取申诉记录")
    public Result getAppeal(@RequestAttribute("userId")Long userId, Integer page, Integer limit, Appeal appeal, String startTime, String endTime){
        return Result.success().put("data",appealService.getAppealPage(page,limit,userId, appeal,startTime,endTime));
    }

    @Login
    @PostMapping("/insertAppeal")
    @ApiOperation("新增申诉")
    public Result insertAppeal(@RequestAttribute("userId")Long userId, Appeal appeal){
        appeal.setProcess(2);
        appeal.setUserId(userId);
        return appealService.insertAppeal(appeal);
    }

    @Login
    @PostMapping("/updateAppeal")
    @ApiOperation("修改申诉")
    public Result updateAppeal(@RequestAttribute("userId")Long userId, Appeal appeal){
        appeal.setUserId(userId);
        return appealService.updateAppeal(appeal);
    }

    @PostMapping("/deleteAppeal")
    @ApiOperation("删除申诉")
    public Result deleteAppeal(Long id){
        return appealService.deleteAppeal(id);
    }
}
