Develop endpoints to retrieve user-specific history and statistics from a web application backend. These endpoints will provide users with access to their past activities and associated data analytics.
Implementation Details
Utilize the fetchUserHistoryAndStats function from the analysisHelpers.js to fetch historical records and aggregate statistical data.
Ensure each endpoint returns the last 10 entries sorted by creation date and provides aggregated sentiment and tone ratios.
Ensure that the response includes all necessary data in a structured and easy-to-consume format for the frontend.
Secure each endpoint with the isLoggedIn middleware to ensure that only authenticated users can access their historical data and statistics.
Design
Define three GET routes in history.js: /mails, /petitions, and /freetexts, each returning the user's history and stats for the respective category.
Use Mongoose or a suitable ODM/ORM to interface with the database models: MailAnalysis, PetitionAnalysis, and FreeTextAnalysis.
Ensure the response format is consistent across all endpoints and includes both the user's historical entries and the statistics.
Tasks
Validate that fetchUserHistoryAndStats works as intended with the existing models.
Ensure that isLoggedIn middleware is correctly verifying user authentication on each endpoint.
Confirm that the correct user ID is being passed from the session to the fetchUserHistoryAndStats function.
Test endpoints to ensure they return correct historical data and statistics, including sentiment and tone ratios.
Implement proper error handling in history.js for database errors or invalid requests.
Expected Output
Each of the history endpoints (/mails, /petitions, /freetexts) returns the latest 10 user-specific records and aggregated statistics.
The response includes sentiment ratios and tone ratios calculated from the user's history.
Acceptance Criteria
The endpoints must check for user authentication and only serve data to the corresponding logged-in user.
The returned data must be accurate and reflect the user's activity and associated analytics.
Aggregated statistics must correctly represent ratios based on the total counts.
Error handling should provide clear and informative feedback for client-side handling.
The implementation must follow RESTful principles and align with existing backend architecture.
Task Description
Develop endpoints to retrieve user-specific history and statistics from a web application backend. These endpoints will provide users with access to their past activities and associated data analytics.
Implementation Details
Utilize the fetchUserHistoryAndStats function from the analysisHelpers.js to fetch historical records and aggregate statistical data. Ensure each endpoint returns the last 10 entries sorted by creation date and provides aggregated sentiment and tone ratios. Ensure that the response includes all necessary data in a structured and easy-to-consume format for the frontend. Secure each endpoint with the isLoggedIn middleware to ensure that only authenticated users can access their historical data and statistics.
Design
Define three GET routes in history.js: /mails, /petitions, and /freetexts, each returning the user's history and stats for the respective category. Use Mongoose or a suitable ODM/ORM to interface with the database models: MailAnalysis, PetitionAnalysis, and FreeTextAnalysis. Ensure the response format is consistent across all endpoints and includes both the user's historical entries and the statistics.
Tasks
Validate that fetchUserHistoryAndStats works as intended with the existing models. Ensure that isLoggedIn middleware is correctly verifying user authentication on each endpoint. Confirm that the correct user ID is being passed from the session to the fetchUserHistoryAndStats function. Test endpoints to ensure they return correct historical data and statistics, including sentiment and tone ratios. Implement proper error handling in history.js for database errors or invalid requests.
Expected Output
Each of the history endpoints (/mails, /petitions, /freetexts) returns the latest 10 user-specific records and aggregated statistics. The response includes sentiment ratios and tone ratios calculated from the user's history.
Acceptance Criteria
The endpoints must check for user authentication and only serve data to the corresponding logged-in user. The returned data must be accurate and reflect the user's activity and associated analytics. Aggregated statistics must correctly represent ratios based on the total counts. Error handling should provide clear and informative feedback for client-side handling. The implementation must follow RESTful principles and align with existing backend architecture.
Screenshots