TestController.java 3.77 KB
package com.infoloop.tianting.controller;

import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.infoloop.tianting.constant.PathVariableResourceConstants;
import com.infoloop.tianting.model.common.CreatedResult;
import com.infoloop.tianting.model.common.PageResult;
import com.infoloop.tianting.model.dto.TestExampleDbDTO;
import com.infoloop.tianting.model.vo.TestExampleDbVO;
import com.infoloop.tianting.service.TestService;
import com.tianting.infoloop.grpc.exampleservice.SingleTestExampleDbRpcResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
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.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;


@Api(tags = "示例")
@ApiSupport(order = -1)
@Slf4j
@Validated
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class TestController {

    private final TestService testService;

    @ApiOperation(value = "分页查询")
    @PostMapping("/testexampledbs/page")
    @ResponseStatus(HttpStatus.OK)
    public PageResult<TestExampleDbVO> queryPage(@Valid @RequestBody TestExampleDbDTO.QueryPage queryPage) {
        return testService.queryPage(queryPage);
    }

    @ApiOperation(value = "查询所有")
    @PostMapping("/testexampledbs/queryall")
    @ResponseStatus(HttpStatus.OK)
    public List<TestExampleDbVO> queryAll() {
        return testService.queryAll();
    }

    @ApiOperation(value = "新增")
    @PutMapping("/testexampledb")
    @ResponseStatus(HttpStatus.CREATED)
    public CreatedResult<TestExampleDbVO> createTestExampleDb(@Valid @RequestBody TestExampleDbDTO.CreateTestExampleDb createTestExampleDb) {
        return testService.createTestExampleDb(createTestExampleDb);
    }

    @ApiOperation(value = "修改")
    @PatchMapping("/testexampledb/{testExampleDbId}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void updateTestExampleDb(@ApiIgnore @RequestAttribute(PathVariableResourceConstants.INJECTED_TEST_EXAMPLE_DB) final SingleTestExampleDbRpcResponse testExampleDbRpcResponse,
                                    @Valid @RequestBody TestExampleDbDTO.UpdateTestExampleDb updateTestExampleDb) {
        testService.updateTestExampleDb(testExampleDbRpcResponse, updateTestExampleDb);
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/testexampledb/{testExampleDbId}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void deleteTestExampleDb(@ApiIgnore @RequestAttribute(PathVariableResourceConstants.INJECTED_TEST_EXAMPLE_DB)final SingleTestExampleDbRpcResponse testExampleDbRpcResponse) {
        testService.deleteTestExampleDb(testExampleDbRpcResponse);
    }

    @ApiOperation(value = "详情")
    @GetMapping("/testexampledb/{testExampleDbId}")
    @ResponseStatus(HttpStatus.OK)
    public TestExampleDbVO getTestExampleDb(@ApiIgnore @RequestAttribute(PathVariableResourceConstants.INJECTED_TEST_EXAMPLE_DB)final SingleTestExampleDbRpcResponse testExampleDbRpcResponse) {
        return testService.getTestExampleDb(testExampleDbRpcResponse);
    }

}