package com.ruoyi.demo.controller;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.demo.entity.App;
import com.ruoyi.demo.entity.vo.AppVo;
import com.ruoyi.demo.service.AppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/app")
public class AppController {
    @Autowired
    AppService appService;

    @PostMapping("/addApp")
    public R addApp(@Validated(value={AddGroup.class}) AppVo appVo){
        appService.addApp(appVo);
        return R.ok();
    }

    @DeleteMapping("/deleteApp")
    public R deleteApp(String[] appKeys){
        appService.deleteApp(appKeys);
        return R.ok();
    }

    @GetMapping("/getAppListByCommercialId")
    public R getAppListByCommercialId(AppVo appVo){
        PageInfo<App> appListByCommercialId = appService.getAppList(appVo);
        return R.ok(appListByCommercialId);
    }

    @GetMapping("/getApp")
    public R getApp(@Validated(value={AddGroup.class})AppVo appVo){
        App app = appService.getApp(appVo);
        return R.ok(app);
    }

    @PutMapping("/updateApp")
    public R updateApp(AppVo appVo){
        appService.updateApp(appVo);
        return R.ok();
    }

    @GetMapping("/testCallBack")
    public R testCallBack(String callBack){
        appService.testCallBack(callBack);
        return R.ok();
    }
}
