3

我有一个简单的 Rest API,它检查数据库中是否存在类别 ID,如下所示

@Controller("/sub-category")
public class SubCategoryController implements ISubCategoryOperation
{
    @Post
      public Maybe<HttpResponse> post(@Valid SubCategoryViewModel categoryViewModel) {
            LOG.info(String.format("Controller --> Updating the specified category"));
            return iCategoryManager.Count(categoryViewModel.categoryId()).flatMap(item -> {
                if (item > 0) {
                    iSubCategoryManager.Create(categoryViewModel);
                    return Maybe.just(HttpResponse.created(categoryViewModel));
                } else
                    return Maybe.just(HttpResponse.notFound("Category id not found"));
            });
        }
}

在 else 语句中,我在 HTTP 正文中返回了一条消息“未找到类别 ID”,但是,我无法在客户端(例如邮递员)上看到该消息

在此处输入图像描述

我错过了什么?

更新 1

上述控制器方法已使用 micronaut 声明式客户端从 API 网关调用,如下所示

@Controller("/api/${api.version:v1}/sub-category")
public class ApiGatewaySubCategoryController implements ISubCategoryOperation{
    private final ISubCategoryClient iSubCategoryClient;

    public ApiGatewaySubCategoryController(ISubCategoryClient iSubCategoryClient) {
        this.iSubCategoryClient = iSubCategoryClient;
    }

    @Override
    public Maybe<HttpResponse<?>> post(@NotBlank String id, @Valid SubCategoryViewModel model) {
        return this.iSubCategoryClient.post(id, model);
    }
}

声明式 HTTP 客户端

@Client(id="feteBirdProduct", path = "/sub-category")
public interface ISubCategoryClient extends ISubCategoryOperation{
}
4

0 回答 0