From a155876da6bba55c1e8b7f4a3fba9a5db005cf80 Mon Sep 17 00:00:00 2001 From: lganzzzo Date: Sun, 24 May 2020 00:08:46 +0300 Subject: [PATCH] Update to the latest oatpp API. --- .../book-service/controller/BookController.hpp | 16 ++++++++-------- book-service/src/book-service/db/Database.cpp | 14 +++++++------- book-service/src/book-service/db/Database.hpp | 14 +++++++------- book-service/src/book-service/dto/BookDto.hpp | 4 ++-- facade/src/facade/dto/BookDto.hpp | 4 ++-- facade/src/facade/dto/BookInfoDto.hpp | 4 ++-- facade/src/facade/dto/UserDto.hpp | 4 ++-- .../user-service/controller/UserController.hpp | 16 ++++++++-------- user-service/src/user-service/db/Database.cpp | 14 +++++++------- user-service/src/user-service/db/Database.hpp | 14 +++++++------- user-service/src/user-service/dto/UserDto.hpp | 4 ++-- 11 files changed, 54 insertions(+), 54 deletions(-) diff --git a/book-service/src/book-service/controller/BookController.hpp b/book-service/src/book-service/controller/BookController.hpp index 6e1b1a2..5559bfd 100644 --- a/book-service/src/book-service/controller/BookController.hpp +++ b/book-service/src/book-service/controller/BookController.hpp @@ -30,11 +30,11 @@ class BookController : public oatpp::web::server::api::ApiController { ENDPOINT_INFO(createBook) { info->summary = "Create new Book"; - info->addConsumes("application/json"); - info->addResponse(Status::CODE_200, "application/json"); + info->addConsumes>("application/json"); + info->addResponse>(Status::CODE_200, "application/json"); } ENDPOINT("POST", "/books", createBook, - BODY_DTO(dto::BookDto, bookDto)) { + BODY_DTO(Object, bookDto)) { OATPP_ASSERT_HTTP(bookDto->authorId, Status::CODE_400, "'authorId' is require!"); return createDtoResponse(Status::CODE_200, m_database->createBook(bookDto)); } @@ -43,15 +43,15 @@ class BookController : public oatpp::web::server::api::ApiController { ENDPOINT_INFO(putBook) { // general info->summary = "Update Book by bookId"; - info->addConsumes("application/json"); - info->addResponse(Status::CODE_200, "application/json"); + info->addConsumes>("application/json"); + info->addResponse>(Status::CODE_200, "application/json"); info->addResponse(Status::CODE_404, "text/plain"); // params specific info->pathParams["bookId"].description = "Book Identifier"; } ENDPOINT("PUT", "/books/{bookId}", putBook, PATH(Int64, bookId), - BODY_DTO(dto::BookDto, bookDto)) { + BODY_DTO(Object, bookDto)) { bookDto->id = bookId; return createDtoResponse(Status::CODE_200, m_database->updateBook(bookDto)); } @@ -60,7 +60,7 @@ class BookController : public oatpp::web::server::api::ApiController { ENDPOINT_INFO(getBookById) { // general info->summary = "Get one Book by bookId"; - info->addResponse(Status::CODE_200, "application/json"); + info->addResponse>(Status::CODE_200, "application/json"); info->addResponse(Status::CODE_404, "text/plain"); // params specific info->pathParams["bookId"].description = "Book Identifier"; @@ -75,7 +75,7 @@ class BookController : public oatpp::web::server::api::ApiController { ENDPOINT_INFO(getBooks) { info->summary = "get all stored books"; - info->addResponse>(Status::CODE_200, "application/json"); + info->addResponse>>(Status::CODE_200, "application/json"); } ENDPOINT("GET", "/books", getBooks) { return createDtoResponse(Status::CODE_200, m_database->getBooks()); diff --git a/book-service/src/book-service/db/Database.cpp b/book-service/src/book-service/db/Database.cpp index 771758f..40c2576 100644 --- a/book-service/src/book-service/db/Database.cpp +++ b/book-service/src/book-service/db/Database.cpp @@ -3,7 +3,7 @@ namespace example { namespace book { namespace db { -model::Book Database::serializeFromDto(const dto::BookDto::ObjectWrapper &bookDto) { +model::Book Database::serializeFromDto(const oatpp::Object &bookDto) { model::Book book; if (bookDto->id) { book.id = bookDto->id; @@ -13,7 +13,7 @@ model::Book Database::serializeFromDto(const dto::BookDto::ObjectWrapper &bookDt return book; } -dto::BookDto::ObjectWrapper Database::deserializeToDto(const model::Book &book) { +oatpp::Object Database::deserializeToDto(const model::Book &book) { auto dto = dto::BookDto::createShared(); dto->id = book.id; dto->title = book.title; @@ -21,7 +21,7 @@ dto::BookDto::ObjectWrapper Database::deserializeToDto(const model::Book &book) return dto; } -dto::BookDto::ObjectWrapper Database::createBook(const dto::BookDto::ObjectWrapper &bookDto) { +oatpp::Object Database::createBook(const oatpp::Object &bookDto) { std::lock_guard lock(m_lock); auto book = serializeFromDto(bookDto); book.id = m_idCounter++; @@ -29,7 +29,7 @@ dto::BookDto::ObjectWrapper Database::createBook(const dto::BookDto::ObjectWrapp return deserializeToDto(book); } -dto::BookDto::ObjectWrapper Database::updateBook(const dto::BookDto::ObjectWrapper &bookDto) { +oatpp::Object Database::updateBook(const oatpp::Object &bookDto) { std::lock_guard lock(m_lock); auto book = serializeFromDto(bookDto); if (book.id < 0) { @@ -44,7 +44,7 @@ dto::BookDto::ObjectWrapper Database::updateBook(const dto::BookDto::ObjectWrapp return deserializeToDto(book); } -dto::BookDto::ObjectWrapper Database::getBookById(v_int64 id) { +oatpp::Object Database::getBookById(v_int64 id) { std::lock_guard lock(m_lock); auto it = m_booksById.find(id); if (it == m_booksById.end()) { @@ -53,9 +53,9 @@ dto::BookDto::ObjectWrapper Database::getBookById(v_int64 id) { return deserializeToDto(it->second); } -oatpp::data::mapping::type::List::ObjectWrapper Database::getBooks() { +oatpp::List> Database::getBooks() { std::lock_guard lock(m_lock); - auto result = oatpp::data::mapping::type::List::createShared(); + auto result = oatpp::List>::createShared(); auto it = m_booksById.begin(); while (it != m_booksById.end()) { result->push_back(deserializeToDto(it->second)); diff --git a/book-service/src/book-service/db/Database.hpp b/book-service/src/book-service/db/Database.hpp index 0ca66cf..24113e0 100644 --- a/book-service/src/book-service/db/Database.hpp +++ b/book-service/src/book-service/db/Database.hpp @@ -20,8 +20,8 @@ class Database { v_int64 m_idCounter; ///< counter to generate bookIds std::unordered_map m_booksById; ///< Map bookId to Book private: - model::Book serializeFromDto(const dto::BookDto::ObjectWrapper& bookDto); - dto::BookDto::ObjectWrapper deserializeToDto(const model::Book& book); + model::Book serializeFromDto(const oatpp::Object& bookDto); + oatpp::Object deserializeToDto(const model::Book& book); public: Database() @@ -37,11 +37,11 @@ class Database { createBook(dto::BookDto::createShared(0, 5, "The Catcher in the Rye")); } - - dto::BookDto::ObjectWrapper createBook(const dto::BookDto::ObjectWrapper& bookDto); - dto::BookDto::ObjectWrapper updateBook(const dto::BookDto::ObjectWrapper& bookDto); - dto::BookDto::ObjectWrapper getBookById(v_int64 id); - oatpp::data::mapping::type::List::ObjectWrapper getBooks(); + + oatpp::Object createBook(const oatpp::Object& bookDto); + oatpp::Object updateBook(const oatpp::Object& bookDto); + oatpp::Object getBookById(v_int64 id); + oatpp::List> getBooks(); bool deleteBook(v_int64 id); }; diff --git a/book-service/src/book-service/dto/BookDto.hpp b/book-service/src/book-service/dto/BookDto.hpp index 9a25cb3..dd1ba7f 100644 --- a/book-service/src/book-service/dto/BookDto.hpp +++ b/book-service/src/book-service/dto/BookDto.hpp @@ -9,9 +9,9 @@ namespace example { namespace book { namespace dto { #include OATPP_CODEGEN_BEGIN(DTO) -class BookDto : public oatpp::Object { +class BookDto : public oatpp::DTO { - DTO_INIT(BookDto, Object) + DTO_INIT(BookDto, DTO) DTO_FIELD(Int64, id); DTO_FIELD(Int64, authorId, "authorId"); diff --git a/facade/src/facade/dto/BookDto.hpp b/facade/src/facade/dto/BookDto.hpp index e665b02..ac9f894 100644 --- a/facade/src/facade/dto/BookDto.hpp +++ b/facade/src/facade/dto/BookDto.hpp @@ -9,9 +9,9 @@ namespace example { namespace facade { namespace dto { #include OATPP_CODEGEN_BEGIN(DTO) -class BookDto : public oatpp::Object { +class BookDto : public oatpp::DTO { - DTO_INIT(BookDto, Object) + DTO_INIT(BookDto, DTO) DTO_FIELD(Int64, id); DTO_FIELD(Int64, authorId, "authorId"); diff --git a/facade/src/facade/dto/BookInfoDto.hpp b/facade/src/facade/dto/BookInfoDto.hpp index 65a9458..cb0d77c 100644 --- a/facade/src/facade/dto/BookInfoDto.hpp +++ b/facade/src/facade/dto/BookInfoDto.hpp @@ -11,9 +11,9 @@ namespace example { namespace facade { namespace dto { #include OATPP_CODEGEN_BEGIN(DTO) -class BookInfoDto : public oatpp::Object { +class BookInfoDto : public oatpp::DTO { - DTO_INIT(BookInfoDto, Object) + DTO_INIT(BookInfoDto, DTO) DTO_FIELD(Int64, id); DTO_FIELD(String, title, "title"); diff --git a/facade/src/facade/dto/UserDto.hpp b/facade/src/facade/dto/UserDto.hpp index 19e0954..db7d4e5 100644 --- a/facade/src/facade/dto/UserDto.hpp +++ b/facade/src/facade/dto/UserDto.hpp @@ -9,9 +9,9 @@ namespace example { namespace facade { namespace dto { #include OATPP_CODEGEN_BEGIN(DTO) -class UserDto : public oatpp::Object { +class UserDto : public oatpp::DTO { - DTO_INIT(UserDto, Object) + DTO_INIT(UserDto, DTO) DTO_FIELD(Int64, id); DTO_FIELD(String, name, "name"); diff --git a/user-service/src/user-service/controller/UserController.hpp b/user-service/src/user-service/controller/UserController.hpp index 877e380..488d4a3 100644 --- a/user-service/src/user-service/controller/UserController.hpp +++ b/user-service/src/user-service/controller/UserController.hpp @@ -30,11 +30,11 @@ class UserController : public oatpp::web::server::api::ApiController { ENDPOINT_INFO(createUser) { info->summary = "Create new User"; - info->addConsumes("application/json"); - info->addResponse(Status::CODE_200, "application/json"); + info->addConsumes>("application/json"); + info->addResponse>(Status::CODE_200, "application/json"); } ENDPOINT("POST", "/users", createUser, - BODY_DTO(dto::UserDto, userDto)) { + BODY_DTO(Object, userDto)) { return createDtoResponse(Status::CODE_200, m_database->createUser(userDto)); } @@ -42,15 +42,15 @@ class UserController : public oatpp::web::server::api::ApiController { ENDPOINT_INFO(putUser) { // general info->summary = "Update User by userId"; - info->addConsumes("application/json"); - info->addResponse(Status::CODE_200, "application/json"); + info->addConsumes>("application/json"); + info->addResponse>(Status::CODE_200, "application/json"); info->addResponse(Status::CODE_404, "text/plain"); // params specific info->pathParams["userId"].description = "User Identifier"; } ENDPOINT("PUT", "/users/{userId}", putUser, PATH(Int64, userId), - BODY_DTO(dto::UserDto, userDto)) { + BODY_DTO(Object, userDto)) { userDto->id = userId; return createDtoResponse(Status::CODE_200, m_database->updateUser(userDto)); } @@ -59,7 +59,7 @@ class UserController : public oatpp::web::server::api::ApiController { ENDPOINT_INFO(getUserById) { // general info->summary = "Get one User by userId"; - info->addResponse(Status::CODE_200, "application/json"); + info->addResponse>(Status::CODE_200, "application/json"); info->addResponse(Status::CODE_404, "text/plain"); // params specific info->pathParams["userId"].description = "User Identifier"; @@ -74,7 +74,7 @@ class UserController : public oatpp::web::server::api::ApiController { ENDPOINT_INFO(getUsers) { info->summary = "get all stored users"; - info->addResponse>(Status::CODE_200, "application/json"); + info->addResponse>>(Status::CODE_200, "application/json"); } ENDPOINT("GET", "/users", getUsers) { return createDtoResponse(Status::CODE_200, m_database->getUsers()); diff --git a/user-service/src/user-service/db/Database.cpp b/user-service/src/user-service/db/Database.cpp index 429807e..46ec1a2 100644 --- a/user-service/src/user-service/db/Database.cpp +++ b/user-service/src/user-service/db/Database.cpp @@ -3,7 +3,7 @@ namespace example { namespace user { namespace db { -model::User Database::serializeFromDto(const dto::UserDto::ObjectWrapper &userDto) { +model::User Database::serializeFromDto(const oatpp::Object &userDto) { model::User user; if (userDto->id) { user.id = userDto->id; @@ -12,14 +12,14 @@ model::User Database::serializeFromDto(const dto::UserDto::ObjectWrapper &userDt return user; } -dto::UserDto::ObjectWrapper Database::deserializeToDto(const model::User &user) { +oatpp::Object Database::deserializeToDto(const model::User &user) { auto dto = dto::UserDto::createShared(); dto->id = user.id; dto->name = user.name; return dto; } -dto::UserDto::ObjectWrapper Database::createUser(const dto::UserDto::ObjectWrapper &userDto) { +oatpp::Object Database::createUser(const oatpp::Object &userDto) { std::lock_guard lock(m_lock); auto user = serializeFromDto(userDto); user.id = m_idCounter++; @@ -27,7 +27,7 @@ dto::UserDto::ObjectWrapper Database::createUser(const dto::UserDto::ObjectWrapp return deserializeToDto(user); } -dto::UserDto::ObjectWrapper Database::updateUser(const dto::UserDto::ObjectWrapper &userDto) { +oatpp::Object Database::updateUser(const oatpp::Object &userDto) { std::lock_guard lock(m_lock); auto user = serializeFromDto(userDto); if (user.id < 0) { @@ -42,7 +42,7 @@ dto::UserDto::ObjectWrapper Database::updateUser(const dto::UserDto::ObjectWrapp return deserializeToDto(user); } -dto::UserDto::ObjectWrapper Database::getUserById(v_int64 id) { +oatpp::Object Database::getUserById(v_int64 id) { std::lock_guard lock(m_lock); auto it = m_usersById.find(id); if (it == m_usersById.end()) { @@ -51,9 +51,9 @@ dto::UserDto::ObjectWrapper Database::getUserById(v_int64 id) { return deserializeToDto(it->second); } -oatpp::List Database::getUsers() { +oatpp::List> Database::getUsers() { std::lock_guard lock(m_lock); - auto result = oatpp::List::createShared(); + auto result = oatpp::List>::createShared(); auto it = m_usersById.begin(); while (it != m_usersById.end()) { result->push_back(deserializeToDto(it->second)); diff --git a/user-service/src/user-service/db/Database.hpp b/user-service/src/user-service/db/Database.hpp index 3f07a85..dfa4d46 100644 --- a/user-service/src/user-service/db/Database.hpp +++ b/user-service/src/user-service/db/Database.hpp @@ -20,8 +20,8 @@ class Database { v_int64 m_idCounter; ///< counter to generate userIds std::unordered_map m_usersById; ///< Map userId to User private: - model::User serializeFromDto(const dto::UserDto::ObjectWrapper& userDto); - dto::UserDto::ObjectWrapper deserializeToDto(const model::User& user); + model::User serializeFromDto(const oatpp::Object& userDto); + oatpp::Object deserializeToDto(const model::User& user); public: Database() @@ -37,11 +37,11 @@ class Database { createUser(dto::UserDto::createShared(0, "J.D. Salinger")); } - - dto::UserDto::ObjectWrapper createUser(const dto::UserDto::ObjectWrapper& userDto); - dto::UserDto::ObjectWrapper updateUser(const dto::UserDto::ObjectWrapper& userDto); - dto::UserDto::ObjectWrapper getUserById(v_int64 id); - oatpp::List getUsers(); + + oatpp::Object createUser(const oatpp::Object& userDto); + oatpp::Object updateUser(const oatpp::Object& userDto); + oatpp::Object getUserById(v_int64 id); + oatpp::List> getUsers(); bool deleteUser(v_int64 id); }; diff --git a/user-service/src/user-service/dto/UserDto.hpp b/user-service/src/user-service/dto/UserDto.hpp index 6ba5d19..222131a 100644 --- a/user-service/src/user-service/dto/UserDto.hpp +++ b/user-service/src/user-service/dto/UserDto.hpp @@ -9,9 +9,9 @@ namespace example { namespace user { namespace dto { #include OATPP_CODEGEN_BEGIN(DTO) -class UserDto : public oatpp::Object { +class UserDto : public oatpp::DTO { - DTO_INIT(UserDto, Object) + DTO_INIT(UserDto, DTO) DTO_FIELD(Int64, id); DTO_FIELD(String, name, "name");