Remnawave_python-sdk/remnawave/controllers/nodes.py
Artem 950a7ffab3
Add Pydantic models for nodes usage history, subscriptions, and user management
- Implemented models for nodes usage history including NodeInfoDto, GetUserAccessibleNodesResponse, and usage statistics.
- Created subscription-related models such as UserSubscription, SubscriptionInfoData, and various response DTOs for subscription information.
- Developed models for subscription settings, templates, and system statistics, enhancing the API's capability to manage and retrieve subscription configurations.
- Introduced user management models including CreateUserRequestDto, UpdateUserRequestDto, and various response DTOs for user actions.
- Added bulk actions for user updates and statistics tracking, improving the efficiency of user management operations.
- Established a base controller for handling API requests and responses, along with decorators for HTTP methods to streamline API interactions.
- Included utility functions for serialization using orjson for better performance with Pydantic models.
2025-07-03 12:22:16 +02:00

101 lines
2.9 KiB
Python

from typing import Annotated
from rapid_api_client import Path
from rapid_api_client.annotations import PydanticBody
from remnawave.models import (
CreateNodeRequestDto,
CreateNodeResponseDto,
DeleteNodeResponseDto,
DisableNodeResponseDto,
EnableNodeResponseDto,
GetAllNodesResponseDto,
GetOneNodeResponseDto,
ReorderNodeRequestDto,
ReorderNodeResponseDto,
RestartAllNodesResponseDto,
RestartNodeResponseDto,
UpdateNodeRequestDto,
UpdateNodeResponseDto,
)
from remnawave.rapid import BaseController, delete, get, patch, post
class NodesController(BaseController):
@post("/nodes", response_class=CreateNodeResponseDto)
async def create_node(
self,
body: Annotated[CreateNodeRequestDto, PydanticBody()],
) -> CreateNodeResponseDto:
"""Create Node"""
...
@get("/nodes", response_class=GetAllNodesResponseDto)
async def get_all_nodes(
self,
) -> GetAllNodesResponseDto:
"""Get All Nodes"""
...
@get("/nodes/{uuid}", response_class=GetOneNodeResponseDto)
async def get_one_node(
self,
uuid: Annotated[str, Path(description="Node UUID")],
) -> GetOneNodeResponseDto:
"""Get One Node"""
...
@delete("/nodes/{uuid}", response_class=DeleteNodeResponseDto)
async def delete_node(
self,
uuid: Annotated[str, Path(description="Node UUID")],
) -> DeleteNodeResponseDto:
"""Delete Node"""
...
@patch("/nodes", response_class=UpdateNodeResponseDto)
async def update_node(
self,
body: Annotated[UpdateNodeRequestDto, PydanticBody()],
) -> UpdateNodeResponseDto:
"""Update Node"""
...
@post("/nodes/{uuid}/actions/enable", response_class=EnableNodeResponseDto)
async def enable_node(
self,
uuid: Annotated[str, Path(description="Node UUID")],
) -> EnableNodeResponseDto:
"""Enable Node"""
...
@post("/nodes/{uuid}/actions/disable", response_class=DisableNodeResponseDto)
async def disable_node(
self,
uuid: Annotated[str, Path(description="Node UUID")],
) -> DisableNodeResponseDto:
"""Disable Node"""
...
@post("/nodes/{uuid}/actions/restart", response_class=RestartNodeResponseDto)
async def restart_node(
self,
uuid: Annotated[str, Path(description="Node UUID")],
) -> RestartNodeResponseDto:
"""Restart Node"""
...
@post("/nodes/actions/restart-all", response_class=RestartAllNodesResponseDto)
async def restart_all_nodes(
self,
) -> RestartAllNodesResponseDto:
"""Restart All Nodes"""
...
@post("/nodes/actions/reorder", response_class=ReorderNodeResponseDto)
async def reorder_nodes(
self,
body: Annotated[ReorderNodeRequestDto, PydanticBody()],
) -> ReorderNodeResponseDto:
"""Reorder Nodes"""
...