|
| 1 | +from abc import abstractmethod |
| 2 | +from dataclasses import dataclass |
| 3 | +from types import TracebackType |
| 4 | +from typing import Self |
| 5 | + |
| 6 | +from src.domain.auth.users.interfaces.base import BaseInterface |
| 7 | + |
| 8 | + |
| 9 | +@dataclass |
| 10 | +class MAO(BaseInterface): |
| 11 | + """ |
| 12 | + Media Access Object (MAO) is an abstract class created |
| 13 | + to define and describe necessary functions for files acess. |
| 14 | +
|
| 15 | + It's used in services' layer to manage files. |
| 16 | +
|
| 17 | + As an abstraction, MAO cannot be used directly - that will |
| 18 | + cause `NotImplementedError` and crash the application. So, |
| 19 | + to provide the files access, a MAO implementation is required. |
| 20 | +
|
| 21 | + MAO implementation is a MAO's subclass designed in a unique way |
| 22 | + for an exact type of media storage. It can only be used for |
| 23 | + files operations with data in that type of storage. The implementation |
| 24 | + must be provided to the service's layer via factory to avoid using |
| 25 | + globals. |
| 26 | + """ |
| 27 | + |
| 28 | + @abstractmethod |
| 29 | + async def update_profile_picture(self, data: bytes, user_id: int) -> str: |
| 30 | + """ |
| 31 | + Changes user's profile picture |
| 32 | +
|
| 33 | + :param user_id: user's numeric identificator |
| 34 | + :param data: file data in bytes format |
| 35 | + :return: cover's URL |
| 36 | + :raise NotImplementedError: when called directly by abstract class instance |
| 37 | + """ |
| 38 | + raise NotImplementedError |
| 39 | + |
| 40 | + async def __aenter__(self) -> Self: |
| 41 | + return self |
| 42 | + |
| 43 | + async def __aexit__( |
| 44 | + self, |
| 45 | + exc_type: type[Exception] | None = None, |
| 46 | + exc_val: Exception | None = None, |
| 47 | + exc_tb: TracebackType | None = None, |
| 48 | + ) -> None: |
| 49 | + pass |
0 commit comments