martin-markovic / learn-connect

Multi-feature platform designed to enhance the online learning experience.
MIT License
0 stars 0 forks source link

Implement Chat and Socket Integration with Enhanced Classroom Management and Error Handling #28

Closed martin-markovic closed 1 month ago

martin-markovic commented 1 month ago

Summary

This pull request introduces chat functionality and socket integration into the application, along with significant improvements to classroom management and error handling. The changes include new utility functions, socket configuration, API endpoints for chat operations, and updates to existing schemas.

Changes

  1. Chat and Socket Integration

    • Implemented chatUtils.js to handle finding common classrooms and managing errors.
    • Created socketConfig.js to initialize and define socket events.
    • Developed socketIo.js to configure socket connections based on JWT authentication.
    • Integrated configureSocket and handleSocketConnection functions into server.js for managing socket connections.
    • Added event listeners in socketIo.js for joinRoom, leaveRoom, messageRoom, chat message, and chat activity events.
    • Implemented logging for socket events to monitor user actions and message flows.
  2. Backend Enhancements

    • Developed controller functions based on chat and classroom schemas, integrated into their respective API endpoints in chatRoutes.js.
    • Integrated chatRoutes into the main router via router.js.
    • Updated classroomModel.js to include name and chat fields for better chat management.
    • Implemented a new chatModel.js schema with fields for sender, receiver, text, classroom, and timestamp.
    • Added sendMessage, joinClassroom, getMessages, getUserClassrooms, and leaveClassroom thunks in chatSlice.js for handling asynchronous chat operations.
    • Updated chatService.js with API calls for sending messages, joining/leaving classrooms, and fetching messages and user classrooms.
    • Configured axios requests in chatService.js with authentication tokens.
    • Enhanced error handling in chatService.js to effectively manage API errors.
  3. API Endpoints and Error Handling

    • Added joinClassroom endpoint to allow users to join classrooms, create a chat entry, and handle errors.
    • Implemented getClassroomMessages endpoint to retrieve messages from a classroom, with validation for user membership.
    • Added leaveClassroom endpoint to enable users to leave a classroom, delete associated messages, and handle errors.
    • Integrated the findCommonClassroom utility to manage chat message distribution based on shared classrooms.
    • Enhanced error handling across the application for missing classroom IDs, authorization issues, and invalid classroom states.

Testing

Additional Information