-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathvalidators.cpp
More file actions
101 lines (85 loc) · 3.14 KB
/
validators.cpp
File metadata and controls
101 lines (85 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "validators.hpp"
#include "article_validators.hpp"
#include "user_validators.hpp"
#include "utils/errors.hpp"
namespace real_medium::validator {
void validate(const handlers::UserLoginDTO& dto) {
if (!dto.email) {
throw utils::error::ValidationException("email", "Field is missing");
} else if (!ValidateEmail(dto.email.value())) {
throw utils::error::ValidationException("email", "Invalid field");
}
if (!dto.password) {
throw utils::error::ValidationException("password", "Field is missing");
} else if (!ValidatePassword(dto.password.value())) {
throw utils::error::ValidationException("password", "Invalid field");
}
}
void validate(const handlers::UserRegistrationDTO& dto) {
if (!dto.username) {
throw utils::error::ValidationException("username", "Field is missing");
} else if (!ValidateUsername(dto.username.value())) {
throw utils::error::ValidationException("username", "Invalid field");
}
if (!dto.email) {
throw utils::error::ValidationException("email", "Field is missing");
} else if (!ValidateEmail(dto.email.value())) {
throw utils::error::ValidationException("email", "Invalid field");
}
if (!dto.password) {
throw utils::error::ValidationException("password", "Field is missing");
} else if (!ValidatePassword(dto.password.value())) {
throw utils::error::ValidationException("password", "Invalid value");
}
}
void validate(const handlers::UserUpdateDTO& dto) {
if (dto.username && !ValidateUsername(dto.username.value())) {
throw utils::error::ValidationException("username", "Invalid field");
}
if (dto.email && !ValidateEmail(dto.email.value())) {
throw utils::error::ValidationException("email", "Invalid field");
}
if (dto.password && !ValidatePassword(dto.password.value())) {
throw utils::error::ValidationException("password", "Invalid field");
}
}
void validate(const handlers::AddComment& dto) {
if (!dto.body) {
throw utils::error::ValidationException("body", "Field is missing");
}
if (dto.body.value().empty()) {
throw utils::error::ValidationException("body", "Invalid field");
}
}
void validate(const handlers::CreateArticleRequest& dto) {
if (!dto.title) {
throw utils::error::ValidationException("title", "Field is missing");
} else {
ValidateTitle(dto.title.value());
}
if (!dto.description) {
throw utils::error::ValidationException("description", "Field is missing");
} else {
ValidateDescription(dto.description.value());
}
if (!dto.body) {
throw utils::error::ValidationException("body", "Field is missing");
} else {
ValidateBody(dto.body.value());
}
if (dto.tags) {
ValidateTags(dto.tags.value());
}
}
void validate(const handlers::UpdateArticleRequest& dto) {
if (dto.title) {
ValidateTitle(dto.title.value());
}
if (dto.description) {
ValidateDescription(dto.description.value());
}
if (dto.body) {
ValidateBody(dto.body.value());
}
}
} // namespace real_medium::validator