Skip to content

Conversation

@annopkdd
Copy link

@annopkdd annopkdd commented Sep 9, 2017

To do

  • Receiver
  • Command
  • Command Register
  • Command Bus
  • Middleware
  • Handle
  • Message Template/Message Factory

@liverbool
Copy link
Contributor

@criticalnooks Can you port this php function to python?

    /**
     * @param Middleware[] $middlewareList
     *
     * @return callable
     */
    function createExecutionChain(array $middlewareList)
    {
        $lastCallable = function () {
            // the final callable is a no-op
        };

        while ($middleware = array_pop($middlewareList)) {
            $lastCallable = function ($command) use ($middleware, $lastCallable) {
                return $middleware->execute($command, $lastCallable);
            };
        }

        return $lastCallable;
    }

criticalnooks added 21 commits September 25, 2017 18:03
MiddleWare
- button_template_middleware
- carousel_template_middleware
- confirm_template_middleware
- default_message_middleware
- image_carousel_template_middleware
- image_message_middleware
-
 imagemap_send_message_middleware
- location_message_middleware
- sticker_message_middleware

Structure
- use dependency injection for middleware
SyntaxError: invalid syntax
TypeError: execute() takes 1 positional argument but 2 were given
NameError: name 'Command' is not defined
 AttributeError: 'MessageTemplateFactory' object has no attribute 'template'
 KeyError: 'longtitude'
KeyError: 'alt_text'
 Process exited with status 3
CarouselTemplate
ImagemapSendTemplate
 KeyError: 'template'
KeyError: 'template'(again)
 NameError: name 'LocationSendMessage' is not defined
change base_url ImageMapSendMessage
ImageMapSendMessage
change base_url
change link_uri
DefaultMessageMiddleware
fix word
@liverbool
Copy link
Contributor

liverbool commented Sep 26, 2017

👍 looks good!

I thinks we need to small change to something like this (?)

pseudo code

class DefaultCommand():
    property name = 'DefaultCommand'
    property cmd = ''
    property template = None

    private event;

    self. __init__(event):
        self.event = event;

    self.isValidCmd():
        return self.cmd == self.event.input

class CommandA():
    property name = 'CommandA'
    property cmd = '/a'
    property template = None

    private event;

    self. __init__(event):
        self.event = event;

    self.isValidCmd():
        return self.cmd == self.event.input

class CommandB():
    property name = 'CommandB'
    property cmd = '/b'
    property template = None

    private event;

    self. __init__(event):
        self.event = event;

    self.isValidCmd():
        return self.cmd == self.event.input

class CommandRegistry():
    private commands = []

    def add(command):
        self.commands.push(command)

    def find(event):
        for (self.commands as command) {
            command = new command(event);
            if (command.isValidCmd()) {
                return command;
            }
        }

        return new DefaultCommand(event);

# Usage
commandRegistry = new CommandRegistry();
commandRegistry.add(CommandA)
commandRegistry.add(CommandB)

# middleware
class MiddlewareX():
    def execute(command):
        if (command.name != 'CommandA') {
            return;
        }

        # i want to tell this command to send vdo message
        command.template = new VdoMessageTemplate(....);

Command should have Abstract -- to handle common logic of commands.

from abc import ABCMeta, abstractmethod

class Command:
    __metaclass__ = ABCMeta
    
    property event;
    property template;

    def setEvent(event):
        self.event = event;

    @abstractmethod
    def isValidCmd(self): pass

class CommandA(Command):
    property cmd
    property name

    def isValidCmd():
        return self.cmd === self.event.input

# in CommandRegistry.find(event) 
....
    command = new CommandA()
    command.setEvent(event)
....

criticalnooks added 2 commits September 27, 2017 15:34
- modify command object
AttributeError: 'CommandRegistry' object has no attribute 'check'
criticalnooks added 25 commits September 27, 2017 15:41
NameError: name 'self' is not defined
AttributeError: 'Command1' object has no attribute 'isValidCmd'
NameError: name 'default_command' is not defined
AttributeError: 'NoneType' object has no attribute 'get_command'
AttributeError: 'NoneType' object has no attribute 'get_command'
AttributeError: 'NoneType' object has no attribute 'get_command'
AttributeError: 'NoneType' object has no attribute 'get_command'
I think it's work now!
: TypeError: string indices must be integers
TabError: inconsistent use of tabs and spaces in indentation
SyntaxError: invalid syntax
debug hello middleware
AttributeError: 'HelloMiddleware' object has no attribute 'command'
in all middleware
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants