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

import com.railway.business.app.domain.AppTask;
import com.railway.business.app.service.IAppTaskService;
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/task")
public class AppTaskController extends BaseController {

  private final IAppTaskService appTaskService;

  public AppTaskController(IAppTaskService appTaskService) {
    this.appTaskService = appTaskService;
  }

  @ApiOperation(value = "新增")
  @PostMapping("/add")
  public AjaxResult add(@Validated @RequestBody AppTask appTask) {
    return toAjax(appTaskService.create(appTask));
  }

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

  @ApiOperation(value = "更新")
  @PutMapping("/update")
  public AjaxResult update(@RequestBody @Valid AppTask appTask) {
    return toAjax(appTaskService.update(appTask));
  }

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

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

}
