diff --git a/app/main.py b/app/main.py index ffdd96b..800f6c8 100644 --- a/app/main.py +++ b/app/main.py @@ -17,6 +17,7 @@ async def get_widgets(request): else: return web.Response(text=f"no subscribers") + @routes.get('/subscribe/{widget_id}') async def subscribe(request): """ @@ -25,11 +26,13 @@ async def subscribe(request): widget_id = request.match_info['widget_id'] url = request.query['url'] success = toonat.add_subscriber(widget_id, url) + if success: - return web.Response(text=f"Subscribed to widget ID {widget_id} with URL {url}.") + return web.Response(text=f"Subscribed to widget ID {success} with URL {url}.") else: return web.Response(text=f"Already subscribed to widget ID {widget_id} with URL {url}.") + @routes.get('/unsubscribe/{widget_id}') async def unsubscribe(request): """ @@ -38,21 +41,24 @@ async def unsubscribe(request): widget_id = request.match_info['widget_id'] url = request.query['url'] success = toonat.remove_subscriber(widget_id, url) + if success: - return web.Response(text=f"Unsubscribed from widget ID {widget_id} with URL {url}.") + return web.Response(text=f"Unsubscribed from widget ID {success} with URL {url}.") else: return web.Response(text=f"Not subscribed to widget ID {widget_id} with URL {url}.") + @routes.get('/get_widgets') async def get_widgets(request): """ 현재 설정된 모든 위젯 ID 목록을 반환하는 웹 API 엔드포인트입니다. """ widget_ids = toonat.get_widget_ids() + if widget_ids: return web.json_response(widget_ids) else: - return web.Response(text=f"no widget_ids") + return web.Response(text=f"widget ids empty") @routes.get('/add_widget') @@ -62,8 +68,13 @@ async def add_widget(request): widget_id: 추가할 위젯 ID """ widget_id = request.query['widget_id'] - await toonat.add_widget_and_start_fetching_notifications(widget_id) - return web.Response(text=f"Widget ID {widget_id} added and fetching started.") + success = await toonat.add_widget_and_start_fetching_notifications(widget_id) + + if success: + return web.Response(text=f"Widget ID {success} added and fetching started.") + else: + return web.Response(text=f"no widget_ids") + @routes.get('/remove_widget') async def remove_widget(request): @@ -72,8 +83,13 @@ async def remove_widget(request): widget_id: 제거할 위젯 ID """ widget_id = request.query['widget_id'] - await toonat.remove_widget_and_stop_fetching_notifications(widget_id) - return web.Response(text=f"Widget ID {widget_id} removed and fetching stopped.") + success = await toonat.remove_widget_and_stop_fetching_notifications(widget_id) + + if success: + return web.Response(text=f"Widget ID {success} removed and fetching stopped.") + else: + return web.Response(text=f"Not in widget list {widget_id}") + @routes.get('/status') async def status(request): @@ -106,7 +122,6 @@ async def main(): await web_server_task - if __name__ == "__main__": if not toonat.WIDGET_IDS: print("No widget ID found in settings.ini.")