From 5998e52f343fd46479421da0fc87660a19bd67c1 Mon Sep 17 00:00:00 2001 From: Kamil <39993982+TBS093A@users.noreply.github.com> Date: Tue, 15 Sep 2020 17:24:04 +0200 Subject: [PATCH 01/14] Create README.md --- README.md | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..4cc7eda --- /dev/null +++ b/README.md @@ -0,0 +1,140 @@ +# Trade App +Python / Django / Websocket / Docker / Own REST / Own App Security + +## Basic Information + +Application for analyze a BTC stock exchange & community. Thanks this app you can subscribe BTC exchange and you can contact quickly with other app users (websocket chat & rest forum). Functionality have: +- chart (candles) +- triggers (it's create a notification when stock exchange get a your value) +- basic prognosis +- notifications + +### Project Structure + +### UML + +## Comments + +Application need a refactor endpoints, general functionality and security. General structure -> "generalApp" will be smashed a smaller apps/directores. Now, CRUD has been refactorized full, you can see: + +```python + +class AbstractUtilsCRUD(): + """ + This class have a primary utilities for CRUD functionality + """ + + @classmethod + def _objectFactory(self): + """ + return a new specific object + """ + pass + + @classmethod + def _setParentID(self, parentID): + """ + set object parent id + """ + pass + + @classmethod + def _allObjectsDict(self): + """ + map all class objects to dict + """ + objectAll = self._objectFactory().objects.all() + list = [] + for x in objectAll: + list.append(x.toDict()) + return list + + class Meta: + abstract = True +``` + +It's a utils for CRUD classes using global like this: + +```python +class AbstractCreate(AbstractUtilsCRUD): + """ + This class have a abstract `create` + """ + + @classmethod + def addObject(self, request, privilige): + """ + create object without parent + """ + object = jsonLoad(request) + if checkSession(request, privilige): + if self._validateUnique(object): + return self._saveObject(object) + else: + return HttpResponse("Object Is Already Exist") + else: + return HttpResponse("No Permission") + + @classmethod + def _validateUnique(self, userDict): + """ + use validate in override this method + """ + return True + + @classmethod + def _saveObject(self, objectDict): + """ + save object without parent + """ + del objectDict['token'] + newObject = self._objectFactory().objects.create(**objectDict) + self._setActualTimeTrigger(newObject) + newObject.save() + return HttpResponse(f"Add new Object: {newObject.toDict()}") + + @classmethod + def _setActualTimeTrigger(self, trigger): + pass + + @classmethod + def addObjectWithParent(self, request, parentID, privilige): + """ + create object with parent + """ + object = jsonLoad(request) + if checkSession(request, privilige): + if self._validateUnique(object): + return self._saveObjectWithParent(parentID, object) + else: + return HttpResponse("Object Is Already Exist") + else: + return HttpResponse("No Permission") + + @classmethod + def _saveObjectWithParent(self, parentID, objectDict): + """ + save object with parent & subject + comment & set trigger time + """ + del objectDict['token'] + newObject = self._objectFactory().objects.create(**objectDict) + + self._setParentID(parentID) + self._createFirstComment(newObject, objectDict) + + newObject.save() + return HttpResponse(f"Add new Object: {newObject.toDict()}") + + @classmethod + def _createFirstComment(self, newSubject, objectDict): + pass + + class Meta: + abstract = True +``` +Other classes looks similar to AbstractCreate (let's see AbstractCRUD for more details). + +Generaly - I'm gonna refactor this app with design patterns like: +- chain of responsibility (thanks tree structure classes, possible go this way: endpoint request -> verify user (security functionality) -> app functionality) +- wrapper (this pattern will be helpfull in the future when I will expanded app for more stock exchanges) +- strategy (for swapping functionality in functionality classes with many `if` statements) From e00de45067892994ff3e9f7b3babf3ffadc08669 Mon Sep 17 00:00:00 2001 From: Kamil <39993982+TBS093A@users.noreply.github.com> Date: Tue, 15 Sep 2020 17:25:09 +0200 Subject: [PATCH 02/14] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4cc7eda..1b61a74 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Python / Django / Websocket / Docker / Own REST / Own App Security ## Basic Information -Application for analyze a BTC stock exchange & community. Thanks this app you can subscribe BTC exchange and you can contact quickly with other app users (websocket chat & rest forum). Functionality have: +Application for analyze a BTC stock exchange & community. Thanks this app you can subscribe BTC exchange and you can contact quickly with other app users (websocket chat & rest forum). Functionality has: - chart (candles) - triggers (it's create a notification when stock exchange get a your value) - basic prognosis From 3f17ccb60ee0c23210dd9ce7a20d1a37cfe25007 Mon Sep 17 00:00:00 2001 From: Kamil <39993982+TBS093A@users.noreply.github.com> Date: Tue, 15 Sep 2020 17:26:25 +0200 Subject: [PATCH 03/14] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1b61a74..1dca1ec 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ class AbstractUtilsCRUD(): abstract = True ``` -It's a utils for CRUD classes using global like this: +It're a utils for CRUD classes using global like this: ```python class AbstractCreate(AbstractUtilsCRUD): From 4bf444ca6d533e0a8d1eaa76a3af6dcf8c84aa28 Mon Sep 17 00:00:00 2001 From: Kamil <39993982+TBS093A@users.noreply.github.com> Date: Tue, 15 Sep 2020 17:29:44 +0200 Subject: [PATCH 04/14] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 1dca1ec..c8e5686 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ Application for analyze a BTC stock exchange & community. Thanks this app you ca - basic prognosis - notifications +Trade App has also security func (like create/verify tokens (hashed information about user)) + ### Project Structure ### UML From 4750778511a68a1bf74ece89ba5546b5ff443682 Mon Sep 17 00:00:00 2001 From: Kamil <39993982+TBS093A@users.noreply.github.com> Date: Tue, 15 Sep 2020 17:33:06 +0200 Subject: [PATCH 05/14] Update README.md --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/README.md b/README.md index c8e5686..6b332d6 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,38 @@ Trade App has also security func (like create/verify tokens (hashed information ### Project Structure +```bash +. +├── chat +│   ├── admin.py +│   ├── consumers.py +│   ├── models.py +│   ├── routing.py +│   ├── urls.py +│   └── views.py +├── generalApp +│   ├── AbstractCRUD.py +│   ├── admin.py +│   ├── apps.py +│   ├── exchangeVO.py +│   ├── methods.py +│   ├── models.py +│   ├── tests.py +│   ├── urls.py +│   ├── utilities.py +│   └── views.py +├── manage.py +├── migrate.sh +├── packages.sh +├── run.sh +└── TradeApp + ├── routing.py + ├── settings.py + ├── urls.py + └── wsgi.py + +``` + ### UML ## Comments From c29b4905b6fb6aaaa83c749706026ef0450387b8 Mon Sep 17 00:00:00 2001 From: Kamil <39993982+TBS093A@users.noreply.github.com> Date: Tue, 15 Sep 2020 17:34:21 +0200 Subject: [PATCH 06/14] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6b332d6..bfe3819 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Application for analyze a BTC stock exchange & community. Thanks this app you ca - basic prognosis - notifications -Trade App has also security func (like create/verify tokens (hashed information about user)) +Trade App has also security func (like create/verify tokens (hashed information about user and session)) ### Project Structure From 59d9371eb3febb2e857bd79b97b549b4034d91f7 Mon Sep 17 00:00:00 2001 From: Kamil <39993982+TBS093A@users.noreply.github.com> Date: Tue, 15 Sep 2020 17:36:58 +0200 Subject: [PATCH 07/14] Update README.md --- README.md | 59 +------------------------------------------------------ 1 file changed, 1 insertion(+), 58 deletions(-) diff --git a/README.md b/README.md index bfe3819..a06ad56 100644 --- a/README.md +++ b/README.md @@ -95,26 +95,7 @@ class AbstractCreate(AbstractUtilsCRUD): This class have a abstract `create` """ - @classmethod - def addObject(self, request, privilige): - """ - create object without parent - """ - object = jsonLoad(request) - if checkSession(request, privilige): - if self._validateUnique(object): - return self._saveObject(object) - else: - return HttpResponse("Object Is Already Exist") - else: - return HttpResponse("No Permission") - - @classmethod - def _validateUnique(self, userDict): - """ - use validate in override this method - """ - return True + [...] @classmethod def _saveObject(self, objectDict): @@ -127,44 +108,6 @@ class AbstractCreate(AbstractUtilsCRUD): newObject.save() return HttpResponse(f"Add new Object: {newObject.toDict()}") - @classmethod - def _setActualTimeTrigger(self, trigger): - pass - - @classmethod - def addObjectWithParent(self, request, parentID, privilige): - """ - create object with parent - """ - object = jsonLoad(request) - if checkSession(request, privilige): - if self._validateUnique(object): - return self._saveObjectWithParent(parentID, object) - else: - return HttpResponse("Object Is Already Exist") - else: - return HttpResponse("No Permission") - - @classmethod - def _saveObjectWithParent(self, parentID, objectDict): - """ - save object with parent & subject + comment & set trigger time - """ - del objectDict['token'] - newObject = self._objectFactory().objects.create(**objectDict) - - self._setParentID(parentID) - self._createFirstComment(newObject, objectDict) - - newObject.save() - return HttpResponse(f"Add new Object: {newObject.toDict()}") - - @classmethod - def _createFirstComment(self, newSubject, objectDict): - pass - - class Meta: - abstract = True ``` Other classes looks similar to AbstractCreate (let's see AbstractCRUD for more details). From 1a35b6adabfd04cfce46aa14c4fc16b50fb32b93 Mon Sep 17 00:00:00 2001 From: Kamil <39993982+TBS093A@users.noreply.github.com> Date: Tue, 15 Sep 2020 17:39:09 +0200 Subject: [PATCH 08/14] Update README.md --- README.md | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a06ad56..de71451 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,56 @@ class AbstractUtilsCRUD(): It're a utils for CRUD classes using global like this: ```python + +class AbstractGet(AbstractUtilsCRUD): + """ + This class have a abstract `getOne` / `getAll` / `getByParent` + """ + + parent_id_field = '' + + @classmethod + def getObject(self, objectID): + """ + get one object + """ + return self.__getObjectNormal(self, objectID) + + def __getObjectNormal(self, objectID): + object = self._objectFactory().objects.get(pk = objectID).toDict() + return HttpResponse(json.dumps(object)) + + @classmethod + def getAllObjects(self): + """ + get all objects + """ + objectsAll = self._allObjectsDict() + return HttpResponse(json.dumps(objectsAll)) + + @classmethod + def getObjectsByParentID(self, parentID): + """ + get objects by parent id + """ + return HttpResponse(self.__getAllByParentID(parentID)) + + @classmethod + def __getAllByParentID(self, parentID): + list = [ + x.toDict() + for x in self._objectFactory() + .objects.filter(**{ self._objectFactory().parent_id_field: parentID }) + ] + return json.dumps(list) + + class Meta: + abstract = True + +``` + +```python + class AbstractCreate(AbstractUtilsCRUD): """ This class have a abstract `create` @@ -104,12 +154,14 @@ class AbstractCreate(AbstractUtilsCRUD): """ del objectDict['token'] newObject = self._objectFactory().objects.create(**objectDict) - self._setActualTimeTrigger(newObject) + + [...] + newObject.save() return HttpResponse(f"Add new Object: {newObject.toDict()}") ``` -Other classes looks similar to AbstractCreate (let's see AbstractCRUD for more details). +Other classes looks similar to AbstractCreate / AbstractGet (let's see AbstractCRUD for more details). Generaly - I'm gonna refactor this app with design patterns like: - chain of responsibility (thanks tree structure classes, possible go this way: endpoint request -> verify user (security functionality) -> app functionality) From b771aad1c370a426b2b3045d40fdeb7ed3c9ba92 Mon Sep 17 00:00:00 2001 From: Kamil <39993982+TBS093A@users.noreply.github.com> Date: Tue, 15 Sep 2020 17:45:17 +0200 Subject: [PATCH 09/14] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index de71451..64a9b4c 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,8 @@ Trade App has also security func (like create/verify tokens (hashed information ### UML +![uml_by_apps](https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/12abb353-ab91-4433-96d3-b5d9c5847254/de56rda-8c6c1a01-e952-4957-9890-c19519eeeae5.png/v1/fill/w_1280,h_864,strp/class_diagram_by_apps_by_00x097_de56rda-fullview.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOiIsImlzcyI6InVybjphcHA6Iiwib2JqIjpbW3siaGVpZ2h0IjoiPD04NjQiLCJwYXRoIjoiXC9mXC8xMmFiYjM1My1hYjkxLTQ0MzMtOTZkMy1iNWQ5YzU4NDcyNTRcL2RlNTZyZGEtOGM2YzFhMDEtZTk1Mi00OTU3LTk4OTAtYzE5NTE5ZWVlYWU1LnBuZyIsIndpZHRoIjoiPD0xMjgwIn1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmltYWdlLm9wZXJhdGlvbnMiXX0.2Jm_XxFhksN8mAtdUS9n_F0shiK8VttfN21rhm1-tbk) + ## Comments Application need a refactor endpoints, general functionality and security. General structure -> "generalApp" will be smashed a smaller apps/directores. Now, CRUD has been refactorized full, you can see: From a311eb4697fe06b8a236847eb2e73eb23f85ec43 Mon Sep 17 00:00:00 2001 From: Kamil <39993982+TBS093A@users.noreply.github.com> Date: Tue, 15 Sep 2020 17:49:11 +0200 Subject: [PATCH 10/14] Update README.md --- README.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 64a9b4c..f3debf1 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Trade App Python / Django / Websocket / Docker / Own REST / Own App Security -## Basic Information +## Basic Informations Application for analyze a BTC stock exchange & community. Thanks this app you can subscribe BTC exchange and you can contact quickly with other app users (websocket chat & rest forum). Functionality has: - chart (candles) @@ -44,8 +44,21 @@ Trade App has also security func (like create/verify tokens (hashed information └── wsgi.py ``` +### Usefull files -### UML +Shell / Bash Files +../packages.sh +This file have every python virtual environment requirements for application run + +../migrate.sh +This file migrate every models with database in app and generate UML + +../run.sh +This file running application + +## UML + +### Class diagram by apps ![uml_by_apps](https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/12abb353-ab91-4433-96d3-b5d9c5847254/de56rda-8c6c1a01-e952-4957-9890-c19519eeeae5.png/v1/fill/w_1280,h_864,strp/class_diagram_by_apps_by_00x097_de56rda-fullview.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOiIsImlzcyI6InVybjphcHA6Iiwib2JqIjpbW3siaGVpZ2h0IjoiPD04NjQiLCJwYXRoIjoiXC9mXC8xMmFiYjM1My1hYjkxLTQ0MzMtOTZkMy1iNWQ5YzU4NDcyNTRcL2RlNTZyZGEtOGM2YzFhMDEtZTk1Mi00OTU3LTk4OTAtYzE5NTE5ZWVlYWU1LnBuZyIsIndpZHRoIjoiPD0xMjgwIn1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmltYWdlLm9wZXJhdGlvbnMiXX0.2Jm_XxFhksN8mAtdUS9n_F0shiK8VttfN21rhm1-tbk) @@ -140,6 +153,8 @@ class AbstractGet(AbstractUtilsCRUD): ``` +And other example + ```python class AbstractCreate(AbstractUtilsCRUD): From 3622eaaeb69e8bd5af463abcfdfb9a28c30fed89 Mon Sep 17 00:00:00 2001 From: Kamil <39993982+TBS093A@users.noreply.github.com> Date: Tue, 15 Sep 2020 17:50:19 +0200 Subject: [PATCH 11/14] Update README.md --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f3debf1..01f055a 100644 --- a/README.md +++ b/README.md @@ -47,13 +47,14 @@ Trade App has also security func (like create/verify tokens (hashed information ### Usefull files Shell / Bash Files -../packages.sh + +- ./packages.sh This file have every python virtual environment requirements for application run -../migrate.sh +- ./migrate.sh This file migrate every models with database in app and generate UML -../run.sh +- ./run.sh This file running application ## UML From 54846d57ff82db7f1cbadfe60179cb23edbd829e Mon Sep 17 00:00:00 2001 From: Kamil <39993982+TBS093A@users.noreply.github.com> Date: Tue, 15 Sep 2020 17:52:14 +0200 Subject: [PATCH 12/14] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 01f055a..910c4cd 100644 --- a/README.md +++ b/README.md @@ -44,18 +44,18 @@ Trade App has also security func (like create/verify tokens (hashed information └── wsgi.py ``` -### Usefull files +### Useful files Shell / Bash Files - ./packages.sh -This file have every python virtual environment requirements for application run +(every python virtual environment requirements for application run) - ./migrate.sh -This file migrate every models with database in app and generate UML +(migrate every models with database in app and generate UML) - ./run.sh -This file running application +(run application) ## UML From b29bc6be8e9a32ba143f26c937dba2eb48beb5f8 Mon Sep 17 00:00:00 2001 From: Kamil <39993982+TBS093A@users.noreply.github.com> Date: Tue, 15 Sep 2020 18:00:32 +0200 Subject: [PATCH 13/14] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 910c4cd..5611bdf 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ class AbstractUtilsCRUD(): abstract = True ``` -It're a utils for CRUD classes using global like this: +It're a utils for CRUD classes used to global like this: ```python From a5e08c615dde76ad35d3cb9a23f4792c1b170cd1 Mon Sep 17 00:00:00 2001 From: Kamil <39993982+TBS093A@users.noreply.github.com> Date: Tue, 15 Sep 2020 18:34:05 +0200 Subject: [PATCH 14/14] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5611bdf..8d0c681 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Trade App has also security func (like create/verify tokens (hashed information └── wsgi.py ``` -### Useful files +### Useful Files Shell / Bash Files @@ -59,7 +59,7 @@ Shell / Bash Files ## UML -### Class diagram by apps +### Class Diagram By Apps ![uml_by_apps](https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/12abb353-ab91-4433-96d3-b5d9c5847254/de56rda-8c6c1a01-e952-4957-9890-c19519eeeae5.png/v1/fill/w_1280,h_864,strp/class_diagram_by_apps_by_00x097_de56rda-fullview.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOiIsImlzcyI6InVybjphcHA6Iiwib2JqIjpbW3siaGVpZ2h0IjoiPD04NjQiLCJwYXRoIjoiXC9mXC8xMmFiYjM1My1hYjkxLTQ0MzMtOTZkMy1iNWQ5YzU4NDcyNTRcL2RlNTZyZGEtOGM2YzFhMDEtZTk1Mi00OTU3LTk4OTAtYzE5NTE5ZWVlYWU1LnBuZyIsIndpZHRoIjoiPD0xMjgwIn1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmltYWdlLm9wZXJhdGlvbnMiXX0.2Jm_XxFhksN8mAtdUS9n_F0shiK8VttfN21rhm1-tbk)