Esempio n. 1
0
def delete_channel_of_manager(
    manager_id: str,
    channel_id:List[str],
    current_user= Security(deps.get_current_active_user,scopes=["channel_manager"]),
    db: Session = Depends(deps.get_db)
):
    manager=crud_user.get_user(db=db,user_id=manager_id)
    if manager is None or manager.role!="manager"   :
        raise HTTPException(
            status_code=status.HTTP_502_BAD_GATEWAY,
            detail="Invalid manager id"
        )
    for id in channel_id:
        if crud_channel.get_channel(db=db,channel_id=id) is None:
            raise HTTPException(
            status_code=status.HTTP_502_BAD_GATEWAY,
            detail="Invalid channel id"
        )
    for id in channel_id:
        if crud_channel_manager.get_channel_manager(db=db,channel_id=id,manager_id=manager_id) is None:
            if crud_channel.get_channel(db=db,channel_id=id):
                raise HTTPException(
            status_code=status.HTTP_502_BAD_GATEWAY,
            detail="Channel not  asign to manager"
        )
    for id in channel_id:
        crud_channel_manager.delete_channel_manager(db=db,manager_id=manager_id,channel_id=id)
    return {"message":"delete success"}
Esempio n. 2
0
def channel_detail(
    channel_id:str,
    current_user= Security(deps.get_current_active_user,scopes=["read_channel"]),
    db: Session = Depends(deps.get_db)
):
    if crud_channel.get_channel(db=db,channel_id=channel_id) is None:
        raise UnicornException(
        messages="CHANNEL ID NOT FOUND",
        name=channel_id
        )
    return crud_channel.get_channel(db=db,channel_id=channel_id)
Esempio n. 3
0
def View_Channel_Details(
    channel_id:str,
    current_user= Security(deps.get_current_active_user,scopes=["READ_CHANNEL"]),
    db: Session = Depends(deps.get_db)
):
    '''
        View Channel details
    '''
    if crud_channel.get_channel(db=db,channel_id=channel_id) is None:
        raise UnicornException(
        messages="CHANNEL ID NOT FOUND",
        name=channel_id
        )
    return crud_channel.get_channel(db=db,channel_id=channel_id)
def get_shop(db: Session, shop_id: str):
    s = db.query(shop.Shop).filter(shop.Shop.id == shop_id).first()
    s.channel_name = crud_channel.get_channel(db=db,
                                              channel_id=s.channel_id).name
    s.country_name = crud_country.get_country(db=db,
                                              country_id=s.postal_code).name
    return s
Esempio n. 5
0
def get_all_shops(db: Session, skip: int = 0, limit: int = 100):
    shops = db.query(shop.Shop).offset(skip).limit(limit).all()
    for s in shops:
        s.channel_name = crud_channel.get_channel(db=db,
                                                  channel_id=s.channel_id).name
        s.country_name = crud_country.get_country(
            db=db, country_id=s.postal_code).name
    return shops
def get_all_shop_channel(db: Session, channel_id: str):
    shops = db.query(
        shop.Shop).filter(shop.Shop.channel_id == channel_id).all()
    for s in shops:
        s.channel_name = crud_channel.get_channel(db=db,
                                                  channel_id=s.channel_id).name
        s.country_name = crud_country.get_country(
            db=db, country_id=s.postal_code).name
    return shops
Esempio n. 7
0
def delete_channel_of_manager(manager_id: str,
                              channel_id: List[str],
                              token: Optional[str] = Header(None),
                              db: Session = Depends(deps.get_db)):

    try:
        check_sercurity_scopes(token=token,
                               scopes=settings.DELETE_CHANNEL_MANAGER_SCOPE)

        manager = crud_user.get_user(db=db, user_id=manager_id)
        if manager is None or manager.role != "manager":
            raise HTTPException(status_code=status.HTTP_502_BAD_GATEWAY,
                                detail="Invalid manager id")
        for id in channel_id:
            if crud_channel.get_channel(db=db, channel_id=id) is None:
                raise HTTPException(status_code=status.HTTP_502_BAD_GATEWAY,
                                    detail="Invalid channel id")
        for id in channel_id:
            if crud_channel_manager.get_channel_manager(
                    db=db, channel_id=id, manager_id=manager_id) is None:
                if crud_channel.get_channel(db=db, channel_id=id):
                    raise HTTPException(
                        status_code=status.HTTP_502_BAD_GATEWAY,
                        detail="Channel not  asign to manager")
        for id in channel_id:
            crud_channel_manager.delete_channel_manager(db=db,
                                                        manager_id=manager_id,
                                                        channel_id=id)
    except (JWTError, ValidationError):
        raise HTTPException(
            status_code=status.HTTP_401_UNAUTHORIZED,
            detail="Unauthorized ",
            headers={"WWW-Authenticate": "Bearer"},
        )
    except (mysql.connector.Error):
        raise HTTPException(
            status_code=status.HTTP_502_BAD_GATEWAY,
            detail="My sql connection error ",
            headers={"WWW-Authenticate": "Bearer"},
        )
    return {"message": "delete success"}
Esempio n. 8
0
def get_all_shop_of_executor(db: Session, executor_id: str):
    all_shop_id = []
    for id in crud_shop_executor.get_shop_id_of_executor(
            db=db, executor_id=executor_id):
        all_shop_id.append(id[0])
    shops = db.query(shop.Shop).filter(shop.Shop.id.in_(all_shop_id)).all()
    for s in shops:
        s.channel_name = crud_channel.get_channel(db=db,
                                                  channel_id=s.channel_id).name
        s.country_name = crud_country.get_country(
            db=db, country_id=s.postal_code).name
    return shops
Esempio n. 9
0
def channel_detail(channel_id: str,
                   token: Optional[str] = Header(None),
                   db: Session = Depends(deps.get_db)):
    try:
        check_sercurity_scopes(token=token,
                               scopes=settings.VIEW_CHANNEL_DETAIL_SCOPE)
    except (JWTError, ValidationError):
        raise HTTPException(
            status_code=status.HTTP_401_UNAUTHORIZED,
            detail="Unauthorized ",
            headers={"WWW-Authenticate": "Bearer"},
        )
    except (mysql.connector.Error):
        raise HTTPException(
            status_code=status.HTTP_502_BAD_GATEWAY,
            detail="My sql connection error ",
            headers={"WWW-Authenticate": "Bearer"},
        )
    return crud_channel.get_channel(db=db, channel_id=channel_id)
Esempio n. 10
0
def delete_manager_from_channel(
    channel_id:str,
    managers_id:List[str],
    current_user= Security(deps.get_current_active_user,scopes=["read_channel"]),
    db: Session = Depends(deps.get_db)
):
    invalid_list=[]
    if crud_channel.get_channel(db=db,channel_id=channel_id) is None:
        raise UnicornException(
        messages="CHANNEL ID NOT FOUND",
        name=channel_id
        )
    if len(managers_id) ==0:
        raise UnicornException(
            messages="INVALID MANAGER ID LIST",
            name=managers_id
        )
    for id in managers_id:
        if crud_user.get_user(db=db,user_id=id) is None or crud_user.get_user(db=db,user_id=id).role!="manager":
            invalid_list.append(id)

    if len(invalid_list) !=0:
        raise UnicornException(
            messages="INVALID MANAGER ID LIST",
            name=invalid_list
        )

    for id in managers_id:
        if crud_channel_manager.get_channel_manager(db=db,channel_id=channel_id,manager_id=id) is None:
            invalid_list.append(id)

    if len(invalid_list) !=0:
        raise UnicornException(
            messages="MANAGER ID NOT FOUND IN CHANNEL",
            name=invalid_list
        )
    for id in managers_id:
        crud_channel_manager.delete_channel_manager(db=db,manager_id=id,channel_id=channel_id)
    return {"message":"update success"}

    
Esempio n. 11
0
def channel_detail(channel_id: str,
                   current_user=Security(deps.get_current_active_user,
                                         scopes=["read_channel"]),
                   db: Session = Depends(deps.get_db)):

    return crud_channel.get_channel(db=db, channel_id=channel_id)