ZumitoTeam / zumito-framework

Framework for creating a bot for discord
https://framework.zumito.dev
7 stars 1 forks source link

feat: Add router system #34

Open fernandomema opened 11 months ago

fernandomema commented 11 months ago

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:

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[bot] commented 11 months ago

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.

github-actions[bot] commented 11 months ago

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

reviewpad[bot] commented 11 months ago

Reviewpad Report

:warning: Warnings

github-actions[bot] commented 2 months ago

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