Skip to content

Commit 2300856

Browse files
committed
Update to the latest oatpp API.
1 parent a36a270 commit 2300856

File tree

19 files changed

+83
-118
lines changed

19 files changed

+83
-118
lines changed

book-service/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ target_include_directories(${project_name}-lib PUBLIC src)
2525

2626
## link libs
2727

28-
find_package(oatpp 1.0.0 REQUIRED)
29-
find_package(oatpp-swagger 1.0.0 REQUIRED)
28+
find_package(oatpp 1.1.0 REQUIRED)
29+
find_package(oatpp-swagger 1.1.0 REQUIRED)
3030

3131
target_link_libraries(${project_name}-lib
3232
PUBLIC oatpp::oatpp

book-service/src/book-service/SwaggerComponent.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class SwaggerComponent {
3030
.setLicenseName("The Unlicense")
3131
.setLicenseUrl("http://unlicense.org")
3232

33-
.addServer("http://localhost:8000", "server on localhost");
33+
.addServer("http://localhost:8002", "server on localhost");
3434

3535
return builder.build();
3636

book-service/src/book-service/controller/BookController.hpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace example { namespace book { namespace controller {
1313

14+
#include OATPP_CODEGEN_BEGIN(ApiController) //<-- codegen Begin
15+
1416
class BookController : public oatpp::web::server::api::ApiController {
1517
private:
1618

@@ -26,18 +28,13 @@ class BookController : public oatpp::web::server::api::ApiController {
2628

2729
public:
2830

29-
/**
30-
* Begin ENDPOINTs generation ('ApiController' codegen)
31-
*/
32-
#include OATPP_CODEGEN_BEGIN(ApiController)
33-
3431
ENDPOINT_INFO(createBook) {
3532
info->summary = "Create new Book";
36-
info->addConsumes<dto::BookDto::ObjectWrapper>("application/json");
37-
info->addResponse<dto::BookDto::ObjectWrapper>(Status::CODE_200, "application/json");
33+
info->addConsumes<dto::BookDto>("application/json");
34+
info->addResponse<dto::BookDto>(Status::CODE_200, "application/json");
3835
}
3936
ENDPOINT("POST", "/books", createBook,
40-
BODY_DTO(dto::BookDto::ObjectWrapper, bookDto)) {
37+
BODY_DTO(dto::BookDto, bookDto)) {
4138
OATPP_ASSERT_HTTP(bookDto->authorId, Status::CODE_400, "'authorId' is require!");
4239
return createDtoResponse(Status::CODE_200, m_database->createBook(bookDto));
4340
}
@@ -46,15 +43,15 @@ class BookController : public oatpp::web::server::api::ApiController {
4643
ENDPOINT_INFO(putBook) {
4744
// general
4845
info->summary = "Update Book by bookId";
49-
info->addConsumes<dto::BookDto::ObjectWrapper>("application/json");
50-
info->addResponse<dto::BookDto::ObjectWrapper>(Status::CODE_200, "application/json");
46+
info->addConsumes<dto::BookDto>("application/json");
47+
info->addResponse<dto::BookDto>(Status::CODE_200, "application/json");
5148
info->addResponse<String>(Status::CODE_404, "text/plain");
5249
// params specific
5350
info->pathParams["bookId"].description = "Book Identifier";
5451
}
5552
ENDPOINT("PUT", "/books/{bookId}", putBook,
5653
PATH(Int64, bookId),
57-
BODY_DTO(dto::BookDto::ObjectWrapper, bookDto)) {
54+
BODY_DTO(dto::BookDto, bookDto)) {
5855
bookDto->id = bookId;
5956
return createDtoResponse(Status::CODE_200, m_database->updateBook(bookDto));
6057
}
@@ -63,7 +60,7 @@ class BookController : public oatpp::web::server::api::ApiController {
6360
ENDPOINT_INFO(getBookById) {
6461
// general
6562
info->summary = "Get one Book by bookId";
66-
info->addResponse<dto::BookDto::ObjectWrapper>(Status::CODE_200, "application/json");
63+
info->addResponse<dto::BookDto>(Status::CODE_200, "application/json");
6764
info->addResponse<String>(Status::CODE_404, "text/plain");
6865
// params specific
6966
info->pathParams["bookId"].description = "Book Identifier";
@@ -78,7 +75,7 @@ class BookController : public oatpp::web::server::api::ApiController {
7875

7976
ENDPOINT_INFO(getBooks) {
8077
info->summary = "get all stored books";
81-
info->addResponse<List<dto::BookDto::ObjectWrapper>::ObjectWrapper>(Status::CODE_200, "application/json");
78+
info->addResponse<List<dto::BookDto>>(Status::CODE_200, "application/json");
8279
}
8380
ENDPOINT("GET", "/books", getBooks) {
8481
return createDtoResponse(Status::CODE_200, m_database->getBooks());
@@ -100,13 +97,10 @@ class BookController : public oatpp::web::server::api::ApiController {
10097
return createResponse(Status::CODE_200, "Book successfully deleted");
10198
}
10299

103-
/**
104-
* Finish ENDPOINTs generation ('ApiController' codegen)
105-
*/
106-
#include OATPP_CODEGEN_END(ApiController)
107-
108100
};
109101

102+
#include OATPP_CODEGEN_END(ApiController) //<-- codegen End
103+
110104
}}}
111105

112106
#endif /* example_book_BookController_hpp */

book-service/src/book-service/db/Database.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ namespace example { namespace book { namespace db {
66
model::Book Database::serializeFromDto(const dto::BookDto::ObjectWrapper &bookDto) {
77
model::Book book;
88
if (bookDto->id) {
9-
book.id = bookDto->id->getValue();
9+
book.id = bookDto->id;
1010
}
1111
book.title = bookDto->title;
12-
book.authorId = bookDto->authorId->getValue();
12+
book.authorId = bookDto->authorId;
1313
return book;
1414
}
1515

@@ -58,7 +58,7 @@ oatpp::data::mapping::type::List<dto::BookDto::ObjectWrapper>::ObjectWrapper Dat
5858
auto result = oatpp::data::mapping::type::List<dto::BookDto::ObjectWrapper>::createShared();
5959
auto it = m_booksById.begin();
6060
while (it != m_booksById.end()) {
61-
result->pushBack(deserializeToDto(it->second));
61+
result->push_back(deserializeToDto(it->second));
6262
it++;
6363
}
6464
return result;

book-service/src/book-service/db/Database.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ class Database {
3030

3131
/* Prepopulate Database */
3232

33-
createBook(dto::BookDto::create(0, 1, "The Great Gatsby"));
34-
createBook(dto::BookDto::create(0, 2, "To Kill a Mockingbird"));
35-
createBook(dto::BookDto::create(0, 3, "Harry Potter and the Sorcerer's Stone"));
36-
createBook(dto::BookDto::create(0, 4, "1984"));
37-
createBook(dto::BookDto::create(0, 5, "The Catcher in the Rye"));
33+
createBook(dto::BookDto::createShared(0, 1, "The Great Gatsby"));
34+
createBook(dto::BookDto::createShared(0, 2, "To Kill a Mockingbird"));
35+
createBook(dto::BookDto::createShared(0, 3, "Harry Potter and the Sorcerer's Stone"));
36+
createBook(dto::BookDto::createShared(0, 4, "1984"));
37+
createBook(dto::BookDto::createShared(0, 5, "The Catcher in the Rye"));
3838

3939
}
4040

book-service/src/book-service/dto/BookDto.hpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
#ifndef example_book_dto_BookDto_hpp
33
#define example_book_dto_BookDto_hpp
44

5-
#include "oatpp/core/data/mapping/type/Object.hpp"
5+
#include "oatpp/core/Types.hpp"
66
#include "oatpp/core/macro/codegen.hpp"
77

88
namespace example { namespace book { namespace dto {
99

1010
#include OATPP_CODEGEN_BEGIN(DTO)
1111

12-
class BookDto : public oatpp::data::mapping::type::Object {
12+
class BookDto : public oatpp::Object {
1313

1414
DTO_INIT(BookDto, Object)
1515

@@ -19,17 +19,11 @@ class BookDto : public oatpp::data::mapping::type::Object {
1919

2020
public:
2121

22-
static BookDto::ObjectWrapper create(v_int64 id, v_int64 authorId, const String& title) {
23-
24-
auto dto = BookDto::createShared();
25-
26-
dto->id = id;
27-
dto->authorId = authorId;
28-
dto->title = title;
29-
30-
return dto;
31-
32-
}
22+
BookDto(v_int64 pId, v_int64 pAuthorId, const String& pTitle)
23+
: id(pId)
24+
, authorId(pAuthorId)
25+
, title(pTitle)
26+
{}
3327

3428
};
3529

facade/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ target_include_directories(${project_name}-lib PUBLIC src)
2727

2828
## link libs
2929

30-
find_package(oatpp 1.0.0 REQUIRED)
31-
find_package(oatpp-swagger 1.0.0 REQUIRED)
30+
find_package(oatpp 1.1.0 REQUIRED)
31+
find_package(oatpp-swagger 1.1.0 REQUIRED)
3232

3333
target_link_libraries(${project_name}-lib
3434
PUBLIC oatpp::oatpp

facade/src/facade/controller/BookController.hpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
namespace example { namespace facade { namespace controller {
1919

20+
#include OATPP_CODEGEN_BEGIN(ApiController) //<--- codegen begin
21+
2022
class BookController : public oatpp::web::server::api::ApiController {
2123
private:
2224

@@ -30,15 +32,10 @@ class BookController : public oatpp::web::server::api::ApiController {
3032

3133
public:
3234

33-
/**
34-
* Begin ENDPOINTs generation ('ApiController' codegen)
35-
*/
36-
#include OATPP_CODEGEN_BEGIN(ApiController)
37-
3835
ENDPOINT_INFO(getBookById) {
3936
// general
4037
info->summary = "Get one Book by bookId";
41-
info->addResponse<dto::BookInfoDto::ObjectWrapper>(Status::CODE_200, "application/json");
38+
info->addResponse<dto::BookInfoDto>(Status::CODE_200, "application/json");
4239
info->addResponse<String>(Status::CODE_404, "text/plain");
4340
// params specific
4441
info->pathParams["bookId"].description = "Book Identifier";
@@ -68,19 +65,16 @@ class BookController : public oatpp::web::server::api::ApiController {
6865

6966
// ENDPOINT_INFO(getBooks) {
7067
// info->summary = "get all stored books";
71-
// info->addResponse<List<dto::BookDto::ObjectWrapper>::ObjectWrapper>(Status::CODE_200, "application/json");
68+
// info->addResponse<List<dto::BookDto>>(Status::CODE_200, "application/json");
7269
// }
7370
// ENDPOINT("GET", "/books", getBooks) {
7471
// return createDtoResponse(Status::CODE_200, m_database->getBooks());
7572
// }
7673

77-
/**
78-
* Finish ENDPOINTs generation ('ApiController' codegen)
79-
*/
80-
#include OATPP_CODEGEN_END(ApiController)
81-
8274
};
8375

76+
#include OATPP_CODEGEN_END(ApiController) //<--- codegen end
77+
8478
}}}
8579

8680
#endif /* example_facade_BookController_hpp */

facade/src/facade/controller/UserController.hpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
namespace example { namespace facade { namespace controller {
1414

15+
#include OATPP_CODEGEN_BEGIN(ApiController) //<--- codegen begin
16+
1517
class UserController : public oatpp::web::server::api::ApiController {
1618
public:
1719

@@ -20,19 +22,12 @@ class UserController : public oatpp::web::server::api::ApiController {
2022

2123
public:
2224

23-
/**
24-
* Begin ENDPOINTs generation ('ApiController' codegen)
25-
*/
26-
#include OATPP_CODEGEN_BEGIN(ApiController)
27-
28-
29-
/**
30-
* Finish ENDPOINTs generation ('ApiController' codegen)
31-
*/
32-
#include OATPP_CODEGEN_END(ApiController)
25+
// TODO - endpoints here
3326

3427
};
3528

29+
#include OATPP_CODEGEN_END(ApiController) //<--- codegen end
30+
3631
}}}
3732

3833
#endif /* example_facade_UserController_hpp */

facade/src/facade/dto/BookDto.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
#ifndef example_facade_dto_BookDto_hpp
33
#define example_facade_dto_BookDto_hpp
44

5-
#include "oatpp/core/data/mapping/type/Object.hpp"
5+
#include "oatpp/core/Types.hpp"
66
#include "oatpp/core/macro/codegen.hpp"
77

88
namespace example { namespace facade { namespace dto {
99

1010
#include OATPP_CODEGEN_BEGIN(DTO)
1111

12-
class BookDto : public oatpp::data::mapping::type::Object {
12+
class BookDto : public oatpp::Object {
1313

1414
DTO_INIT(BookDto, Object)
1515

0 commit comments

Comments
 (0)