Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MVC: support business logic layer #411

Open
ego opened this issue Apr 20, 2024 · 1 comment
Open

MVC: support business logic layer #411

ego opened this issue Apr 20, 2024 · 1 comment

Comments

@ego
Copy link

ego commented Apr 20, 2024

We have Model and View aka Node, but we lack a way to write code between them.

class PetBusinessLogic:
    def __init__(self, pet):
        self.pet = pet

    @property
    def name1(self):
        return self.pet.name + "!"

    @property
    def name2(self):
        return self.pet.name + "!"


class Pet(SQLAlchemyObjectType):
    class Meta:
        model = PetModel
        name = "Pet"
        interfaces = (relay.Node,)
        batching = True

    def resolve_name1(node, info):
        # write here application logic code for a large project is not good idea.
        # so we need some controller aka PetBusinessLogic
        return PetBusinessLogic(node).name1    # DRY and I would like to initialize it once

    def resolve_name2(node, info):
        return PetBusinessLogic(node).name2  # DRY and I would like to initialize it once

Any suggestions for this design problem?
*(put this PetBusinessLogic into model is also bad idea)

@ego
Copy link
Author

ego commented May 3, 2024

@syrusakbary any thoughts?

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

No branches or pull requests

1 participant