-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EntityInterface and accessor model in order to validate the input and…
… forward the sanitized input to the main model.
- Loading branch information
1 parent
7da1238
commit 2c5f5cf
Showing
15 changed files
with
225 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#include "Console.h" | ||
#include <vld> | ||
|
||
using namespace std; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <map> | ||
|
||
#include "Helpers.h" | ||
|
||
using namespace std; | ||
|
||
class EntityInterface { | ||
private: | ||
virtual void defineValidationRules() = 0; | ||
protected: | ||
map<string, string> ValidationRules; | ||
|
||
// Might change, as we writing only string to the DB | ||
map<string, string> payLoad; | ||
public: | ||
virtual void receiveCleanInput(map<string, string> &) = 0; | ||
virtual void writeNewRecord() = 0; | ||
virtual void validateItem() = 0; | ||
|
||
virtual void retrieveItemForActive() = 0; | ||
virtual void retrieveAll() = 0; | ||
|
||
virtual void logPayload() = 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "Model.h" | ||
|
||
string Model::parseModelName(string inputAlias) | ||
{ | ||
return inputAlias.erase(inputAlias.find("-"), string::npos); | ||
} | ||
|
||
void Model::attachModel(string &model) | ||
{ | ||
toLowerCase(model); | ||
if (model == "user") | ||
{ | ||
this->currentModel = new User(); | ||
} | ||
else if (model == "question") | ||
{ | ||
|
||
} | ||
else if (model == "category") | ||
{ | ||
|
||
} | ||
} | ||
|
||
Model::Model() | ||
{ | ||
this->accessHistory = {}; | ||
this->currentModel = NULL; | ||
} | ||
|
||
void Model::sendSerializedInput(map<string, string> &input) | ||
{ | ||
string modelName = this->parseModelName(input.begin()->first); | ||
|
||
if (this->currentModel == NULL) | ||
{ | ||
this->attachModel(modelName); | ||
} | ||
|
||
string inputAlias = input.begin()->first; | ||
inputAlias.erase(0, modelName.size() + 1); | ||
|
||
// if (this->currentModel->validateItem(inputAlias, input.begin()->second)) { | ||
|
||
// If the validation was successful push back into the ready map | ||
this->ready[inputAlias] = input.begin()->second; | ||
|
||
// } | ||
} | ||
|
||
void Model::confirmInput() | ||
{ | ||
// Send the input to the attached model and determine if there are any errors and if the payload is complete | ||
this->currentModel->receiveCleanInput(this->ready); | ||
} | ||
|
||
Model::~Model() | ||
{ | ||
delete this->currentModel; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
#include <map> | ||
|
||
#include "Helpers.h" | ||
#include "Entity.h" | ||
#include "User.h" | ||
|
||
using namespace std; | ||
|
||
class Model { | ||
private: | ||
static string userModelAlias; | ||
static string questionModelAlias; | ||
|
||
vector<string> accessHistory; | ||
map<string, string> ready; | ||
|
||
EntityInterface *currentModel; | ||
|
||
string parseModelName(string); | ||
void attachModel(string &); | ||
public: | ||
Model(); | ||
|
||
void sendSerializedInput(map<string, string> &); | ||
void confirmInput(); | ||
|
||
~Model(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,47 @@ | ||
#include "User.h" | ||
|
||
//--- User --- | ||
//------------ | ||
unsigned User::count = 0; | ||
string User::modelPath = "..\\db\\user.store"; | ||
string User::modelAlias = "user"; | ||
|
||
void User::setFromLastUuid() | ||
void User::defineValidationRules() | ||
{ | ||
// Get the last uuid from the db file | ||
this->ValidationRules = {}; | ||
} | ||
|
||
User::User() | ||
{ | ||
this->defineValidationRules(); | ||
} | ||
|
||
void User::receiveCleanInput(map<string, string>& cleanInput) | ||
{ | ||
cout << "Got the input, doing something with it..." | ||
<< endl; | ||
} | ||
|
||
User::count = 30; | ||
void User::writeNewRecord() | ||
{ | ||
// | ||
} | ||
|
||
void User::validateItem() | ||
{ | ||
// Appli validation rules for the next item | ||
} | ||
|
||
User::User() : uuid(User::count++) | ||
void User::retrieveItemForActive() | ||
{ | ||
this->nick = new char[4]; | ||
// Search for the record having active set to true | ||
} | ||
|
||
User::~User() | ||
void User::retrieveAll() | ||
{ | ||
delete[] this->nick; | ||
// Print everything | ||
} | ||
|
||
unsigned User::getUuid() | ||
void User::logPayload() | ||
{ | ||
return this->uuid; | ||
} | ||
// | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,25 @@ | ||
class User { | ||
#include <iostream> | ||
#include <string> | ||
#include <map> | ||
|
||
#include "Entity.h" | ||
|
||
class User : public EntityInterface { | ||
private: | ||
static unsigned count; | ||
static string modelPath; | ||
static string modelAlias; | ||
|
||
const unsigned uuid; | ||
char *nick; | ||
void defineValidationRules(); | ||
public: | ||
static void setFromLastUuid(); | ||
User(); | ||
~User(); | ||
unsigned getUuid(); | ||
|
||
void receiveCleanInput(map<string, string> &); | ||
void writeNewRecord(); | ||
void validateItem(); | ||
|
||
void retrieveItemForActive(); | ||
void retrieveAll(); | ||
|
||
void logPayload(); | ||
// Set the active to false when destroying the object. | ||
}; |
Oops, something went wrong.