package com.yida.data.system.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.system.Dept;
import com.yida.data.common.core.entity.system.EduYidaApp;
import com.yida.data.system.service.EduYidaAppService;
import com.yida.data.system.service.IDeptService;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;

@Api(tags = "易达 app管理")
@RestController
@RequestMapping("/yida/app")
@RequiredArgsConstructor
public class EduYidaAppController {
    private final EduYidaAppService eduYidaAppService;
    private final IDeptService deptService;

    @ApiOperation("根据学校id查询app")
    @GetMapping("/getAppBySchool")
    public ResultBean<EduYidaApp> getAppBySchool(Long schoolId) {
        Dept school = deptService.getById(schoolId);
        return ResultBean.buildSuccess(school != null ? eduYidaAppService.getById(school.getYidaAppId()) : null);
    }

    @ApiOperation("查询易达app列表")
    @GetMapping("/listApp")
    public ResultBean<List<EduYidaApp>> listApp(){
        return ResultBean.buildSuccess(eduYidaAppService.list(Wrappers.<EduYidaApp>lambdaQuery().orderByAsc(EduYidaApp::getId)));
    }
}
