Skip to content

Commit 2920956

Browse files
committed
Update to the latest oatpp API.
1 parent d417eff commit 2920956

File tree

7 files changed

+31
-31
lines changed

7 files changed

+31
-31
lines changed

src/AppComponent.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class AppComponent {
2323
/**
2424
* This should be configured through config-server ex. Consul
2525
*/
26-
OATPP_CREATE_COMPONENT(ConfigDto::ObjectWrapper, config)([this] {
26+
OATPP_CREATE_COMPONENT(oatpp::Object<ConfigDto>, config)([this] {
2727

2828
const char* configPath = CONFIG_PATH;
2929
auto objectMapper = oatpp::parser::json::mapping::ObjectMapper::createShared();

src/ServiceComponent.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class ServiceComponent {
6565
* Create ConnectionProvider component which listens on the port
6666
*/
6767
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, serverConnectionProvider)([] {
68-
OATPP_COMPONENT(ConfigDto::ObjectWrapper, config); // Get config component
68+
OATPP_COMPONENT(oatpp::Object<ConfigDto>, config); // Get config component
6969
return oatpp::network::server::SimpleTCPConnectionProvider::createShared(config->port);
7070
}());
7171

@@ -88,7 +88,7 @@ class ServiceComponent {
8888
}());
8989

9090
OATPP_CREATE_COMPONENT(std::shared_ptr<Database>, database)([] {
91-
OATPP_COMPONENT(ConfigDto::ObjectWrapper, config); // Get config component
91+
OATPP_COMPONENT(oatpp::Object<ConfigDto>, config); // Get config component
9292
auto db = std::make_shared<Database>(config->dbHost, config->dbUser, config->dbPass, config->dbName);
9393
db->connect();
9494
db->init();

src/SwaggerComponent.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class SwaggerComponent {
1616
* General API docs info
1717
*/
1818
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::swagger::DocumentInfo>, swaggerDocumentInfo)([] {
19-
OATPP_COMPONENT(ConfigDto::ObjectWrapper, config); // Get config component
19+
OATPP_COMPONENT(oatpp::Object<ConfigDto>, config); // Get config component
2020

2121
oatpp::swagger::DocumentInfo::Builder builder;
2222

src/controller/UserController.hpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class UserController : public oatpp::web::server::api::ApiController {
2929
: oatpp::web::server::api::ApiController(objectMapper)
3030
{}
3131
private:
32-
OATPP_COMPONENT(ConfigDto::ObjectWrapper, config); // Inject config
32+
OATPP_COMPONENT(oatpp::Object<ConfigDto>, config); // Inject config
3333
OATPP_COMPONENT(std::shared_ptr<Database>, database); // Inject database
3434
private:
3535
void assertUid(const oatpp::String& uid);
@@ -48,12 +48,12 @@ class UserController : public oatpp::web::server::api::ApiController {
4848

4949
ENDPOINT_INFO(createUser) {
5050
info->summary = "Create new User";
51-
info->addConsumes<UserDto>("application/json");
52-
info->addResponse<UserDto>(Status::CODE_200, "application/json");
53-
info->addResponse<ErrorDto>(Status::CODE_500, "application/json");
51+
info->addConsumes<oatpp::Object<UserDto>>("application/json");
52+
info->addResponse<oatpp::Object<UserDto>>(Status::CODE_200, "application/json");
53+
info->addResponse<oatpp::Object<ErrorDto>>(Status::CODE_500, "application/json");
5454
}
5555
ENDPOINT("POST", "/users", createUser,
56-
BODY_DTO(UserDto, user)) {
56+
BODY_DTO(Object<UserDto>, user)) {
5757
assertLogin(user->login);
5858
assertEmail(user->email);
5959
assertPassword(user->password);
@@ -65,8 +65,8 @@ class UserController : public oatpp::web::server::api::ApiController {
6565

6666
ENDPOINT_INFO(getUserByUid) {
6767
info->summary = "Get user by UID";
68-
info->addResponse<UserDto>(Status::CODE_200, "application/json");
69-
info->addResponse<ErrorDto>(Status::CODE_500, "application/json");
68+
info->addResponse<oatpp::Object<UserDto>>(Status::CODE_200, "application/json");
69+
info->addResponse<oatpp::Object<ErrorDto>>(Status::CODE_500, "application/json");
7070
}
7171
ENDPOINT("GET", "/users/uid/{userId}", getUserByUid,
7272
PATH(String, userId)) {
@@ -79,8 +79,8 @@ class UserController : public oatpp::web::server::api::ApiController {
7979

8080
ENDPOINT_INFO(getUserByLogin) {
8181
info->summary = "Get user by Login";
82-
info->addResponse<UserDto>(Status::CODE_200, "application/json");
83-
info->addResponse<ErrorDto>(Status::CODE_500, "application/json");
82+
info->addResponse<oatpp::Object<UserDto>>(Status::CODE_200, "application/json");
83+
info->addResponse<oatpp::Object<ErrorDto>>(Status::CODE_500, "application/json");
8484
}
8585
ENDPOINT("GET", "/users/login/{login}", getUserByLogin,
8686
PATH(String, login)) {
@@ -93,8 +93,8 @@ class UserController : public oatpp::web::server::api::ApiController {
9393

9494
ENDPOINT_INFO(getUserByEmail) {
9595
info->summary = "Get user by Email";
96-
info->addResponse<UserDto>(Status::CODE_200, "application/json");
97-
info->addResponse<ErrorDto>(Status::CODE_500, "application/json");
96+
info->addResponse<oatpp::Object<UserDto>>(Status::CODE_200, "application/json");
97+
info->addResponse<oatpp::Object<ErrorDto>>(Status::CODE_500, "application/json");
9898
}
9999
ENDPOINT("GET", "/users/email/{email}", getUserByEmail,
100100
PATH(String, email)) {

src/db/Database.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void Database::tryReconnect() {
7171
}
7272
}
7373

74-
UserDto::ObjectWrapper Database::readUserFromResult(const ResultWrapper& result, v_int32 index) {
74+
oatpp::Object<UserDto> Database::readUserFromResult(const ResultWrapper& result, v_int32 index) {
7575

7676
auto cuserId = PQfnumber(result.get(), "userId");
7777
auto clogin = PQfnumber(result.get(), "login");
@@ -112,10 +112,10 @@ bool Database::checkResultOrThrow(const ResultWrapper& result) {
112112
}
113113
}
114114

115-
UserDto::ObjectWrapper Database::createUser(const UserDto::ObjectWrapper& user) {
115+
oatpp::Object<UserDto> Database::createUser(const oatpp::Object<UserDto>& user) {
116116
std::lock_guard<std::mutex> lock(m_mutex);
117117
tryReconnect();
118-
UserDto::ObjectWrapper createdUser;
118+
oatpp::Object<UserDto> createdUser;
119119
const v_int32 paramsNumber = 3;
120120
const char* params[paramsNumber] = {user->login->c_str(), user->password->c_str(), user->email->c_str()};
121121
ResultWrapper result = PQexecParams(m_connection, SQL_INSERT_USER, paramsNumber, nullptr, params, nullptr, nullptr, 0);
@@ -127,10 +127,10 @@ UserDto::ObjectWrapper Database::createUser(const UserDto::ObjectWrapper& user)
127127
return createdUser;
128128
}
129129

130-
UserDto::ObjectWrapper Database::getUserByUid(const oatpp::String& uid) {
130+
oatpp::Object<UserDto> Database::getUserByUid(const oatpp::String& uid) {
131131
std::lock_guard<std::mutex> lock(m_mutex);
132132
tryReconnect();
133-
UserDto::ObjectWrapper user;
133+
oatpp::Object<UserDto> user;
134134
const char* params[1] = {uid->c_str()};
135135
ResultWrapper result = PQexecParams(m_connection, SQL_SELECT_USER_BY_USERID, 1, nullptr, params, nullptr, nullptr, 0);
136136
if (checkResultOrThrow(result)) {
@@ -141,10 +141,10 @@ UserDto::ObjectWrapper Database::getUserByUid(const oatpp::String& uid) {
141141
return user;
142142
}
143143

144-
UserDto::ObjectWrapper Database::getUserByLogin(const oatpp::String& login) {
144+
oatpp::Object<UserDto> Database::getUserByLogin(const oatpp::String& login) {
145145
std::lock_guard<std::mutex> lock(m_mutex);
146146
tryReconnect();
147-
UserDto::ObjectWrapper user;
147+
oatpp::Object<UserDto> user;
148148
const char* params[1] = {login->c_str()};
149149
ResultWrapper result = PQexecParams(m_connection, SQL_SELECT_USER_BY_LOGIN, 1, nullptr, params, nullptr, nullptr, 0);
150150
if (checkResultOrThrow(result)) {
@@ -155,10 +155,10 @@ UserDto::ObjectWrapper Database::getUserByLogin(const oatpp::String& login) {
155155
return user;
156156
}
157157

158-
UserDto::ObjectWrapper Database::getUserByEmail(const oatpp::String& email) {
158+
oatpp::Object<UserDto> Database::getUserByEmail(const oatpp::String& email) {
159159
std::lock_guard<std::mutex> lock(m_mutex);
160160
tryReconnect();
161-
UserDto::ObjectWrapper user;
161+
oatpp::Object<UserDto> user;
162162
const char* params[1] = {email->c_str()};
163163
ResultWrapper result = PQexecParams(m_connection, SQL_SELECT_USER_BY_EMAIL, 1, nullptr, params, nullptr, nullptr, 0);
164164
if (checkResultOrThrow(result)) {

src/db/Database.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Database {
4545
std::mutex m_mutex;
4646
private:
4747
void tryReconnect();
48-
UserDto::ObjectWrapper readUserFromResult(const ResultWrapper& result, v_int32 index);
48+
oatpp::Object<UserDto> readUserFromResult(const ResultWrapper& result, v_int32 index);
4949
bool checkResultOrThrow(const ResultWrapper& result);
5050
public:
5151
void connect();
@@ -61,11 +61,11 @@ class Database {
6161

6262
void init();
6363

64-
UserDto::ObjectWrapper createUser(const UserDto::ObjectWrapper& user);
64+
oatpp::Object<UserDto> createUser(const oatpp::Object<UserDto>& user);
6565

66-
UserDto::ObjectWrapper getUserByUid(const oatpp::String& uid);
67-
UserDto::ObjectWrapper getUserByLogin(const oatpp::String& login);
68-
UserDto::ObjectWrapper getUserByEmail(const oatpp::String& email);
66+
oatpp::Object<UserDto> getUserByUid(const oatpp::String& uid);
67+
oatpp::Object<UserDto> getUserByLogin(const oatpp::String& login);
68+
oatpp::Object<UserDto> getUserByEmail(const oatpp::String& email);
6969

7070
};
7171

src/dto/UserDto.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
#include OATPP_CODEGEN_BEGIN(DTO)
99

10-
class UserDto : public oatpp::Object {
10+
class UserDto : public oatpp::DTO {
1111

12-
DTO_INIT(UserDto, Object)
12+
DTO_INIT(UserDto, DTO)
1313

1414
DTO_FIELD(String, userId);
1515
DTO_FIELD(String, login);

0 commit comments

Comments
 (0)