<gh_stars>0
from abc import ABC, abstractproperty
from datetime import timedelta

from services.database.database import Database
from utils.utils import parse_date


class Filter(ABC, Database):
    def __init__(self):
        super().__init__()

    @abstractproperty
    def filtered_orders(self):
        pass


class TophatterFilter(Filter):
    """

    Class for filtering tophatter orders.

    """
    def __init__(self, start_date: str, end_date: str):
        super().__init__()
        self.start_date = parse_date(start_date)
        self.end_date = parse_date(end_date)
        self.tophatter = self.get_collection("tophatter")

    @property
    def filtered_orders(self) -> list[dict]:
        """
        Metod is returning list of tophatter filtered orders.
        """
        return list(
            self.tophatter.find(
                {"paid_at": {
                    "$lte": self.end_date,
                    "$gte": self.start_date
                }}))


class ShipstationFilter(Filter):
    """
    Class for filtering shipstation orders.

    """
    def __init__(self, start_date: str, end_date: str, store: str):
        super().__init__()
        self.start_date = parse_date(start_date)
        self.end_date = parse_date(end_date) + timedelta(days=1)
        self.store = store
        self.shipstation = self.get_collection("shipstation")

    @property
    def filtered_orders(self) -> list[dict]:
        """
        Method is returning list of shipstation filtered orders.
        """
        print(self.store)
        return list(
            self.shipstation.find({
                "store": self.store,
                "paymentDate": {
                    "$lte": self.end_date,
                    "$gte": self.start_date
                },
            }))

from abc import ABC, abstractproperty
from datetime import timedelta

from services.database.database import Database
from utils.utils import parse_date


class Filter(ABC, Database):
    def __init__(self):
        super().__init__()

    @abstractproperty
    def filtered_orders(self):
        pass


class TophatterFilter(Filter):
    """

    Class for filtering tophatter orders.

    """
    def __init__(self, start_date: str, end_date: str):
        super().__init__()
        self.start_date = parse_date(start_date)
        self.end_date = parse_date(end_date)
        self.tophatter = self.get_collection("tophatter")

    @property
    def filtered_orders(self) -> list[dict]:
        """
        Metod is returning list of tophatter filtered orders.
        """
        return list(
            self.tophatter.find(
                {"paid_at": {
                    "$lte": self.end_date,
                    "$gte": self.start_date
                }}))


class ShipstationFilter(Filter):
    """
    Class for filtering shipstation orders.

    """
    def __init__(self, start_date: str, end_date: str, store: str):
        super().__init__()
        self.start_date = parse_date(start_date)
        self.end_date = parse_date(end_date) + timedelta(days=1)
        self.store = store
        self.shipstation = self.get_collection("shipstation")

    @property
    def filtered_orders(self) -> list[dict]:
        """
        Method is returning list of shipstation filtered orders.
        """
        print(self.store)
        return list(
            self.shipstation.find({
                "store": self.store,
                "paymentDate": {
                    "$lte": self.end_date,
                    "$gte": self.start_date
                },
            }))
Class for filtering tophatter orders. Metod is returning list of tophatter filtered orders. Class for filtering shipstation orders. Method is returning list of shipstation filtered orders.