package com.purui.prims.headless.server.rest;


import com.purui.prims.auth.api.authentication.pojo.User;
import com.purui.prims.common.pojo.ModelRela;
import com.purui.prims.headless.server.service.ModelRelaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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;

import java.util.List;

@RestController
@RequestMapping("/api/semantic/modelRela")
@Api(tags = "模型关联设置")
public class ModelRelaController {

    @Autowired
    private ModelRelaService modelRelaService;

    @ApiOperation(value = "保存模型关系")
    @PostMapping
    public boolean save(@RequestBody ModelRela modelRela, User user) {
        modelRelaService.save(modelRela, user);
        return true;
    }

    @ApiOperation(value = "更新模型关系")
    @PutMapping
    public boolean update(@RequestBody ModelRela modelRela, User user) {
        modelRelaService.update(modelRela, user);
        return true;
    }

    @ApiOperation(value = "获取模型关系列表")
    @GetMapping("/list")
    public List<ModelRela> getModelRelaList(@RequestParam("domainId") Long domainId) {
        return modelRelaService.getModelRelaList(domainId);
    }

    @ApiOperation(value = "删除模型关系")
    @DeleteMapping("/{id}")
    public void delete(@PathVariable("id") Long id) {
        modelRelaService.delete(id);
    }

}
