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

feat: Add router system #34

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

feat: Add router system #34

wants to merge 1 commit into from

Conversation

fernandomema
Copy link
Collaborator

@fernandomema fernandomema commented Jul 20, 2023

Summary:

This Pull Request aims to enhance the ZumitoFramework by introducing user routing functionality, empowering developers to publish endpoints on their bot via an express server. The primary addition is the creation of a new class called FrameworkRouter, dedicated to be extended by developers who want to create new routes

Changes Introduced:

  • Creation of FrameworkRouter Class: A new class, FrameworkRouter, has been added to the ZumitoFramework. This class is responsible for handling all routing-related tasks.
  • Route Definition Refactoring: Routes are now defined using a Map type within the ZumitoFramework class, offering improved organization and accessibility.
  • Module Route Registration Updates: The process of registering module routes has been modified to accommodate the new routing functionality.
  • Exporting FrameworkRouter: The FrameworkRouter class is exported in the index.ts file for accessibility across the framework.
  • Introduction of FrameworkRouter Class: The FrameworkRouter class includes a constructor for setting up a basePath and an abstract method getRoutes(), enhancing flexibility and customization.
  • Module Class Enhancements: New methods, registerRoutes() and getRoutes(), have been added to the Module class for registering and retrieving routes, respectively.

Objective:

These modifications are geared towards improving the route handling capabilities of the ZumitoFramework. By introducing user routing functionality and refining the routing process, this Pull Request seeks to enhance the framework's flexibility and usability, ultimately empowering developers to build more robust and efficient bots.

Implementation

Here is an example of a route implementantion on a bot
src/modules/general/routes/Example.ts

import { FrameworkRouter } from "zumito-framework";

export class Example extends FrameworkRouter {
    getRoutes(): Map<string, (req: any, res: any) => void> {
        const routes = new Map();

        routes.set('/test', (req: any, res: any) => {
            res.send('test');
        });

        return routes;
    } 
}

@reviewpad
Copy link
Contributor

reviewpad bot commented Jul 20, 2023

AI-Generated Summary: This pull request introduces significant changes to the ZumitoFramework. A new class FrameworkRouter is created and added to the framework to handle all routing related tasks.

The modifications include:

  1. Moving the definition of routes from any type to a Map type in the ZumitoFramework class.
  2. Making changes in the process of registering module routes.
  3. Adding the FrameworkRouter export to the index.ts file.

Additionally, the pull request also introduces the new FrameworkRouter class which has a constructor for setting up basePath and an abstract method getRoutes().

In the Module class, new methods registerRoutes() and getRoutes() are added for registering and fetching the routes respectively. Three new files are also created in the dist/types and src/types directories - FrameworkRouter.d.ts, FrameworkRouter.js and FrameworkRouter.ts. These files contain the implementation details of the abstract class FrameworkRouter.

Overall, these changes aim to improve the route handling capabilities of the framework.

@reviewpad reviewpad bot added the small Pull request is small label Jul 20, 2023
@github-actions
Copy link

Beta tag version created: 1.1.79.
You can install it with npm install zumito-framework@1.1.79.

@reviewpad
Copy link
Contributor

reviewpad bot commented Jul 20, 2023

Reviewpad Report

⚠️ Warnings

  • Please link an issue to the pull request

@fernandomema fernandomema force-pushed the router branch 3 times, most recently from b14a13d to 687d366 Compare April 19, 2024 09:58
Copy link

Beta tag version created: v1.1.72-dev-8752871829.0.
You can install it with:

npm install zumito-framework@v1.1.72-dev-8752871829.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
small Pull request is small
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant