def article(title): with unit_of_work.SqlAlchemyUnitOfWork() as uow: _article = uow.articles.get(title) if _article: return render_template('article.html', _article=_article) return '<h1>Página não encontrada</h1>', 404
def delete(title): try: article_service.delete_article( article_url=title, uow=unit_of_work.SqlAlchemyUnitOfWork()) return jsonify({'message': 'Article deleted'}), 200 except exceptions.ArticleNotFound as e: return jsonify(message=str(e)), 404
def post(): try: tag_name = tag_service.add_tag( tag_name=request.json['tag_name'].lower(), uow=unit_of_work.SqlAlchemyUnitOfWork()) return jsonify(message=tag_name), 201 except exceptions.DuplicateTag as e: return jsonify(message=str(e)), 409
def create(username, password): uow = unit_of_work.SqlAlchemyUnitOfWork() try: result = credential_service.add_credential(username=username, password=password, uow=uow) print(result) except exceptions.PasswordStrengthError as error: print(str(error))
def editor(): categories = { 'GUIA': category.Category.GUIDE, 'CULTURA': category.Category.CULTURE, 'EXERCÍCIOS': category.Category.EXERCISES } with unit_of_work.SqlAlchemyUnitOfWork() as uow: tags = uow.tags.list() serialized_tags = [tag.name for tag in tags] return render_template('editor.html', categories=categories, tags=serialized_tags), 200
def post(): try: credential_service.add_credential( username=request.json['username'], password=request.json['password'], uow=unit_of_work.SqlAlchemyUnitOfWork()) return jsonify({ "message": f"Credential created for user " f"{request.json['username']}" }), 201 except exceptions.PasswordStrengthError as e: return jsonify(message=str(e)), 400
def post(): try: article = article_service.add_article( title=request.json['title'], description=request.json['description'], content=request.json['content'], tags=request.json['tags'], category_id=int(request.json['category_id']), uow=unit_of_work.SqlAlchemyUnitOfWork()) return jsonify(message=article), 201 except (exceptions.CategoryNotFound, exceptions.DuplicateTitle) as e: return jsonify(message=str(e)), 404
def test_uow_can_add_an_article(session_factory): _article = article.Article(title='An article', description='A great description', content='This is a useful article', tags=[tag.Tag('verbos')], category=category.Category.GUIDE) uow = unit_of_work.SqlAlchemyUnitOfWork(session_factory) with uow: uow.articles.add(_article) uow.commit() session = session_factory() retrieved_article = session.query(article.Article).first() assert retrieved_article.title == 'An article'
def home(): with unit_of_work.SqlAlchemyUnitOfWork() as uow: articles = uow.articles.list() return render_template('home.html', articles=articles), 200