package com.persagy.proxy.object.controller;

import com.persagy.proxy.adm.request.AdmQueryCriteria;
import com.persagy.proxy.adm.request.AdmResponse;
import com.persagy.proxy.adm.utils.AdmContextUtil;
import com.persagy.proxy.object.model.AdmProject;
import com.persagy.proxy.object.service.IAdmProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.ws.rs.QueryParam;

/**
 * ADM 项目 API
 * @author Charlie Yu
 * @date 2021-08-16
 */
@RestController
@RequestMapping("/object/project")
public class AdmProjectController {

    @Autowired
    private IAdmProjectService service;

    /**
     * 查询项目信息
     * @param request
     * @return
     * @throws Exception
     */
    @PostMapping("/query")
    public AdmResponse query(@QueryParam("projectId") String projectId, @RequestBody AdmQueryCriteria request) throws Exception {
        request.setName(AdmProject.OBJ_TYPE);
        return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmProject.class);
    }

    /**
     * 查询项目信息-全部或指定id
     * @param request
     * @return
     * @throws Exception
     */
    @PostMapping("/query/obj")
    public AdmResponse queryObj(@RequestBody AdmQueryCriteria request) throws Exception {
        return query(null, request);
    }
}
