mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 10:05:28 +03:00
work on Response
This commit is contained in:
@@ -3,4 +3,6 @@ from enum import Enum
|
||||
|
||||
class Status(Enum):
|
||||
SUCCESSFUL = 200
|
||||
partSUCCESSFUL = 206
|
||||
UNSUCCESSFUL = 400
|
||||
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
from typing import Callable, Iterator
|
||||
|
||||
from argenta.command import Command
|
||||
from argenta.command.flags.models import InputFlags
|
||||
|
||||
from argenta.response import Response
|
||||
|
||||
|
||||
class CommandHandler:
|
||||
def __init__(self, handler: Callable[[], None] | Callable[[InputFlags], None], handled_command: Command):
|
||||
def __init__(self, handler: Callable[[Response], None], handled_command: Command):
|
||||
"""
|
||||
Private. Entity of the model linking the handler and the command being processed
|
||||
:param handler: the handler being called
|
||||
@@ -15,21 +14,18 @@ class CommandHandler:
|
||||
self._handler = handler
|
||||
self._handled_command = handled_command
|
||||
|
||||
def handling(self, input_flags: InputFlags = None) -> None:
|
||||
def handling(self, response: Response) -> None:
|
||||
"""
|
||||
Private. Direct processing of an input command
|
||||
:param input_flags: the flags of the input command
|
||||
:param response: the entity of response: various groups of flags and status of response
|
||||
:return: None
|
||||
"""
|
||||
if input_flags is not None:
|
||||
self._handler(input_flags)
|
||||
else:
|
||||
self._handler()
|
||||
self._handler(response)
|
||||
|
||||
def get_handler(self) -> Callable[[], None] | Callable[[InputFlags], None]:
|
||||
def get_handler(self) -> Callable[[Response], None]:
|
||||
"""
|
||||
Private. Returns the handler being called
|
||||
:return: the handler being called as Callable[[], None] or Callable[[InputFlags], None]
|
||||
:return: the handler being called as Callable[[Response], None]
|
||||
"""
|
||||
return self._handler
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ from argenta.command import Command
|
||||
from argenta.command.models import InputCommand
|
||||
from argenta.response import Response, Status
|
||||
from argenta.router.command_handler.entity import CommandHandlers, CommandHandler
|
||||
from argenta.command.flag.models import Flag
|
||||
from argenta.command.flags.models import Flags, InputFlags, UndefinedInputFlags, ValidInputFlags, InvalidValueInputFlags
|
||||
from argenta.router.exceptions import (RepeatedFlagNameException,
|
||||
TooManyTransferredArgsException,
|
||||
@@ -30,7 +29,7 @@ class Router:
|
||||
"""
|
||||
Public. Registers handler
|
||||
:param command: Registered command
|
||||
:return: decorated handler as Callable[[Any], Any]
|
||||
:return: decorated handler as Callable
|
||||
"""
|
||||
self._validate_command(command)
|
||||
|
||||
@@ -75,29 +74,26 @@ class Router:
|
||||
if input_command_flags.get_flags():
|
||||
response.status = Status.SUCCESSFUL
|
||||
flags = self._validate_input_flags(handle_command, input_command_flags)
|
||||
response.valid_flags, response.undefined_flags, response.invalid_flags = flags
|
||||
response.valid_flags, response.undefined_flags, response.invalid_value_flags = flags
|
||||
command_handler.handling(response)
|
||||
return
|
||||
else:
|
||||
response.status = Status.SUCCESSFUL
|
||||
command_handler.handling(response)
|
||||
return
|
||||
else:
|
||||
if input_command_flags.get_flags():
|
||||
response.status = Status.UNSUCCESSFUL
|
||||
response.undefined_flags = UndefinedInputFlags(*input_command_flags)
|
||||
response.undefined_flags = UndefinedInputFlags()
|
||||
response.undefined_flags.add_flags(input_command_flags.get_flags())
|
||||
command_handler.handling(response)
|
||||
return
|
||||
else:
|
||||
response.status = Status.SUCCESSFUL
|
||||
command_handler.handling(response)
|
||||
return
|
||||
|
||||
|
||||
@staticmethod
|
||||
def _validate_input_flags(handled_command: Command, input_flags: InputFlags) -> (ValidInputFlags,
|
||||
UndefinedInputFlags,
|
||||
InvalidValueInputFlags):
|
||||
def _validate_input_flags(handled_command: Command, input_flags: InputFlags) -> tuple[ValidInputFlags,
|
||||
UndefinedInputFlags,
|
||||
InvalidValueInputFlags]:
|
||||
"""
|
||||
Private. Validates flags of input command
|
||||
:param handled_command: entity of the handled command
|
||||
|
||||
Reference in New Issue
Block a user