Exemple #1
0
def Delete(id):
    try:
        toDel = Rockets.query.filter_by(id=id).first()
        if toDel is not None:
            db_session.delete(toDel)
            db_session.commit()
            return 200
        else:
            return 400
    except InvalidRequestError:
        log().error("Unable to delete data")
        return 400
Exemple #2
0
def Delete(username):
    try:
        toDel = Clients.query.filter_by(username=username).first()
        if toDel is not None:
            db_session.delete(toDel)
            db_session.commit()
            return 200
        else:
            return 400
    except InvalidRequestError:
        log().error("Unable to delete data")
        return 400
Exemple #3
0
def Patch(querys, content):
    try:
        query = Timelines.query.filter_by(id=querys).first()
        if query is not None:
            for key in content:
                setattr(query, key, content[key])
            db_session.commit()
            return 200
        else:
            return 404
    except InvalidRequestError:
        log().error("Unable to patch data")
        return 400
Exemple #4
0
def Create(cond):
    createClients = Timelines(**cond, create_time=datetime.now())
    
    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
Exemple #5
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
Exemple #6
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
Exemple #7
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
Exemple #8
0
def Delete(id):
    try:
        toDel = ClientOrders.query.filter_by(id=id).first()
        if toDel is not None:
            delRelate = MissionClientOrderRelate.query.filter_by(clientOrder_id=id)
            if delRelate.one_or_none() is not None:
                for data in delRelate.all():
                    db_session.delete(data)
            db_session.commit()
            
            db_session.delete(toDel)
            db_session.commit()
            return 200
        else:
            return 400
    except InvalidRequestError:
        log().error("Unable to delete clientOrder data")
        return 400
Exemple #9
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
Exemple #10
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
Exemple #11
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
Exemple #12
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