Skip to content
This repository has been archived by the owner on Apr 14, 2024. It is now read-only.

Commit

Permalink
task/54 rename servises faxed rename classmethods
Browse files Browse the repository at this point in the history
  • Loading branch information
brulitsan committed Sep 29, 2023
1 parent 41fb1bf commit b8d419a
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 21 deletions.
8 changes: 4 additions & 4 deletions sapphire/common/api/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ def __init__(self, title: str, version: str, port: int = 8000):
self._version = version
self._port = port

def base_get_app(self) -> fastapi.FastAPI:
def get_app(self) -> fastapi.FastAPI:
app = fastapi.FastAPI(title=self._title, version=self._version)
app.service = self
self.base_setup_app(app=app)
self.setup_app(app=app)

return app

def base_setup_app(self, app: fastapi.FastAPI):
def setup_app(self, app: fastapi.FastAPI):
pass

async def start(self):
config = uvicorn.Config(app=self.base_get_app(), port=self._port)
config = uvicorn.Config(app=self.get_app(), port=self._port)
server = UvicornServer(config)

self.add_task(server.serve())
10 changes: 5 additions & 5 deletions sapphire/common/broker/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ def __init__(
)
self._producer = aiokafka.AIOKafkaProducer(bootstrap_servers=", ".join(servers))

async def base_consume(self):
async def consume(self):
await self._consumer.start()
try:
async for message in self._consumer:
await self.base_handle(message)
await self.handle(message)
finally:
await self._consumer.stop()

async def base_handle(self, message: aiokafka.ConsumerRecord):
async def handle(self, message: aiokafka.ConsumerRecord):
for handler in self._handlers:
if not await handler.check(message=message):
continue

await handler.handle(message=message)

async def base_start(self):
self.add_task(self.base_consume())
async def start(self):
self.add_task(self.consume())
14 changes: 7 additions & 7 deletions sapphire/common/database/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ def __init__(self, dsn: str):
self._engine = create_async_engine(self._dsn)
self._sessionmaker = async_sessionmaker(self._engine, expire_on_commit=False)

def base_get_alembic_config_path(self) -> pathlib.Path:
def get_alembic_config_path(self) -> pathlib.Path:
raise NotImplementedError

def base_get_alembic_config(self) -> AlembicConfig:
migrations_path = self.base_get_alembic_config_path()
def get_alembic_config(self) -> AlembicConfig:
migrations_path = self.get_alembic_config_path()

config = AlembicConfig()
config.set_main_option("script_location", str(migrations_path))
config.set_main_option("sqlalchemy.url", self._dsn)

return config

def bae_migrate(self):
alembic_command.upgrade(self.base_get_alembic_config(), "head")
def migrate(self):
alembic_command.upgrade(self.get_alembic_config(), "head")

def base_create_migration(self, message: str | None = None):
alembic_command.revision(self.base_get_alembic_config(), message=message, autogenerate=True)
def create_migration(self, message: str | None = None):
alembic_command.revision(self.get_alembic_config(), message=message, autogenerate=True)
2 changes: 1 addition & 1 deletion sapphire/projects/api/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ProjectsAPIService(BaseAPIService):
def __init__(self, version: str, port: int = 8000):
super().__init__(title="Projects", version=version, port=port)

def base_setup_app(self, app: fastapi.FastAPI):
def setup_app(self, app: fastapi.FastAPI):
app.include_router(router, prefix="/api")


Expand Down
2 changes: 1 addition & 1 deletion sapphire/users/api/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(

super().__init__(title="Users", version=version, port=port)

def base_setup_app(self, app: fastapi.FastAPI):
def setup_app(self, app: fastapi.FastAPI):
app.include_router(router, prefix="/api")

@property
Expand Down
2 changes: 1 addition & 1 deletion sapphire/users/database/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class UsersDatabaseService(BaseDatabaseService):
def base_get_alembic_config_path(self) -> pathlib.Path:
def get_alembic_config_path(self) -> pathlib.Path:
return pathlib.Path(__file__).parent / "migrations"


Expand Down
2 changes: 1 addition & 1 deletion sapphire/users/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, database: UsersDatabaseService, version: str = "0.0.0", port:

super().__init__(title="Users", version=version, port=port)

def base_setup_app(self, app: fastapi.FastAPI):
def setup_app(self, app: fastapi.FastAPI):
app.include_router(api.router, prefix="/api")

@property
Expand Down
2 changes: 1 addition & 1 deletion tests/users/database/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_get_alembic_config_path(database_service: UsersDatabaseService):
pathlib.Path(os.curdir).absolute() / "sapphire" / "users" / "database" / "migrations"
)

path = database_service.base_get_alembic_config_path()
path = database_service.get_alembic_config_path()

assert isinstance(path, pathlib.Path)
assert path == expected_path

0 comments on commit b8d419a

Please sign in to comment.