def list_blog(user_id=None): if user_id is not None: user = User.get_user_by_id(user_id) else: user = User.get_user_by_email(session['email']) blogs = user.get_blogs() return render_template('user_blogs.html', blogs=blogs, name=user.name)
def get_repository(username: str, repository_name: str, provider: ProviderType, save_data: bool, data_base: SESSION = Depends(get_con)): source = dealer.get_provider(provider=provider) repository = source.get_repository(username=username, repository_name=repository_name) if not repository: return JSONResponse(status_code=404, content=dict(message='Repository not found')) if save_data: user = source.get_user(username=username) if not ModelUser.get_user_by_id( db_session=data_base, index=user.id, provider=provider): model_user = ModelUser(id=user.id, login=user.login, email=user.email, twitter_username=user.twitter_username, provider=provider) status_user, message = model_user.save(connection=data_base) if not status_user: return JSONResponse( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content=dict(message='Database error', details=message)) if not ModelRepository.get_by_id(db_session=data_base, index=repository.id): model_repository = ModelRepository( id=repository.id, user_id=user.id, name=repository.name, private=repository.private, created_at=repository.created_at, updated_at=repository.updated_at, size=repository.size, stars=repository.stars, watchers=repository.watchers) status_repository, message = model_repository.save( connection=data_base) if not status_repository: return JSONResponse( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content=dict(message='Database error', details=message)) return repository
def delete_user(username: str, provider: ProviderType, data_base: SESSION = Depends(get_con)): source = dealer.get_provider(provider=provider) user = source.get_user(username=username) user = ModelUser.get_user_by_id(db_session=data_base, index=user.id, provider=provider) if not user: return 'User deleted' if ModelRepository.get_all_from_local(db_session=data_base, user_id=user.id): return JSONResponse(status_code=status.HTTP_400_BAD_REQUEST, content=dict(message='Constraint violation')) status_user, message = user.delete(connection=data_base) if not status_user: return JSONResponse(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content=dict(message='Database error', details=message)) return 'User deleted'