remove unuse file and modify home debt app

This commit is contained in:
2025-06-26 16:51:54 +07:00
parent c31cff8749
commit 464bb18b3c
10 changed files with 84 additions and 362 deletions
-44
View File
@@ -1,44 +0,0 @@
from typing import Optional, List
from models.channel import DiscordChannel
from infra.db import postgres
class ChannelRepository:
def __init__(self):
self.table = postgres.get_table('discord_channel')
async def get_channel(self, channel_id: int) -> Optional[DiscordChannel]:
try:
response = self.table.select('*').eq('channel_id', channel_id).execute()
if response.data:
return DiscordChannel.model_validate(response.data[0])
return None
except Exception as e:
print(f"Error getting channel: {e}")
return None
async def get_channels_by_server(self, server_id: int) -> List[DiscordChannel]:
try:
response = self.table.select('*').eq('server_id', server_id).execute()
return [DiscordChannel(**channel) for channel in response.data]
except Exception as e:
print(f"Error getting channels: {e}")
return []
async def create_channel(self, server_id: int, channel_id: int, app: str) -> Optional[DiscordChannel]:
try:
channel = DiscordChannel(server_id=server_id, channel_id=channel_id, app=app)
response = self.table.insert(channel.dict(exclude_none=True)).execute()
return DiscordChannel(**response.data[0])
except Exception as e:
print(f"Error creating channel: {e}")
return None
async def update_channel(self, channel_id: int, app: str) -> Optional[DiscordChannel]:
try:
response = self.table.update({'app': app}).eq('channel_id', channel_id).execute()
if response.data:
return DiscordChannel(**response.data[0])
return None
except Exception as e:
print(f"Error updating channel: {e}")
return None
-52
View File
@@ -1,52 +0,0 @@
from typing import Optional, List
from models.channel_app import DiscordChannelApp
from infra.db import postgres
class ChannelAppRepository:
def __init__(self):
self.table = postgres.get_table('discord_channel_app')
async def get_channel_app(self, name: str) -> Optional[DiscordChannelApp]:
try:
response = self.table.select('*').eq('name', name).execute()
if response.data:
return DiscordChannelApp(**response.data[0])
return None
except Exception as e:
print(f"Error getting channel app: {e}")
return None
async def get_all_apps(self) -> List[DiscordChannelApp]:
try:
response = self.table.select('*').execute()
return [DiscordChannelApp(**app) for app in response.data]
except Exception as e:
print(f"Error getting channel apps: {e}")
return []
async def create_channel_app(self, name: str, description: str) -> Optional[DiscordChannelApp]:
try:
app = DiscordChannelApp(name=name, description=description)
response = self.table.insert(app.dict(exclude_none=True)).execute()
return DiscordChannelApp(**response.data[0])
except Exception as e:
print(f"Error creating channel app: {e}")
return None
async def update_channel_app(self, name: str, description: str) -> Optional[DiscordChannelApp]:
try:
response = self.table.update({'description': description}).eq('name', name).execute()
if response.data:
return DiscordChannelApp(**response.data[0])
return None
except Exception as e:
print(f"Error updating channel app: {e}")
return None
async def delete_channel_app(self, channel_id: int, app_name: str) -> bool:
try:
response = self.table.delete().eq('channel_id', channel_id).eq('app_name', app_name).execute()
return len(response.data) > 0
except Exception as e:
print(f"Error deleting channel app: {e}")
return False
-39
View File
@@ -1,39 +0,0 @@
from typing import Optional
from models.server import DiscordServer
from infra.db import postgres
class ServerRepository:
def __init__(self):
self.table = postgres.get_table('discord_server')
async def get(self, server_id: int) -> Optional[DiscordServer]:
"""Get Discord server by ID"""
try:
response = self.table.select('*').eq('server_id', server_id).execute()
if response.data:
return DiscordServer.model_validate(response.data[0])
return None
except Exception as e:
print(f"Error getting server: {e}")
return None
async def create(self, server_id: int, name: str) -> Optional[DiscordServer]:
"""Create new Discord server"""
try:
server = DiscordServer(server_id=server_id, name=name)
response = self.table.insert(server.to_dict()).execute()
return DiscordServer.model_validate(response.data[0])
except Exception as e:
print(f"Error creating server: {e}")
return None
async def update(self, server_id: int, name: str) -> Optional[DiscordServer]:
"""Update Discord server"""
try:
response = self.table.update({'name': name}).eq('server_id', server_id).execute()
if response.data:
return DiscordServer.model_validate(response.data[0])
return None
except Exception as e:
print(f"Error updating server: {e}")
return None