示例#1
0
def buy(ctx, uid, quantity):
    """Buy an article"""
    if quantity > 0:
        article_service = ArticleService(ctx.obj['table_name'])
        article = article_service.get_article(uid)
        article.increment_sales(quantity)
        status = article_service.update_article(article)

        if status:
            click.echo('Article bought')
        else:
            click.echo('Error: something went wrong')
    elif quantity < 0:
        click.echo('Invalid quantity')
示例#2
0
def update(ctx, uid):
    """Update an article"""
    article_service = ArticleService(ctx.obj['table_name'])
    article = article_service.get_article(uid)

    if article:
        article = _update_article_flow(article)
        status = article_service.update_article(article)

        if status:
            click.echo('Successful article update')
        else:
            click.echo('Error: something went wrong')
    else:
        click.echo(f'Error: the article with uid {uid} doesnt exists')