def sim_details( 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.get_sim_by_number(db=db,sim_number=sim_number)
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"}
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) ): ''' Inactivate user ''' for s in sim: if crud_sim.get_sim_by_number(db=db,sim_number=s) is None: raise HTTPException( status_code=status.HTTP_502_BAD_GATEWAY, detail="Sim not found" ) for u in url: if crud_url.get_url(db=db,id=u) is None: raise HTTPException( status_code=status.HTTP_502_BAD_GATEWAY, detail="Url not found" ) 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: raise HTTPException( status_code=status.HTTP_502_BAD_GATEWAY, detail="Sim url already exist" ) 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"}
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_user.role=="manager": if crud_channel_manager.get_channel_manager(db=db,channel_id=current_shop.channel_id,manager_id=current_user.id) is None: raise HTTPException( status_code=status.HTTP_502_BAD_GATEWAY, detail="Shop not belong to your channel" ) if crud_sim.get_sim_by_number(db=db,sim_number=sim_number) is None: raise HTTPException( status_code=status.HTTP_502_BAD_GATEWAY, detail="Sim number Not Found" ) if current_shop is None: raise HTTPException( status_code=status.HTTP_502_BAD_GATEWAY, detail="Shop not found" ) crud_shop.update_shop_sim(db=db,sim_number=sim_number,shop_id=shop_id) return {"message":"update success"}
async def update_shop_sim(shop_id: str, sim_number: str, token: Optional[str] = Header(None), db: Session = Depends(deps.get_db)): ''' Update sim number of shop ''' try: current_user_id = check_sercurity_scopes( token=token, scopes=settings.UPDATE_SHOP_SIM_SCOPE) payload = jwt.decode(token, settings.SECRET_KEY, algorithms=[settings.ALGORITHM]) current_shop = crud_shop.get_shop(db=db, shop_id=shop_id) if payload.get("role") == "manager": if crud_channel_manager.get_channel_manager( db=db, channel_id=current_shop.channel_id, manager_id=payload.get("id")) is None: raise HTTPException(status_code=status.HTTP_502_BAD_GATEWAY, detail="Shop not belong to your channel") if crud_sim.get_sim_by_number(db=db, sim_number=sim_number) is None: raise HTTPException(status_code=status.HTTP_502_BAD_GATEWAY, detail="Sim number Not Found") if current_shop is None: raise HTTPException(status_code=status.HTTP_502_BAD_GATEWAY, detail="Shop not found") crud_shop.update_shop_sim(db=db, sim_number=sim_number, shop_id=shop_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": "update success"}
def get_sim_db(sim_number: str, token: Optional[str] = Header(None), db: Session = Depends(deps.get_db)): try: check_sercurity_scopes(token=token, scopes=settings.VIEW_SIM_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_sim.get_sim_by_number(db=db, sim_number=sim_number)
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"}
def sim_details(sim_number: str, current_user=Security(deps.get_current_active_user, scopes=["read_sim"]), db: Session = Depends(deps.get_db)): return crud_sim.get_sim_by_number(db=db, sim_number=sim_number)