Skip to content

Commit 1ba49bc

Browse files
committed
update to the latest oatpp API version.
1 parent 0bea5ad commit 1ba49bc

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ target_include_directories(crud-lib PUBLIC src)
2525

2626
## link libs
2727

28-
find_package(oatpp 1.2.5 REQUIRED)
29-
find_package(oatpp-swagger 1.2.5 REQUIRED)
30-
find_package(oatpp-sqlite 1.2.5 REQUIRED)
28+
find_package(oatpp 1.3.0 REQUIRED)
29+
find_package(oatpp-swagger 1.3.0 REQUIRED)
30+
find_package(oatpp-sqlite 1.3.0 REQUIRED)
3131

3232
target_link_libraries(crud-lib
3333
# Oat++

src/App.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,15 @@ void run() {
1414

1515
AppComponent components; // Create scope Environment components
1616

17-
/* create ApiControllers and add endpoints to router */
18-
19-
auto router = components.httpRouter.getObject();
20-
auto docEndpoints = oatpp::swagger::Controller::Endpoints::createShared();
21-
22-
auto userController = UserController::createShared();
23-
userController->addEndpointsToRouter(router);
24-
25-
docEndpoints->pushBackAll(userController->getEndpoints());
26-
27-
auto swaggerController = oatpp::swagger::Controller::createShared(docEndpoints);
28-
swaggerController->addEndpointsToRouter(router);
17+
/* Get router component */
18+
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router);
19+
20+
oatpp::web::server::api::Endpoints docEndpoints;
21+
22+
docEndpoints.append(router->addController(UserController::createShared())->getEndpoints());
2923

30-
auto staticController = StaticController::createShared();
31-
staticController->addEndpointsToRouter(router);
24+
router->addController(oatpp::swagger::Controller::createShared(docEndpoints));
25+
router->addController(StaticController::createShared());
3226

3327
/* Get connection handler component */
3428
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>, connectionHandler);

src/service/UserService.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ oatpp::Object<UserDto> UserService::updateUser(const oatpp::Object<UserDto>& dto
2020

2121
}
2222

23-
oatpp::Object<UserDto> UserService::getUserById(const oatpp::Int32& id, const std::shared_ptr<oatpp::orm::Connection>& connection) {
23+
oatpp::Object<UserDto> UserService::getUserById(const oatpp::Int32& id, const oatpp::provider::ResourceHandle<oatpp::orm::Connection>& connection) {
2424

2525
auto dbResult = m_database->getUserById(id, connection);
2626
OATPP_ASSERT_HTTP(dbResult->isSuccess(), Status::CODE_500, dbResult->getErrorMessage());

src/service/UserService.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class UserService {
1818

1919
oatpp::Object<UserDto> createUser(const oatpp::Object<UserDto>& dto);
2020
oatpp::Object<UserDto> updateUser(const oatpp::Object<UserDto>& dto);
21-
oatpp::Object<UserDto> getUserById(const oatpp::Int32& id, const std::shared_ptr<oatpp::orm::Connection>& connection = nullptr);
21+
oatpp::Object<UserDto> getUserById(const oatpp::Int32& id, const oatpp::provider::ResourceHandle<oatpp::orm::Connection>& connection = nullptr);
2222
oatpp::Object<PageDto<oatpp::Object<UserDto>>> getAllUsers(const oatpp::UInt32& offset, const oatpp::UInt32& limit);
2323
oatpp::Object<StatusDto> deleteUserById(const oatpp::Int32& id);
2424

0 commit comments

Comments
 (0)