예제 #1
0
    def handleMethod(clazz, method, model, id=None):
        result = None
        status = False
        message = None
        code = None
        entityById = None
        if id is not None:
            entityById = DBUtil.findById(clazz, id)
        if method == 'POST':
            s, model = DBUtil.insert(model)
            status = s
            result = model
            code = 201
            if not status:
                code = 500
                message = "Entity not created [{}]".format(model)
        elif method == 'PUT':
            if entityById is not None:
                GenericHelperService.compareWithCurrent(entityById, model)
                status = True
                result = entityById
            else:
                status = False
                result = None
                if id is None:
                    message = "PUT method [PATH param ID is missing]"
                    code = 500
                else:
                    message = "Entity not found"
                    code = 404
        elif method == 'GET':
            if id is not None:
                result = DBUtil.findById(clazz, id)
            else:
                result = DBUtil.findAll(clazz)
            if result is None:
                status = False
                code = 404
                message = "Entity not found"
            else:
                status = True
        elif method == 'DELETE':
            if entityById is not None:
                entityById.active = False
                DBUtil.commit()
                status = False
                code = 200
                message = "Successfully deleted"
            else:
                status = False
                code = 404
                message = "Entity not found"

            result = None


        return status, result, message, code
예제 #2
0
    def getAll(header):
        try:
            token = header.get(AUTH_TOKEN)
            status = TaskExecutionService.checkToken(token)
            if status is not None:
                return status
        except:
            return Utils.JsonMessage("Internal server error", 500)

        entityList = DBUtil.findAll(TaskExecution)
        dtoList = []
        for e in entityList:
            dto = TaskExecutedResponseDto()
            dto.fromEntity(e)
            dtoList.append(dto.getJson())

        jsonList = {
            'executed': dtoList
        }

        return Utils.JsonResponse(jsonList, 200)
예제 #3
0
 def getAllUsers():
     return DBUtil.findAll(User)