Commit 45f6bbe8 authored by hrishikesh.r's avatar hrishikesh.r

Made Further changes to Oee_handlers.py

parent 071b0650
from scripts.logging import logger
from scripts.utils.mongo_util import MongoCollectionBaseClass
from scripts.schemas.oee_config_schema import oee_tag_mapping_list, get_oee_tag, update_oee_tags, project_id
from scripts.schemas.oee_config_schema import Oee_Tag_Mapping_List, Get_Oee_Tag, Update_Oee_Tags, Get_Project_Id
from scripts.constants import CommonKeys
from scripts.db.mongo.ilens_configuration import database
from scripts.db.mongo.ilens_configuration.collections import collection_constants
from scripts.utils.mongo_util import MongoCollectionBaseClass
from scripts.schemas import mongo_schema
from scripts.constants.db_connections import mongo_client
class Oee_Services:
def __init__(self):
def __init__(self, project_id=Get_Project_Id.project_id):
try:
self.connect = MongoCollectionBaseClass(mongo_client=mongo_client, database="ilens_configuration",
collection="oee_tag_mapping")
self.connect = collection_constants(mongo_client=mongo_client)
except Exception as e:
logger.exception("Error while connecting to mongodb")
def oee_tag_mapping(self, oee_tag_mapping_list: oee_tag_mapping_list):
def oee_tag_mapping(self, oee_tag_mapping_list: Oee_Tag_Mapping_List):
try:
return_json = {"message": "failure", "status": "failure", "message": "data not inserted in to mongodb"}
insert_json = {"hierarchy": oee_tag_mapping_list.hierarchy,
"project_id": oee_tag_mapping_list.project_id,
"meta": oee_tag_mapping_list.project_id,
......@@ -24,18 +28,12 @@ class Oee_Services:
result = self.connect.insert_one(data=insert_json)
if result:
logger.info("Data inserted in to mongodb successfully")
return_json["message"] = "success"
return_json["status"] = "success"
else:
logger.info("Unable to insert data in to Mongodb")
return return_json
except Exception as e:
logger.exception("Error occurred while inserting data")
def get_oee_tag_mapping(self, get_oee_tag: get_oee_tag):
def get_oee_tag_mapping(self, get_oee_tag: Get_Oee_Tag):
try:
return_json = {"message": "failure", "status": "failure", "data": "data not found"}
query = {'project_id': get_oee_tag.project_id}
......@@ -43,10 +41,6 @@ class Oee_Services:
no_of_documents = self.connect.count_documents(query=query)
result = self.connect.find(query=query).skip(skips).limit(get_oee_tag.page_num)
if result:
return_json["message"] = "success"
return_json["status"] = "success"
return_json["data"] = result
return_json["total_records"] = no_of_documents
if skips < no_of_documents:
return_json["endOfrecords"] = False
else:
......@@ -55,8 +49,7 @@ class Oee_Services:
except Exception as e:
logger.exception(f"Exception occured while fetching data as {e}")
def delete_oee_tags(self, project_id: project_id):
def delete_oee_tags(self, project_id: Get_Project_Id):
try:
return_json = {"message": "failure", "status": "failure", "data": "data not found"}
query = {"project_id": project_id.project_id}
......@@ -69,17 +62,11 @@ class Oee_Services:
except Exception as e:
logger.exception(f"Exception occurred while fetching data as {e}")
def update_oee_tags(self, update_oee_tags: update_oee_tags):
def update_oee_tags(self, update_oee_tags: Update_Oee_Tags):
try:
return_json = {"message": "failure", "status": "failure", "data": "data not found"}
query = {"project_id": ['update_oee_tags.projec_id']}
result = self.connect.update_one(query=query, data=return_json)
query = {"project_id": ['update_oee_tags.project_id']}
result = self.connect.update_one(query=query)
if result:
return_json["message"] = "success"
return_json["status"] = "success"
return_json["data"] = result
return return_json
return result
except Exception as e:
logger.exception(f"Exception occured while fetching data as {e}")
from pydantic import BaseModel
from typing import Any, Optional
from scripts.constants import CommonKeys
from scripts.db.mongo.ilens_configuration import database
from scripts.db.mongo.ilens_configuration.collections import collection_constants
from scripts.utils.mongo_util import MongoCollectionBaseClass
class ConstantsSchema(BaseModel):
type: Optional[str]
data: Optional[Any]
map_json: Optional[Any]
content_type: Optional[Any]
content: Optional[Any]
class Constants(MongoCollectionBaseClass):
def __init__(self, mongo_client):
super().__init__(mongo_client, database=database,
collection=collection_constants)
from pydantic import BaseModel
class oee_tag_mapping_list(BaseModel):
class Oee_Tag_Mapping_List(BaseModel):
hierarchy: str
project_id: str
meta: str
oee_tag_mapping: str
class get_oee_tag(BaseModel):
class Get_Oee_Tag(BaseModel):
project_id: str
page_size: str
page_num: str
class project_id(BaseModel):
class Get_Project_Id(BaseModel):
project_id: str
class update_oee_tags(BaseModel):
class Update_Oee_Tags(BaseModel):
project_id: str
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment