async def delete_collect(public_work_id: str, collect_id: str) -> Response: if repository.delete_collect(public_work_id, collect_id): return Response(success=True) else: return Response(success=False, error=Error(status_code=401, message="Erro ao deletar coleta"))
async def delete_public_work(id: str) -> Response: if repository.delete_public_work(id): return Response(success=True) else: return Response(success=False, error=Error( status_code=401, message="Erro ao deletar obra pública"))
async def add_public_work_to_queue(public_work: PublicWork) -> Response: if repository.add_public_work(public_work): return Response(success=True) else: return Response(success=False, error=Error( status_code=401, message="Erro ao adicionar obra pública"))
async def delete_city( codigo_ibge: str, db: Session = Depends(get_db)) -> Response: city_db = repository.delete_city(db, codigo_ibge) if city_db: return Response(success=True) else: return Response(success=False, error=Error(status_code=401, message="Not able to delete city"))
async def delete_user( email: str, db: Session = Depends(get_db)) -> Response: user = security_repository.delete_user_by_email(db, email) if user: return Response(success=True) else: return Response(success=False, error=Error(status_code=401, message="User not found"))
async def accept_public_work( id: str, db: Session = Depends(get_db)) -> Response: if repository.accept_public_work(db, id): return Response(success=True) else: return Response(success=False, error=Error( status_code=401, message="Erro ao aceitar obra pública"))
async def delete_photo( public_work_id: str, photo_id: str, db: Session = Depends(get_db)) -> Response: if repository.deletePhoto(db, public_work_id, photo_id): return Response(success=True) else: return Response(success=False, error=Error(status_code=401, message="Erro ao deletar foto"))
async def accept_collect( public_work_id: str, collect_id: str, db: Session = Depends(get_db)) -> Response: if repository.accept_collect(db, public_work_id, collect_id): return Response(success=True) else: return Response(success=False, error=Error(status_code=401, message="Erro ao aceitar coleta"))
async def add_photo_to_queue( photo: Photo, db: Session = Depends(get_db)) -> Response: if repository.add_photo(db, photo): return Response(success=True) else: return Response( success=False, error=Error( status_code=401, message="Erro ao adicionar foto a fila, coleta não existe") )
async def add_collect_to_queue( collect: Collect, db: Session = Depends(get_db)) -> Response: if repository.add_collect(db, collect): return Response(success=True) else: return Response( success=False, error=Error( status_code=401, message= "Erro ao adicionar coleta a fila, obra pública não existe") )
async def add_type_photo_to_type_work( type_work_id: int, type_photo_id: int, db: Session = Depends(get_db)) -> Response: result = repository.add_type_photo_to_type_work( db, type_work_id, type_photo_id) if result: return Response(success=result) else: raise HTTPException(status_code=603, detail="Not able to create association")
async def create_user( user: User, db: Session = Depends(get_db)) -> Response: old_user = security_repository.get_user_by_email(db, user.email) if old_user: return Response(success=False, error=Error(status_code=401, message="Esse usuário utilizado.")) if not check_password_strength(user.authentication, 0.2): return Response(success=False, error=Error(status_code=401, message="Senha muito fraca.")) hashed_password = get_password_hash(user.authentication) user.authentication = hashed_password saved_user = security_repository.add_user(db, user) if saved_user: return Response(success=True) else: raise HTTPException(status_code=403, detail="Not able to create user account")
async def update_type_photos_to_type_work( type_work_id: int = Body(...), type_photos: List[int] = Body(...), db: Session = Depends(get_db)) -> Response: result = repository.update_type_photos_to_type_work( db, type_work_id, type_photos) if result: return Response(success=result) else: raise HTTPException( status_code=603, detail="Not able to create association between type photos")
async def create_admin_user( user: User, token: Optional[str] = Header(None), db: Session = Depends(get_db) ) -> Response: old_user = security_repository.get_user_by_email(db, user.email) if old_user: return Response(success=False, error=Error(status_code=401, message="Esse usuário foi utilizado.")) if not token and security_repository.count_admin_users(db) > 0: return Response( success=False, error=Error( status_code=401, message= "Usuário não tem permissão para criar administradores")) if token and security_repository.count_admin_users( db) > 0 and not check_user_role(token, UserRoles.ADMIN, db): return Response(success=False, error=Error(status_code=403, message="Não autorizado")) if not check_password_strength(user.authentication, 0.3): return Response(success=False, error=Error(status_code=401, message="Senha muito fraca.")) hashed_password = get_password_hash(user.authentication) user.authentication = hashed_password user.role = UserRoles.ADMIN.name saved_user = security_repository.add_user(db, user) if saved_user: return Response(success=True) else: raise HTTPException(status_code=403, detail="Not able to create user account")