Esempio n. 1
0
def Patch(content):
    log().debug(content)
    if not content['id']:
        return None, 400
    query = MissionOrders.query.filter_by(id=content.pop("id")).one_or_none()
    if query is not None:
        querydict = {}
        querydict, isMatch = checkDictKeyMatchArray(modelKey, content)
        if not isMatch:
            return None, 400
        for key in querydict:
            setattr(query, key, querydict[key])
        db_session.commit()
        return querydict, 200
    else:
        return None, 404
Esempio n. 2
0
def Patch(content):
    try:
        queryDict, isMatch = checkDictKeyMatchArray(modelKey, content)
        if not isMatch:
            return 400
        query = Clients.query.filter_by(
            username=queryDict['username']).one_or_none()
        if query is not None:
            for key in queryDict:
                setattr(query, key, queryDict[key])
            db_session.commit()
            return 200
        else:
            return 404
    except InvalidRequestError:
        log().error("Unable to patch data")
        return 400
Esempio n. 3
0
def Create(cond):
    querydict = {}
    querydict, isMatch = checkDictKeyMatchArray(modelKey, cond)
    if not isMatch:
        return None, 400

    createRocket = Rockets(**querydict)

    try:
        db_session.add(createRocket)
        db_session.commit()
        return 200
    except InvalidRequestError:
        log().error("Unable to create data")
        return 400
    except IntegrityError:
        log().error("Foreign key not found")
        return 400
Esempio n. 4
0
def Create(cond):
    passwd = encrypt_password(cond['passwd'])
    cond.pop('passwd')
    queryDict, isMatch = checkDictKeyMatchArray(modelKey, cond)
    if not isMatch:
        return None, 400
    createClients = Clients(**queryDict, passwd=passwd)

    try:
        db_session.add(createClients)
        db_session.commit()
        return 200
    except InvalidRequestError:
        log().error("Unable to create data")
        return 400
    except IntegrityError:
        log().error("Foreign key not found")
        return 400
Esempio n. 5
0
def Patch(content):
    try:
        if 'id' not in content:
            return None, 400
        cid = content.pop('id')
        querydict, isMatch = checkDictKeyMatchArray(modelKey, content)
        if not isMatch:
            return None, 400
        query = Missions.query.filter_by(id=cid).one_or_none()
        if query is not None:
            if "pair_order" in querydict:
                pair = list(map(int, querydict["pair_order"].split(',')))
                relate = MissionClientOrderRelate.query.filter_by(
                    mission_id=query.id).all()
                qPair = []
                for data in relate:
                    qPair.append(data.clientOrder_id)

                for toDel in list(set(qPair) - set(pair)):
                    m = MissionClientOrderRelate.query.filter_by(
                        mission_id=query.id, clientOrder_id=toDel).one()
                    db_session.delete(m)

                for toAdd in list(set(pair) - set(qPair)):
                    createRelate = MissionClientOrderRelate(
                        mission_id=query.id, clientOrder_id=toAdd)
                    db_session.add(createRelate)

                try:
                    db_session.commit()
                except:
                    log().error("Unable to patch mission client order relate ")
                    return 400

            for key in querydict:
                setattr(query, key, querydict[key])

            db_session.commit()
            return querydict, 200
        else:
            return None, 404
    except InvalidRequestError:
        log().error("Unable to patch data")
        return None, 400
Esempio n. 6
0
def Patch(content):
    try:
        if not content['id']:
            return None, 400
        query = Rockets.query.filter_by(id=content.pop("id")).one_or_none()
        if query is not None:
            querydict = {}
            querydict, isMatch = checkDictKeyMatchArray(modelKey, content)
            if not isMatch:
                return None, 400
            for key in querydict:
                setattr(query, key, querydict[key])
            db_session.commit()
            return querydict, 200
        else:
            return None, 404
    except InvalidRequestError:
        log().error("Unable to patch data")
        return None, 400
Esempio n. 7
0
def Create(cond):
    log().debug(cond)
    querydict = {}
    querydict, isMatch = checkDictKeyMatchArray(modelKey, cond)
    if not isMatch:
        return None, 400

    if "pair_order" in querydict:
        pair = querydict.pop('pair_order')
        pair = list(map(int, pair.split(',')))
        createMission = Missions(**querydict)
        try:
            db_session.add(createMission)
            db_session.commit()
        except:
            log().error("Unable to add mission")
            return 400
        for values in pair:
            createRelation = MissionClientOrderRelate(
                mission_id=createMission.id, clientOrder_id=values)
            try:
                db_session.add(createRelation)
                db_session.commit()
            except:
                log().error(
                    "Unable to add mission clientOrder relation with id: " +
                    str(values))
                return 400

        return 200

    else:
        createMission = Missions(**querydict)
        try:
            db_session.add(createMission)
            db_session.commit()
            return 200
        except InvalidRequestError:
            log().error("Unable to create mission data")
            return 400
        except IntegrityError:
            log().error("Foreign key not found")
            return 400
Esempio n. 8
0
def FindOne(cond):
    try:
        if "id" not in cond:
            return None, 400
        orderID = cond.pop("id")

        querydict, isMatch = checkDictKeyMatchArray(modelKey, cond)
        if not isMatch:
            return None, 400
        query = Rockets.query.filter_by(**querydict, id=orderID)

        if query.one_or_none() is not None:
            q = query.one_or_none()
            q.__dict__.pop("_sa_instance_state")
            return q.__dict__, 200
        else:
            return None, 404
    except InvalidRequestError:
        log().error("mission InvalidRequestError")
        return None, 400