Skip to content

Commit fcc18ee

Browse files
committed
Prepare first version
1 parent 47eefe3 commit fcc18ee

9 files changed

+107
-32
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ addons:
1717
# Build steps
1818
script:
1919
- ./build_simple.sh
20+
- ./wsjcpp-dto
2021
- cd unit-tests.wsjcpp
2122
- ./build_simple.sh
2223
- ./unit-tests

README.md

+10-11
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,24 @@ Helper classes for create C++ Data Transfer Object
66

77
## Integrate to your project
88

9-
Include this files:
10-
11-
* src.wsjcpp/nlohmann_json/json.hpp
12-
* src/wsjcpp_dto.h
13-
* src/wsjcpp_dto.cpp
14-
15-
Or use a `wsjcpp`:
9+
Use a `wsjcpp`:
1610

1711
```
1812
$ wsjcpp install https://github.com/wsjcpp/wsjcpp-dto:master
1913
```
2014

21-
## How to use:
15+
Or include this files:
16+
17+
* src.wsjcpp/nlohmann_json/json.hpp
18+
* src/wsjcpp_dto.h
19+
* src/wsjcpp_dto.cpp
20+
21+
## How to use
2222

2323
```
24-
class WsjcppDtoPerson : public WsjcppDefineDto {
24+
class WsjcppDtoPerson : public WsjcppDto {
2525
public:
26-
WsjcppDtoPerson() : WsjcppDefineDto("person", "Person") {
27-
// requireField<WsjcppDtoString>("name", "Name of person");
26+
WsjcppDtoPerson() : WsjcppDto("person", "Person") {
2827
requireField<WsjcppDtoString>("name", "Name of person");
2928
optionalField<WsjcppDtoInteger>("age", "Age of person");
3029
};

src/main.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
#include <wsjcpp_core.h>
55
#include <wsjcpp_dto.h>
66

7-
class WsjcppDtoPerson : public WsjcppDefineDto {
7+
class WsjcppDtoPerson : public WsjcppDto {
88
public:
9-
WsjcppDtoPerson() : WsjcppDefineDto("person", "Person") {
9+
WsjcppDtoPerson() : WsjcppDto("person", "Person") {
1010
// requireField<WsjcppDtoString>("name", "Name of person");
1111
requireField<WsjcppDtoString>("name", "Name of person");
1212
optionalField<WsjcppDtoInteger>("age", "Age of person");
1313
};
1414
};
1515

16-
class WsjcppDtoUserProfile : public WsjcppDefineDto {
16+
class WsjcppDtoUserProfile : public WsjcppDto {
1717
public:
18-
WsjcppDtoUserProfile() : WsjcppDefineDto("user_profile", "User Profile") {
18+
WsjcppDtoUserProfile() : WsjcppDto("user_profile", "User Profile") {
1919
// requireField<WsjcppDtoString>("name", "Name of person");
2020
requireField<WsjcppDtoInteger>("userid", "User Id");
2121
requireField<WsjcppDtoString>("", "Current Page");
@@ -26,9 +26,9 @@ class WsjcppDtoUserProfile : public WsjcppDefineDto {
2626
};
2727
};
2828

29-
class WsjcppDtoPersonsPage : public WsjcppDefineDto {
29+
class WsjcppDtoPersonsPage : public WsjcppDto {
3030
public:
31-
WsjcppDtoPersonsPage() : WsjcppDefineDto("persons_page", "Persons page") {
31+
WsjcppDtoPersonsPage() : WsjcppDto("persons_page", "Persons page") {
3232
// requireField<WsjcppDtoString>("name", "Name of person");
3333
requireField<WsjcppDtoInteger>("page", "Current Page");
3434
requireField<WsjcppDtoInteger>("onpage", "Nomebr per page");

src/wsjcpp_dto.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -80,29 +80,29 @@ WsjcppDtoInteger::WsjcppDtoInteger(const std::string &sName, const std::string &
8080
}
8181

8282
// ---------------------------------------------------------------------
83-
// WsjcppDefineDto
83+
// WsjcppDto
8484

85-
WsjcppDefineDto::WsjcppDefineDto(const std::string &sTypeName, const std::string &sDescription) {
85+
WsjcppDto::WsjcppDto(const std::string &sTypeName, const std::string &sDescription) {
8686
TAG = "DTO-" + sTypeName;
8787
m_sTypeName = sTypeName;
8888
m_sDescription = sDescription;
8989
}
9090

9191
// ---------------------------------------------------------------------
9292

93-
const std::string &WsjcppDefineDto::getTypeName() {
93+
const std::string &WsjcppDto::getTypeName() {
9494
return m_sTypeName;
9595
}
9696

9797
// ---------------------------------------------------------------------
9898

99-
const std::string &WsjcppDefineDto::getDescription() {
99+
const std::string &WsjcppDto::getDescription() {
100100
return m_sDescription;
101101
}
102102

103103
// ---------------------------------------------------------------------
104104

105-
bool WsjcppDefineDto::setFieldStringValue(const std::string &sFieldName, const std::string &sFieldValue) {
105+
bool WsjcppDto::setFieldStringValue(const std::string &sFieldName, const std::string &sFieldValue) {
106106
WsjcppDefineFieldDto *pField = this->findFieldByName(sFieldName);
107107
if (pField == nullptr) {
108108
WsjcppLog::throw_err(TAG, "Object '" + m_sTypeName + "' has not field '" + sFieldName + "'");
@@ -117,7 +117,7 @@ bool WsjcppDefineDto::setFieldStringValue(const std::string &sFieldName, const s
117117

118118
// ---------------------------------------------------------------------
119119

120-
bool WsjcppDefineDto::setFieldIntegerValue(const std::string &sFieldName, int nValue) {
120+
bool WsjcppDto::setFieldIntegerValue(const std::string &sFieldName, int nValue) {
121121
WsjcppDefineFieldDto *pField = this->findFieldByName(sFieldName);
122122
if (pField == nullptr) {
123123
WsjcppLog::throw_err(TAG, "Object '" + m_sTypeName + "' has not field '" + sFieldName + "'");
@@ -130,7 +130,7 @@ bool WsjcppDefineDto::setFieldIntegerValue(const std::string &sFieldName, int nV
130130

131131
// ---------------------------------------------------------------------
132132

133-
bool WsjcppDefineDto::setFieldBooleanValue(const std::string &sFieldName, bool bValue) {
133+
bool WsjcppDto::setFieldBooleanValue(const std::string &sFieldName, bool bValue) {
134134
WsjcppDefineFieldDto *pField = this->findFieldByName(sFieldName);
135135
if (pField == nullptr) {
136136
WsjcppLog::throw_err(TAG, "Object '" + m_sTypeName + "' has not field '" + sFieldName + "'");
@@ -143,7 +143,7 @@ bool WsjcppDefineDto::setFieldBooleanValue(const std::string &sFieldName, bool b
143143

144144
// ---------------------------------------------------------------------
145145

146-
bool WsjcppDefineDto::setFieldJsonValue(const std::string &sFieldName, const nlohmann::json &jsonFieldValue) {
146+
bool WsjcppDto::setFieldJsonValue(const std::string &sFieldName, const nlohmann::json &jsonFieldValue) {
147147
WsjcppDefineFieldDto *pField = this->findFieldByName(sFieldName);
148148
if (pField == nullptr) {
149149
WsjcppLog::throw_err(TAG, "Object '" + m_sTypeName + "' has not field '" + sFieldName + "'");
@@ -156,19 +156,19 @@ bool WsjcppDefineDto::setFieldJsonValue(const std::string &sFieldName, const nlo
156156

157157
// ---------------------------------------------------------------------
158158

159-
bool WsjcppDefineDto::fillFromJson(nlohmann::json &jsonData, std::string &sError) {
159+
bool WsjcppDto::fillFromJson(nlohmann::json &jsonData, std::string &sError) {
160160
return false;
161161
}
162162

163163
// ---------------------------------------------------------------------
164164

165-
nlohmann::json WsjcppDefineDto::toJson() {
165+
nlohmann::json WsjcppDto::toJson() {
166166
return m_jsonReadyObject;
167167
}
168168

169169
// ---------------------------------------------------------------------
170170

171-
WsjcppDefineFieldDto *WsjcppDefineDto::findFieldByName(const std::string &sFieldName) {
171+
WsjcppDefineFieldDto *WsjcppDto::findFieldByName(const std::string &sFieldName) {
172172
for (int i = 0; i < m_vFields.size(); i++) {
173173
if (m_vFields[i]->getFieldName() == sFieldName) {
174174
return m_vFields[i];

src/wsjcpp_dto.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ class WsjcppDtoBoolean : public WsjcppDefineFieldDto {
6363
};
6464

6565
// ---------------------------------------------------------------------
66-
// WsjcppDefineDto - parent class for Data Transfer Objects
66+
// WsjcppDto - parent class for Data Transfer Objects
6767

68-
class WsjcppDefineDto {
68+
class WsjcppDto {
6969
public:
70-
WsjcppDefineDto(const std::string &sTypeName, const std::string &sDescription);
70+
WsjcppDto(const std::string &sTypeName, const std::string &sDescription);
7171
const std::string &getTypeName();
7272
const std::string &getDescription();
7373

@@ -115,7 +115,6 @@ class WsjcppDefineDto {
115115
std::string m_sTypeName;
116116
std::string m_sDescription;
117117

118-
119118
std::vector<WsjcppDefineFieldDto *> m_vFields;
120119
nlohmann::json m_jsonReadyObject;
121120

unit-tests.wsjcpp/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ list (APPEND WSJCPP_SOURCES "../src.wsjcpp/nlohmann_json/json.hpp")
3535

3636
# wsjcpp-dto:v0.0.1
3737
list (APPEND WSJCPP_INCLUDE_DIRS "../src")
38+
list (APPEND WSJCPP_SOURCES "../src/wsjcpp_dto.h")
39+
list (APPEND WSJCPP_SOURCES "../src/wsjcpp_dto.cpp")
3840

3941
# unit-tests
4042
list (APPEND WSJCPP_INCLUDE_DIRS "src")
43+
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_dto_person.h")
44+
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_dto_person.cpp")
4145

4246
include(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.user-custom.txt)
4347

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include "unit_test_dto_person.h"
2+
#include <vector>
3+
#include <wsjcpp_core.h>
4+
#include <wsjcpp_dto.h>
5+
6+
REGISTRY_WSJCPP_UNIT_TEST(UnitTestDtoPerson)
7+
8+
UnitTestDtoPerson::UnitTestDtoPerson()
9+
: WsjcppUnitTestBase("UnitTestDtoPerson") {
10+
}
11+
12+
// ---------------------------------------------------------------------
13+
14+
void UnitTestDtoPerson::init() {
15+
// nothing
16+
}
17+
18+
// ---------------------------------------------------------------------
19+
20+
class WsjcppDtoPerson : public WsjcppDto {
21+
public:
22+
WsjcppDtoPerson() : WsjcppDto("person", "Person") {
23+
requireField<WsjcppDtoString>("name", "Name of person");
24+
optionalField<WsjcppDtoInteger>("age", "Age of person");
25+
};
26+
};
27+
28+
// ---------------------------------------------------------------------
29+
30+
bool UnitTestDtoPerson::run() {
31+
bool bTestSuccess = true;
32+
WsjcppDtoPerson p;
33+
p.setFieldStringValue("name", "John Smith");
34+
p.setFieldIntegerValue("age", 21);
35+
std::string sJsonGot = p.toJson().dump();
36+
std::string sJsonExpected = "{\"age\":21,\"name\":\"John Smith\"}";
37+
compareS(bTestSuccess, "WsjcppDtoPerson", sJsonGot, sJsonExpected);
38+
return bTestSuccess;
39+
}
40+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef UNIT_TEST_DTO_PERSON_H
2+
#define UNIT_TEST_DTO_PERSON_H
3+
4+
#include <wsjcpp_unit_tests.h>
5+
6+
// Description: TODO
7+
class UnitTestDtoPerson : public WsjcppUnitTestBase {
8+
public:
9+
UnitTestDtoPerson();
10+
virtual void init();
11+
virtual bool run();
12+
};
13+
14+
#endif // UNIT_TEST_DTO_PERSON_H
15+

wsjcpp.yml

+17
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ version: "v0.0.1"
33
cmake_minimum_required: "3.0"
44
cmake_cxx_standard: "11"
55
description: "Helper classes for create C++ Data Transfer Object "
6+
67
authors:
78
- name: "Evgenii Sopov"
89
10+
911
origins:
1012
- address: "https://sea-kg.com/wsjcpp-package-registry/"
1113
type: "package-registry"
14+
1215
keywords:
1316
- "c++"
17+
1418
dependencies:
1519
- name: "wsjcpp-core"
1620
version: "v0.1.5"
@@ -22,3 +26,16 @@ dependencies:
2226
url: "https://github.com/nlohmann/json:develop"
2327
origin: "https://github.com/"
2428
installation-dir: "./src.wsjcpp/nlohmann_json"
29+
30+
unit-tests:
31+
cases:
32+
- name: "DtoPerson"
33+
description: "Test DtoPerson"
34+
35+
distribution:
36+
- source-file: "src/wsjcpp_dto.h"
37+
target-file: "wsjcpp_dto.h"
38+
type: "source-code"
39+
- source-file: "src/wsjcpp_dto.cpp"
40+
target-file: "wsjcpp_dto.cpp"
41+
type: "source-code"

0 commit comments

Comments
 (0)