mirror of
https://gitee.com/zyjblog/oatpp.git
synced 2025-01-03 05:22:24 +08:00
Update README.md
This commit is contained in:
parent
1c0aea3f88
commit
a8ceacbced
18
README.md
18
README.md
@ -50,7 +50,7 @@ For more info see [Api Controller](https://oatpp.io/docs/components/api-controll
|
||||
```cpp
|
||||
ENDPOINT("PUT", "/users/{userId}", putUser,
|
||||
PATH(Int64, userId),
|
||||
BODY_DTO(UserDto, userDto))
|
||||
BODY_DTO(Object<UserDto>, userDto))
|
||||
{
|
||||
userDto->id = userId;
|
||||
return createDtoResponse(Status::CODE_200, m_database->updateUser(userDto));
|
||||
@ -65,7 +65,7 @@ For more info see [Api Controller / CORS](https://oatpp.io/docs/components/api-c
|
||||
ADD_CORS(putUser)
|
||||
ENDPOINT("PUT", "/users/{userId}", putUser,
|
||||
PATH(Int64, userId),
|
||||
BODY_DTO(UserDto, userDto))
|
||||
BODY_DTO(Object<UserDto>, userDto))
|
||||
{
|
||||
userDto->id = userId;
|
||||
return createDtoResponse(Status::CODE_200, m_database->updateUser(userDto));
|
||||
@ -82,7 +82,7 @@ using namespace oatpp::web::server::handler;
|
||||
ENDPOINT("PUT", "/users/{userId}", putUser,
|
||||
AUTHORIZATION(std::shared_ptr<DefaultBasicAuthorizationObject>, authObject),
|
||||
PATH(Int64, userId),
|
||||
BODY_DTO(UserDto, userDto))
|
||||
BODY_DTO(Object<UserDto>, userDto))
|
||||
{
|
||||
OATPP_ASSERT_HTTP(authObject->userId == "Ivan" && authObject->password == "admin", Status::CODE_401, "Unauthorized");
|
||||
userDto->id = userId;
|
||||
@ -100,15 +100,15 @@ For more info see [Endpoint Annotation And API Documentation](https://oatpp.io/d
|
||||
ENDPOINT_INFO(putUser) {
|
||||
// general
|
||||
info->summary = "Update User by userId";
|
||||
info->addConsumes<UserDto>("application/json");
|
||||
info->addResponse<UserDto>(Status::CODE_200, "application/json");
|
||||
info->addConsumes<Object<UserDto>>("application/json");
|
||||
info->addResponse<Object<UserDto>>(Status::CODE_200, "application/json");
|
||||
info->addResponse<String>(Status::CODE_404, "text/plain");
|
||||
// params specific
|
||||
info->pathParams["userId"].description = "User Identifier";
|
||||
}
|
||||
ENDPOINT("PUT", "/users/{userId}", putUser,
|
||||
PATH(Int64, userId),
|
||||
BODY_DTO(UserDto, userDto))
|
||||
BODY_DTO(Object<UserDto>, userDto))
|
||||
{
|
||||
userDto->id = userId;
|
||||
return createDtoResponse(Status::CODE_200, m_database->updateUser(userDto));
|
||||
@ -137,7 +137,7 @@ public:
|
||||
|
||||
```cpp
|
||||
auto response = userService->getUserById(id);
|
||||
auto user = response->readBodyToDto<dto::UserDto>(objectMapper);
|
||||
auto user = response->readBodyToDto<oatpp::Object<UserDto>>(objectMapper);
|
||||
```
|
||||
|
||||
### Object Mapping
|
||||
@ -147,9 +147,9 @@ For more info see [Data Transfer Object (DTO)](https://oatpp.io/docs/components/
|
||||
#### Declare DTO
|
||||
|
||||
```cpp
|
||||
class UserDto : public oatpp::data::mapping::type::Object {
|
||||
class UserDto : public oatpp::DTO {
|
||||
|
||||
DTO_INIT(UserDto, Object)
|
||||
DTO_INIT(UserDto, DTO)
|
||||
|
||||
DTO_FIELD(Int64, id);
|
||||
DTO_FIELD(String, name);
|
||||
|
Loading…
Reference in New Issue
Block a user