Esempio n. 1
0
def add_new_url(url_list: List[str],
                current_user=Security(deps.get_current_active_user,
                                      scopes=["URL"]),
                db: Session = Depends(deps.get_db)):
    '''
    Create new URL
    '''
    url_fail_list = []

    for url in url_list:
        if sercurity.check_url(url) is None:
            url_fail_list.append(url)

    if len(url_fail_list) != 0:
        raise UnicornException(messages="Wrong URL format", name=url_fail_list)

    for url in url_list:
        if not crud_url.find_url(db=db, input_url=url) is None:
            url_fail_list.append(url)

    if len(url_fail_list) != 0:
        raise UnicornException(messages="URL ALREADY EXIST",
                               name=url_fail_list)
    for url in url_list:
        crud_url.create_new_url(db=db, new_url=url)
    return url_list
Esempio n. 2
0
def asign_url_to_sim(sim: List[str],
                     url: List[str],
                     current_user=Security(deps.get_current_active_user,
                                           scopes=["url"]),
                     db: Session = Depends(deps.get_db)):
    '''
    Asign url to sim 
    '''
    invalid_list = []
    for s in sim:
        if crud_sim.get_sim_by_number(db=db, sim_number=s) is None:
            invalid_list.append(s)
    if len(invalid_list) != 0:
        raise UnicornException(messages="SIM NUMBER NOT FOUND",
                               name=invalid_list)
    for u in url:
        if crud_url.get_url(db=db, id=u) is None:
            invalid_list.append(u)

    if len(invalid_list) != 0:
        raise UnicornException(messages="URL ID NOT FOUND", name=invalid_list)
    for s in sim:
        for u in url:
            if not crud_sim_url.get_sim_url(db=db, sim_number=s,
                                            url_id=u) is None:
                invalid_list.append([s, u])

    if len(invalid_list) != 0:
        raise UnicornException(messages="URL&SIM ALREADY ASIGN",
                               name=invalid_list)
    for s in sim:
        for u in url:
            crud_sim_url.create_new_sim_url(db=db, sim_number=s, url_id=u)

    return {"message": " success"}
Esempio n. 3
0
def update_url(url_id: str,
               new_url: str,
               current_user=Security(deps.get_current_active_user,
                                     scopes=["url"]),
               db: Session = Depends(deps.get_db)):
    '''
    Update URL
    '''
    if sercurity.check_email(new_url) is None:
        raise UnicornException(messages="INVALID URL FORMAT", name=new_url)
    if crud_url.get_url(db=db, id=url_id) is None:
        raise UnicornException(messages="URL Not Found", name=url_id)
    crud_url.update_url(db=db, id=url_id, new_url=new_url)
    return {"message": " success"}
Esempio n. 4
0
def View_country_detail(postal_code: str,
                        current_user=Security(deps.get_current_active_user,
                                              scopes=["read_country"]),
                        db: Session = Depends(deps.get_db)):
    if crud_country.get_country(db=db, country_id=postal_code) is None:
        raise UnicornException(messages="COUNTRY ID NOT FOUND",
                               name=postal_code)
    return crud_shop.get_all_shop_country(db=db, postal_code=postal_code)
Esempio n. 5
0
def Create_new_user(new_user: user_schema.UserCreate,
                    current_user=Security(deps.get_current_active_user,
                                          scopes=["read_user"]),
                    db: Session = Depends(deps.get_db)):
    '''
    Create_new_user
    '''
    if sercurity.check_email(new_user.user_name) is False:
        raise UnicornException(messages="Invalid Email",
                               name=new_user.user_name)
    if not crud_user.get_user_by_username(
            db=db, user_name=new_user.user_name) is None:
        raise UnicornException(messages="Email already exist",
                               name=new_user.user_name)
    if new_user.role not in ['executor', 'manager']:
        raise HTTPException(status_code=status.HTTP_502_BAD_GATEWAY,
                            detail="Invalid Role")
    return crud_user.create_user(db=db, users=new_user)
Esempio n. 6
0
def View_all_sim_of_shop(shop_id: str,
                         current_user=Security(deps.get_current_active_user,
                                               scopes=["READ_SHOP"]),
                         db: Session = Depends(deps.get_db)):
    '''
    View All sim of shop
    '''
    if crud_shop.get_shop(db=db, shop_id=shop_id) is None:
        raise UnicornException(messages="SHOP ID NOT FOUND", name=shopid)
    return crud_sim.get_all_sim_of_shop(db=db, shop_id=shop_id)
Esempio n. 7
0
def get_sim_db(
    sim_number:str,
    current_user= Security(deps.get_current_active_user,scopes=["read_sim"]),
    db: Session = Depends(deps.get_db)
):
    if crud_sim.get_sim_by_number(db=db,sim_number=sim_number) is None:
        raise UnicornException(
            messages="SIM NOT FOUND",
            name=sim_number
        )
    return crud_sim.count_shop(db=db,sim_number=sim_number)
Esempio n. 8
0
def all_channel_manager_not_belong_to_channel(
    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_user.get_all_manager_not_belong_to_channel(db=db,channel_id=channel_id)
Esempio n. 9
0
def Count_shop_of_channel(
    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_shop.count_shop(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 View_All_Shop_Of_Country(postal_code: str,
                             current_user=Security(
                                 deps.get_current_active_user,
                                 scopes=["READ_COUNTRY"]),
                             db: Session = Depends(deps.get_db)):
    '''
        View ALL Shop Of Country
    '''
    if crud_country.get_country(db=db, country_id=postal_code) is None:
        raise UnicornException(messages="COUNTRY ID NOT FOUND",
                               name=postal_code)
    return crud_shop.get_all_shop_country(db=db, postal_code=postal_code)
Esempio n. 12
0
def Delete_url_list(id_list: List[str],
                    current_user=Security(deps.get_current_active_user,
                                          scopes=["URL"]),
                    db: Session = Depends(deps.get_db)):
    '''
    Create new URL
    '''
    invalid_list = []
    for id in id_list:
        if crud_url.get_url(db=db, id=id) is None:
            invalid_list.append(id)

    if len(invalid_list) != 0:
        raise UnicornException(messages="URL ID NOT FOUND", name=invalid_list)
    for id in id_list:
        if crud_sim_url.count_sim_of_url(db=db, url_id=id) != 0:
            invalid_list.append(id)

    if len(invalid_list) != 0:
        raise UnicornException(messages="DELETE FAIL", name=invalid_list)
    for url in id_list:
        crud_url.delete_url(db=db, id=url)
    return id_list
Esempio n. 13
0
def View_All_shop_of_channel(
    channel_id:str,
    current_user= Security(deps.get_current_active_user,scopes=["READ_CHANNEL"]),
    db: Session = Depends(deps.get_db)
):
    '''
        View All Shop of channel
    '''
    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_shop.get_all_shop_channel(db=db,channel_id=channel_id)
Esempio n. 14
0
def All_shop_executors(
    shop_id:str,
    current_user= Security(deps.get_current_active_user,scopes=["read_shop"]),
    db: Session = Depends(deps.get_db)
):
    '''
    View All shop executors
    '''
    if crud_shop_sim.get_all_shop_sim(db=db,shop_id=shop_id) is None:
        raise UnicornException(
            messages="SHOP ID NOT FOUND",
            name=shop_id
            )
    return crud_shop_sim.get_all_shop_sim(db=db,shop_id=shop_id)
Esempio n. 15
0
def All_executor_that_not_managed_shop(
    shop_id:str,
    current_user= Security(deps.get_current_active_user,scopes=["read_shop"]),
    db: Session = Depends(deps.get_db)
):
    '''
    View all executors that not managed shop with shop id
    '''
    if crud_shop.get_shop(db=db,shop_id=shopid) is None:
        raise UnicornException(
            messages="SHOP ID NOT FOUND",
            name=shopid
            )
    return crud_user.get_all_shop_not_belong_to_executors(db=db,shop_id=shop_id)
Esempio n. 16
0
def Number_of_shop_executors(
    shop_id:str,
    current_user= Security(deps.get_current_active_user,scopes=["read_shop"]),
    db: Session = Depends(deps.get_db)
):
    '''
    Number of executors that managed Shop with shop id
    '''
    if crud_shop.get_shop(db=db,shop_id=shopid) is None:
        raise UnicornException(
            messages="SHOP ID NOT FOUND",
            name=shopid
            )
    return crud_shop_executor.count_shop_of_executors(db=db,shop_id=shop_id)
Esempio n. 17
0
def Shop_detail(
    shopid:str,
    current_user= Security(deps.get_current_active_user,scopes=["read_shop"]),
    db: Session = Depends(deps.get_db)
):
    '''
    View Shop detail by Shop Id request
    '''
    if crud_shop.get_shop(db=db,shop_id=shopid) is None:
        raise UnicornException(
            messages="SHOP ID NOT FOUND",
            name=shopid
            )
    return crud_shop.get_shop(db=db,shop_id=shopid)
Esempio n. 18
0
async def delete_executors_of_shop(
    executors_id: List[str],
    shop_id:str,
    current_user= Security(deps.get_current_active_user,scopes=["shop_executor"]),
    db: Session = Depends(deps.get_db)
):
    '''
    Delete one or many executors to shop with shop id and list of executor id
    '''
    invalid_list=[]
    if crud_shop.get_shop(db=db,shop_id=shopid) is None:
        raise UnicornException(
            messages="SHOP ID NOT FOUND",
            name=shopid
            )
    current_shop=crud_shop.get_shop(db=db,shop_id=shop_id)
    if crud_channel_manager.get_channel_manager(db=db,channel_id=current_shop.channel_id,manager_id=current_user.id) is None:
        raise UnicornException(
            messages="SHOP ID NOT FOUND",
            name=shopid
            )
    if len(executors_id) ==0:
        raise UnicornException(
            messages="INVALID EXECUTOR ID LIST",
            name=executors_id
            )
    for id in executors_id:
        if crud_user.get_user(db=db,user_id=id)is None :
            invalid_list.append(id)
    
    if len(invalid_list)!=0:
        raise UnicornException(
            messages="EXECUTOR NOT EXIST",
            name=invalid_list
            )
    for id in executors_id:
        if  crud_user.get_user(db=db,user_id=id).role!="executor" :
            invalid_list.append(id)

    if len(invalid_list)!=0:
        raise UnicornException(
            messages="USER IS NOT EXECUTOR",
            name=invalid_list
            )
    
    for id in executors_id:
        if crud_shop_executor.get_shop_executor(db=db,shop_id=shop_id,executor_id=id) is None:
            invalid_list.append(id)

    if len(invalid_list)!=0:
        raise UnicornException(
            messages="EXECUTOR NOT BELONG TO SHOP",
            name=invalid_list
            )
    for id in executors_id:
        crud_shop_executor.delete_shop_executor(db=db,shop_id=shop_id,executor_id=id)
    return {"message":"update success"}
Esempio n. 19
0
async def update_shop_sim(
    shop_id:str,
    sim_number:str,
    current_user= Security(deps.get_current_active_user,scopes=["shop_executor"]),
    db: Session = Depends(deps.get_db)
):
    '''
    Update sim number of shop
    '''
    current_shop=crud_shop.get_shop(db=db,shop_id=shop_id)
    if current_shop is None:
        raise UnicornException(
                messages="SHOP ID NOT FOUND",
                name=shop_id)
    if crud_channel_manager.get_channel_manager(db=db,channel_id=current_shop.channel_id,manager_id=current_user.id) is None:
        raise UnicornException(
                messages="SHOP NOT BELONG TO YOUR CHANNEL",
                name=shop_id)
    if crud_sim.get_sim_by_number(db=db,sim_number=sim_number) is None:
        raise UnicornException(
                messages="SIM NOT FOUND",
                name=sim_number)
    crud_shop.update_shop_sim(db=db,sim_number=sim_number,shop_id=shop_id)
    return {"message":"update success"}
Esempio n. 20
0
async def add_many_executor_to_many_shop(
    executors_id: List[str],
    shop_id:List[str],
    current_user= Security(deps.get_current_active_user,scopes=["shop_executor"]),
    db: Session = Depends(deps.get_db)
):
    '''
    Asign one or many executors to one or many shops with list of  executors and shops request
    '''  
    invalid_list=[]
    if len(executors_id) ==0 :
        raise UnicornException(
                messages="EXECUTOR ID LIST IS EMPTY",
                name=executors_id
            )
    if len(shop_id) ==0 :
        raise UnicornException(
                messages="SHOP ID LIST IS EMPTY",
                name=executors_id
            )
    for id in shop_id:
        current_shop=crud_shop.get_shop(db=db,shop_id=id)
        if current_shop is None:
            invalid_list.append(id)

    if len(invalid_list)!=0:
        raise UnicornException(
                messages="SOME SHOP NOT FOUND",
                name=invalid_list
            )
    for id in shop_id:
        current_shop=crud_shop.get_shop(db=db,shop_id=id)
        if crud_channel_manager.get_channel_manager(db=db,channel_id=current_shop.channel_id,manager_id=current_user.id) is None:
            invalid_list.append(id)
    
    if len(invalid_list)!=0:
        raise UnicornException(
                messages="SOME SHOP NOT BELONG TO YOUR CHANNEL",
                name=invalid_list
            )
    for id in executors_id:
        if crud_user.get_user(db=db,user_id=id)is None :
            invalid_list.append(id)
    
    if len(invalid_list)!=0:
        raise UnicornException(
            messages="EXECUTOR NOT EXIST",
            name=invalid_list
            )
    for id in executors_id:
        if  crud_user.get_user(db=db,user_id=id).role!="executor" :
            invalid_list.append(id)

    if len(invalid_list)!=0:
        raise UnicornException(
            messages="USER IS NOT EXECUTOR",
            name=invalid_list
            )       
        
    for eid in executors_id:
        for sid in shop_id:
            invalid_list.append([eid,sid])

    if len(invalid_list)!=0:
        raise UnicornException(
            messages="EXECUTOR&SHOP ALREADY ASIGN",
            name=invalid_list
            )  
    for eid in executors_id:
        for sid in shop_id:
            crud_shop_executor.create_new_shop_executor(db=db,shop_id=sid,executor_id=eid)
    return {"message":"update success"}