Open ArunaAcharya opened 1 month ago
Have you deployed the API in Google Cloud and verified the functionality works as expected? Can you also include these test outputs (screenshots) in the Pull Request description please π
@20was @sonam-serchan @ArunaAcharya I see that you are trying to implement some sort of framework or a template - defining routes and modules. What is this process or framework called? What are we basing this off?
@20was @sonam-serchan @ArunaAcharya I see that you are trying to implement some sort of framework or a template - defining routes and modules. What is this process or framework called? What are we basing this off?
I was following a template inspired my this article. This guide provides a structure for creating REST APIs with TypeScript and Node.js, which we could adapt for our project. Feel free to suggest better approach though π
The changes introduce new functionality for handling Slack user information in an Express application. This includes the addition of controllers for fetching user details and status, a service for interacting with the Slack API, and a custom error handling mechanism. The project structure has been modularized by separating routes and controllers into distinct files, enhancing organization. Additionally, a new .gitignore
entry has been added, and the package.json
has been updated with new dependencies and scripts.
Files | Change Summary |
---|---|
.gitignore |
Added launch.json to the list of ignored files. |
package.json |
Updated scripts to include a new dev script using nodemon , added dependencies: morgan , nodemon , zod , and dev dependencies: @types/morgan , ts-node . |
src/authentication/controllers/... |
Introduced getSlackUserDetail and checkSlackUserStatus controller functions for fetching Slack user details and status, respectively. |
src/authentication/models/... |
Added new TypeScript interfaces and types for Slack user data in slackUserInterface.ts , and defined a validation schema in slackUserSchema.ts . |
src/authentication/routes/... |
Created authenticationRouter.ts to define routes for Slack user operations. |
src/authentication/services/... |
Introduced fetchSlackUser.ts service to interact with the Slack API for user information retrieval. |
src/errors/customErrorType.ts |
Added CustomError class for structured error handling. |
src/events/controllers/getEvents.ts |
Introduced a simple getEvents function to handle event requests. |
src/events/routes/eventRoutes.ts |
Created an Express router for handling /events GET requests. |
src/index.ts |
Restructured routing logic to use modular route imports instead of direct route definitions. |
src/middleware/errorMiddleware.ts |
Added error handling middleware to manage errors in the Express application. |
src/server.ts |
Established an Express server setup with middleware and route handling. |
src/slackUser.ts |
Deleted file that previously handled Slack user interactions, as functionality has been modularized and refactored. |
sequenceDiagram
participant Client
participant Server
participant Router
participant Controller
participant Service
Client->>Server: GET /slack/user
Server->>Router: Route request
Router->>Controller: getSlackUserDetail()
Controller->>Service: fetchSlackUser(params)
Service-->>Controller: User data
Controller-->>Router: Respond with user data
Router-->>Server: Send response to Client
sequenceDiagram
participant Client
participant Server
participant Router
participant Controller
participant Service
Client->>Server: GET /slack/user/status
Server->>Router: Route request
Router->>Controller: checkSlackUserStatus()
Controller->>Service: fetchSlackUser(email)
Service-->>Controller: User status
Controller-->>Router: Respond with user status
Router-->>Server: Send response to Client
π° In the burrow where code does hop,
New features bloom, and never stop.
With Slack users fetched, and errors tamed,
Our app now dances, forever acclaimed!
So let us cheer, with a joyful shout,
For the changes made, weβre leaping about! π
Great work @ArunaAcharya
I have implemented a feature-based architecture for this project. This approach organises the codebase around features or domains rather than technical layers. Each feature or domain is encapsulated with its own directory, which includes relevant controllers, modules, routes and tests. Details: Feature Organisation: This project is divided into feature-specific directories such as authentication, event, accolades etc. Each of these directories contains: Controllers: Each controller is responsible for handling the logic associated with a specific router. This separation ensures that each controllers deals with a single route or a set of related routes, simplifying maintenance and understanding of the code.
Models: Data models and interaction with external services Routes: routing definitions for the feature Tests: Unit and integration tests specific to the feature Error Handling: Added a centralised error handling middleware to manage errors consistently across the application. To ensure that the error handling middleware is triggered properly, all errors should be passed to it using the
next
function in controllers. Centralised Routing: index.ts: This file acts as the common router, aggregating and managing routes for various features. It consolidates routes from different feature modules into a single point of entry for routing. Application entry Point: server.ts: This file is the main application entry point. It initialises the Express application, set up middleware and starts the server. it also imports the common router from index.ts and applies it to the Express app.For the existing fetchSlackUser functionality, I have refactored the code into three distinct files for better organization and clarity: fetchSlackUserCtrl.ts: Controller responsible for fetching Slack user details. fetchSlackUserStatusCtrl.ts: Controller dedicated to fetching the status of a Slack user. fetchSlackUser.ts: Module that handles the actual communication with the Slack API to retrieve user information.
tested against google cloud api gateway:
references: https://roro88.medium.com/how-to-create-a-simple-rest-api-using-typescript-and-nodejs-324b80f0122d https://expressjs.com/en/guide/writing-middleware.html
Summary by CodeRabbit
Release Notes
New Features
nodemon
.Bug Fixes
Chores
.gitignore
to excludelaunch.json
.Documentation