Exemple #1
0
def create_cart_for_user(userId):  # noqa: E501
    """create_cart_for_user

     # noqa: E501

    :param userId: 
    :type userId: int

    :rtype: None
    """
    with Repository() as repository:
        repository.create_cart(userId)
    return
Exemple #2
0
def get_cart_by_user_id(userId):  # noqa: E501
    """get_cart_by_user_id

     # noqa: E501

    :param userId: 
    :type userId: int

    :rtype: Cart
    """
    try:
        with Repository() as repository:
            return repository.get_items(userId)
    except NotFoundException:
        return 404
Exemple #3
0
def checkout_cart(userId):  # noqa: E501
    """checkout_cart

     # noqa: E501

    :param userId: 
    :type userId: int

    :rtype: None
    """
    try:
        with Repository() as repository:
            return repository.checkout_cart(userId)
    except NotFoundException:
        return 404
Exemple #4
0
def empty_cart(userId):  # noqa: E501
    """empty_cart

     # noqa: E501

    :param userId: 
    :type userId: int

    :rtype: None
    """
    try:
        with Repository() as repository:
            repository.delete_cart(userId)
        return
    except NotFoundException:
        return 404
Exemple #5
0
def remove_article_from_cart(userId, articleId):  # noqa: E501
    """remove_article_from_cart

     # noqa: E501

    :param userId: 
    :type userId: int
    :param articleId: 
    :type articleId: int
    :param quantity: 
    :type quantity: int

    :rtype: None
    """
    try:
        with Repository() as repository:
            return repository.remove_item(userId, articleId)
    except NotFoundException:
        return 404
Exemple #6
0
def add_article_to_cart(userId, article):  # noqa: E501
    """add_article_to_cart

     # noqa: E501

    :param userId: 
    :type userId: int
    :param article: 
    :type article: dict | bytes

    :rtype: None
    """
    if connexion.request.is_json:
        article = Item.from_dict(connexion.request.get_json())  # noqa: E501
        try:
            with Repository() as repository:
                cart = repository.get_cart(userId)
                repository.add_item(cart.id, article)
        except NotFoundException:
            return 404
        return
Exemple #7
0
import connexion
import six

from swagger_server.models.article import Article  # noqa: E501
from swagger_server import util

from swagger_server.repository.repository import Repository
from swagger_server.exceptions.exceptions import *

repository = Repository()


def get_articles_by_ids(articleIds):  # noqa: E501
    """get_articles_by_ids

     # noqa: E501

    :param articleIds: IDs of articles that need to be fetched
    :type articleIds: List[int]

    :rtype: Articles
    """
    try:
        articles = repository.get_articles(articleIds)
    except ArticleNotFoundException:
        return 'article not found', 404
    return articles


def get_article(articleId):  # noqa: E501
    """get_articles_by_ids