package com.railway.web.controller.business.app;

import com.railway.business.app.domain.AppFeedback;
import com.railway.business.app.service.IAppFeedbackService;
import com.railway.common.core.controller.BaseController;
import com.railway.common.core.domain.AjaxResult;
import com.railway.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ZhaoMn
 */
@Api(value = "rest/app", tags = "意见反馈 - apk意见反馈")
@RestController
@Validated
@RequestMapping(value = "app/feedback")
public class AppFeedbackController extends BaseController {

  private final IAppFeedbackService appFeedbackService;

  public AppFeedbackController(IAppFeedbackService appFeedbackService) {
    this.appFeedbackService = appFeedbackService;
  }

  @ApiOperation(value = "新增")
  @PostMapping("/add")
  public AjaxResult add(@Validated @RequestBody AppFeedback appFeedback) {
    return toAjax(appFeedbackService.create(appFeedback));
  }

  @ApiOperation(value = "删除")
  @DeleteMapping("/{ids}")
  public AjaxResult delete(@RequestParam String[] ids) {
    return toAjax(appFeedbackService.delete(ids));
  }

  @ApiOperation(value = "更新")
  @PutMapping("/update")
  public AjaxResult update(@RequestBody @Valid AppFeedback appFeedback) {
    return toAjax(appFeedbackService.update(appFeedback));
  }

  @ApiOperation(value = "单个")
  @GetMapping(value = {"/", "/{id}"})
  public AjaxResult getInfo(String id) {
    AppFeedback info = appFeedbackService.getInfo(id);
    AjaxResult ajax = AjaxResult.success();
    ajax.put("info", info);
    return ajax;
  }

  @ApiOperation(value = "列表")
  @GetMapping(value = "list")
  public TableDataInfo getList(AppFeedback appFeedback) {
    startPage();
    List<AppFeedback> list = appFeedbackService.getList(appFeedback);
    return getDataTable(list);
  }

}
