Beispiel #1
0
def delete_one_project(projectID:int):
    try:
        result=Project21Database.find_one(settings.DB_COLLECTION_PROJECT,{"projectID":projectID})
        if result:
            Project21Database.delete_one(settings.DB_COLLECTION_PROJECT,{"projectID":projectID})
        else:
            return ErrorResponseModel("An Error Occured",404,"project could not be found")
    except:
        return ErrorResponseModel("An Error Occured",404,"project could not be deleted")
    return ResponseModel(projectID,"Successfully Deleted")
Beispiel #2
0
def delete_one_project(belongsToModelID:int):
    try:
        result=Project21Database.find_one(settings.DB_COLLECTION_METRICS,{"belongsToModelID":belongsToModelID})
        if result:
            Project21Database.delete_one(settings.DB_COLLECTION_METRICS,{"belongsToModelID":belongsToModelID})
        else:
            return ErrorResponseModel("An Error Occured",404,"Metrics could not be found")
    except:
        return ErrorResponseModel("An Error Occured",404,"Metrics could not be deleted")
    return ResponseModel(belongsToModelID,"Successfully Deleted")
Beispiel #3
0
def update_one_project(projectID:int,updateProject: UpdateProject=Body(...)):
    updateProject={k:v for k,v in updateProject.dict().items() if v is not None}
    result=Project21Database.find_one(settings.DB_COLLECTION_PROJECT,{"projectID":projectID})
    if result:
        try:
            result=Project21Database.update_one(settings.DB_COLLECTION_PROJECT,{"projectID":projectID},{"$set":updateProject})
            return ResponseModel(projectID,"Successfully Updated")
        except:
            return ErrorResponseModel("An Error Occured",404,"Project could not be updated")
    return ErrorResponseModel("An Error Occured",404,"Project could not be updated")
Beispiel #4
0
def delete_one_user(id: int):
    try:
        result = Project21Database.find_one(settings.DB_COLLECTION_USER,
                                            {"userID": id})
        if result:
            Project21Database.delete_one(settings.DB_COLLECTION_USER,
                                         {"userID": id})
        else:
            return ErrorResponseModel("An Error Occured", 404,
                                      "User could not be found")
    except:
        return ErrorResponseModel("An Error Occured", 404,
                                  "User could not be deleted")
    return ResponseModel(id, "Successfully Deleted")
Beispiel #5
0
def update_one_user(id: int, updateUser: UpdateUser = Body(...)):
    updateUser = {k: v for k, v in updateUser.dict().items() if v is not None}
    result = Project21Database.find_one(settings.DB_COLLECTION_USER,
                                        {"userID": id})
    if result:
        try:
            result = Project21Database.update_one(settings.DB_COLLECTION_USER,
                                                  {"userID": id},
                                                  {"$set": updateUser})
            return ResponseModel(id, "Successfully Updated")
        except:
            return ErrorResponseModel("An Error Occured", 404,
                                      "User could not be updated")
    return ErrorResponseModel("An Error Occured", 404,
                              "User could not be updated")
Beispiel #6
0
def update_one_data(dataID: int, updateData: UpdateData = Body(...)):
    updateData = {k: v for k, v in updateData.dict().items() if v is not None}
    result = Project21Database.find_one(settings.DB_COLLECTION_DATA,
                                        {"dataID": dataID})
    if result:
        try:
            Project21Database.update_one(settings.DB_COLLECTION_DATA,
                                         {"dataID": dataID},
                                         {"$set": updateData})
            return ResponseModel(dataID, "Succesfully Updated")
        except:
            return ErrorResponseModel("An Exception error Occured", 404,
                                      "Data could not be updated")
    return ErrorResponseModel("An Exception error Occured", 404,
                              "Data could not be updated")
Beispiel #7
0
def insert_one_project(project: Project=Body(...)):
    project=jsonable_encoder(project)
    try:
        Project21Database.insert_one(settings.DB_COLLECTION_PROJECT,project)
    except:
        return ErrorResponseModel("An Error Occured",404,"Could not insert Project into the Collection")
    return ResponseModel(project["projectID"],"Succesfully Inserted")
Beispiel #8
0
def insert_one_metrics(metrics: Metrics=Body(...)):
    metrics=jsonable_encoder(metrics)
    try:
        Project21Database.insert_one(settings.DB_COLLECTION_METRICS,metrics)
    except:
        return ErrorResponseModel("An Error Occured",404,"Could not insert Metrics into the Collection")
    return ResponseModel(metrics["belongsToModelID"],"Succesfully Inserted")
Beispiel #9
0
def insert_one_data(data: Data = Body(...)):
    data = jsonable_encoder(data)
    try:
        Project21Database.insert_one(settings.DB_COLLECTION_DATA, data)
    except:
        return ErrorResponseModel("An Error Occured", 404,
                                  "Could not insert Data into the Collection")
    return ResponseModel(data["dataID"], "Succesfully Inserted")
Beispiel #10
0
def insert_one_user(user: User = Body(...)):
    user = jsonable_encoder(user)
    try:
        Project21Database.insert_one(settings.DB_COLLECTION_USER, user)
    except:
        return ErrorResponseModel("An Error Occured", 404,
                                  "Could not insert User into the Collection")
    return ResponseModel(user["userID"], "Succesfully Inserted")
Beispiel #11
0
def update_one_model(modelID: int, updateModel: UpdateModel = Body(...)):
    updateModel = {
        k: v
        for k, v in updateModel.dict().items() if v is not None
    }
    result = Project21Database.find_one(settings.DB_COLLECTION_MODEL,
                                        {"modelID": modelID})
    if result:
        try:
            Project21Database.update_one(settings.DB_COLLECTION_MODEL,
                                         {"modelID": modelID},
                                         {"$set": updateModel})
            return ResponseModel(modelID, "Succesfully Updated")
        except:
            return ErrorResponseModel("An Exception error Occured", 404,
                                      "Model could not be updated")
    return ErrorResponseModel("An Exception error Occured", 404,
                              "Model could not be updated")
Beispiel #12
0
def get_one_model(modelID: int):
    try:
        model = serialiseDict(
            Project21Database.find_one(settings.DB_COLLECTION_MODEL,
                                       {"modelID": modelID}))
    except:
        return ErrorResponseModel("An Error Occured", 404,
                                  "Model could not be found")
    return model
Beispiel #13
0
def get_one_user(id: int):
    try:
        user = userEntity(
            Project21Database.find_one(settings.DB_COLLECTION_USER,
                                       {"userID": id}))
    except:
        return ErrorResponseModel("An Error Occured", 404,
                                  "User could not be found")
    return user
Beispiel #14
0
def get_one_data(dataID: int):
    try:
        data = serialiseDict(
            Project21Database.find_one(settings.DB_COLLECTION_DATA,
                                       {"dataID": dataID}))
    except:
        return ErrorResponseModel("An Error Occured", 404,
                                  "Data could not be found")
    return data
Beispiel #15
0
def insert_one_model(model: Model = Body(...)):
    model = jsonable_encoder(model)
    try:
        Project21Database.insert_one(settings.DB_COLLECTION_MODEL, model)
    except:
        return ErrorResponseModel(
            "An Error Occured", 404,
            "Could not insert Model into the Collection")
    return ResponseModel(model["modelID"], "Succesfully Inserted")
Beispiel #16
0
def get_one_metrics(belongsToModelID:int):
    try:
        metrics=serialiseDict(Project21Database.find_one(settings.DB_COLLECTION_METRICS,{"belongsToModelID":belongsToModelID}))
    except:
        return ErrorResponseModel("An Error Occured",404,"Metrics could not be found")
    return metrics
Beispiel #17
0
def get_one_project(projectID:int):
    try:
        project=serialiseDict(Project21Database.find_one(settings.DB_COLLECTION_PROJECT,{"projectID":projectID}))
    except:
        return ErrorResponseModel("An Error Occured",404,"Project could not be found")
    return project