Skip to content

Conversation

@rubybui
Copy link
Owner

@rubybui rubybui commented May 17, 2025

Description

Brief summary of the changes and any relevant context (design doc, screenshots of bugs...).

Fixes # (issue)

Changes

  • Feature: Describe new features or changes.
  • Bugfix: Outline any bug fixes.
  • Refactor: Note any code refactoring.

Testing

Describe tests run to verify changes. If manual testing has been done, provide instructions to reproduce.

  • Unit tests
  • Manual testing

Checklist:

  • Added tests for new features or bug fixes
  • (For the final review) I have refactored my code :)

Summary by CodeRabbit

  • New Features
    • Introduced the ability to associate multiple surveys with campaigns and vice versa.
    • Added tracking of how many survey responses a campaign participant has submitted.
    • Campaigns now specify the required number of survey responses needed to earn a reward.
    • Added new API endpoints to retrieve campaigns, survey response counts, and participation data for authenticated users.

@coderabbitai
Copy link

coderabbitai bot commented May 17, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This update introduces a many-to-many relationship between campaigns and surveys by adding a new association table, campaign_surveys, to the database schema and ORM models. It also adds integer columns to track required and submitted survey responses in the Campaign and CampaignParticipation models, respectively. Additionally, new API routes, repository methods, and service methods were added to support campaign-related data retrieval. Minor renaming was done in the emergency contacts API for clarity.

Changes

File(s) Change Summary
migrations/versions/6d69432c2997_update_campaign_model.py Migration script adds campaign_surveys association table, survey_responses_count to campaign_participation, and required_survey_responses to campaigns. Downgrade reverses these changes.
mind_matter_api/models/campaigns.py Updates Campaign model with required_survey_responses and surveys relationship. Adds survey_responses_count to CampaignParticipation. Introduces CampaignSurvey association model.
mind_matter_api/models/surveys.py Adds campaigns relationship to Survey model, establishing many-to-many link with Campaign.
mind_matter_api/api/init.py Imports campaign-related modules, initializes CampaignsService, and registers campaign routes in app.
mind_matter_api/api/campaigns.py Adds new Flask API routes for campaigns: list campaigns, get survey responses count, and get campaign participation, all requiring authentication.
mind_matter_api/api/emergency_contacts.py Renames emergency contacts service instance variable from svc to emergency_contact_service for clarity.
mind_matter_api/repositories/campaigns.py Adds methods get_survey_responses_count and get_campaign_participation to CampaignRepository.
mind_matter_api/services/campaigns.py Adds methods get_survey_responses_count and get_campaign_participation to CampaignsService, delegating to repository.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant FlaskApp
    participant CampaignsService
    participant CampaignRepository
    participant Database

    User->>FlaskApp: GET /campaigns
    FlaskApp->>CampaignsService: get_campaigns(user_id)
    CampaignsService->>CampaignRepository: query campaigns by user_id
    CampaignRepository->>Database: fetch campaigns
    Database-->>CampaignRepository: campaigns data
    CampaignRepository-->>CampaignsService: campaigns data
    CampaignsService-->>FlaskApp: campaigns data
    FlaskApp-->>User: campaigns list

    User->>FlaskApp: GET /campaigns/{id}/survey-responses-count
    FlaskApp->>CampaignsService: get_survey_responses_count(campaign_id)
    CampaignsService->>CampaignRepository: get survey responses count
    CampaignRepository->>Database: count query
    Database-->>CampaignRepository: count
    CampaignRepository-->>CampaignsService: count
    CampaignsService-->>FlaskApp: count
    FlaskApp-->>User: count

    User->>FlaskApp: GET /campaigns/{id}/participation
    FlaskApp->>CampaignsService: get_campaign_participation(campaign_id)
    CampaignsService->>CampaignRepository: get participation data
    CampaignRepository->>Database: select participation
    Database-->>CampaignRepository: participation data
    CampaignRepository-->>CampaignsService: participation data
    CampaignsService-->>FlaskApp: participation data
    FlaskApp-->>User: participation data
Loading

Poem

In fields of code where campaigns bloom,
Surveys now join, dispelling the gloom.
With counts to track, and links anew,
Rabbits hop, database grew!
Many-to-many, the tables dance,
Rewards await—let’s give surveys a chance!
🐇✨

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between d896dc4 and 900a8c6.

📒 Files selected for processing (2)
  • mind_matter_api/api/__init__.py (2 hunks)
  • mind_matter_api/services/campaigns.py (2 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@rubybui
Copy link
Owner Author

rubybui commented May 17, 2025

Associate multiple surveys with a campaign
Track how many times each participant has responded to surveys
Set a required number of survey responses for rewards
Monitor participant progress through the survey_responses_count

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
mind_matter_api/models/campaigns.py (2)

29-29: Great performance optimization for tracking responses

Adding a counter column is more efficient than counting related records every time you need this information. Consider adding validation to ensure this count doesn't exceed the required responses.

-    survey_responses_count = db.Column(db.Integer, default=0)  # Track number of survey responses
+    survey_responses_count = db.Column(db.Integer, default=0)  # Track number of survey responses
+    
+    @property
+    def has_completed_surveys(self):
+        """Check if participant has completed the required number of survey responses"""
+        return self.survey_responses_count >= self.campaign.required_survey_responses

35-42: Well-structured association model

Using a full model class for the association table rather than a simple Table construct is a good approach as it allows tracking creation timestamps and potentially adding more functionality later. The composite primary key is correctly defined.

Consider adding methods to this model to handle association-specific logic if needed in the future, such as:

def is_active(self):
    """Check if this campaign-survey association is still active based on campaign dates"""
    now = datetime.utcnow()
    return self.campaign.start_date <= now <= self.campaign.end_date
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between c72a5b6 and 091f3ec.

📒 Files selected for processing (3)
  • migrations/versions/6d69432c2997_update_campaign_model.py (1 hunks)
  • mind_matter_api/models/campaigns.py (2 hunks)
  • mind_matter_api/models/surveys.py (1 hunks)
🔇 Additional comments (6)
mind_matter_api/models/surveys.py (1)

19-19: Well-implemented bidirectional relationship!

The many-to-many relationship between Survey and Campaign models is properly defined with appropriate parameters. The secondary parameter correctly references the association table, and the back_populates parameter maintains the bidirectional relationship with the surveys attribute in the Campaign model.

migrations/versions/6d69432c2997_update_campaign_model.py (3)

21-28: Association table design looks good

The campaign_surveys table is correctly structured with composite primary keys and appropriate foreign key constraints. Including a timestamp will be helpful for auditing when associations were created.


29-31: Proper tracking of survey responses

Adding survey_responses_count to track participant survey submissions is a good approach for performance optimization, as it avoids the need to count related records each time this information is needed.


38-47: Downgrade function is correctly implemented

The downgrade function correctly reverts all changes in the proper order: first dropping the added columns, then dropping the association table.

mind_matter_api/models/campaigns.py (2)

15-15: Good addition of required responses tracking

The required_survey_responses column with a default value of 1 provides a clear way to configure how many survey responses are needed for a campaign to be completed. The default value also ensures backward compatibility.


19-19: Properly defined many-to-many relationship

The relationship to surveys is correctly implemented using the secondary parameter to reference the association table and back_populates to maintain bidirectionality.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

🧹 Nitpick comments (1)
mind_matter_api/api/campaigns.py (1)

1-7: Remove unused imports.

Several imports are not used in this file and should be removed to improve code clarity.

- from flask import jsonify, request, current_app
- from marshmallow import ValidationError
+ from flask import jsonify

- from mind_matter_api.utils.decorators import require_auth, require_owner
- from mind_matter_api.utils.auth import is_user_owner, is_user_admin
+ from mind_matter_api.utils.decorators import require_auth
🧰 Tools
🪛 Ruff (0.11.9)

1-1: flask.jsonify imported but unused

Remove unused import

(F401)


1-1: flask.request imported but unused

Remove unused import

(F401)


1-1: flask.current_app imported but unused

Remove unused import

(F401)


2-2: marshmallow.ValidationError imported but unused

Remove unused import: marshmallow.ValidationError

(F401)


5-5: mind_matter_api.utils.decorators.require_owner imported but unused

Remove unused import: mind_matter_api.utils.decorators.require_owner

(F401)


6-6: mind_matter_api.utils.auth.is_user_owner imported but unused

Remove unused import

(F401)


6-6: mind_matter_api.utils.auth.is_user_admin imported but unused

Remove unused import

(F401)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 091f3ec and d896dc4.

📒 Files selected for processing (5)
  • mind_matter_api/api/__init__.py (2 hunks)
  • mind_matter_api/api/campaigns.py (1 hunks)
  • mind_matter_api/api/emergency_contacts.py (5 hunks)
  • mind_matter_api/repositories/campaigns.py (2 hunks)
  • mind_matter_api/services/campaigns.py (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • mind_matter_api/api/emergency_contacts.py
🧰 Additional context used
🧬 Code Graph Analysis (4)
mind_matter_api/api/__init__.py (3)
mind_matter_api/api/campaigns.py (1)
  • init_campaigns_routes (11-27)
mind_matter_api/repositories/campaigns.py (1)
  • CampaignRepository (6-45)
mind_matter_api/services/campaigns.py (1)
  • CampaignsService (5-32)
mind_matter_api/services/campaigns.py (3)
mind_matter_api/models/campaigns.py (1)
  • CampaignParticipation (21-33)
mind_matter_api/api/campaigns.py (2)
  • get_survey_responses_count (21-22)
  • get_campaign_participation (26-27)
mind_matter_api/repositories/campaigns.py (2)
  • get_survey_responses_count (41-42)
  • get_campaign_participation (44-45)
mind_matter_api/repositories/campaigns.py (4)
mind_matter_api/models/campaigns.py (2)
  • Campaign (4-19)
  • CampaignParticipation (21-33)
mind_matter_api/repositories/types.py (1)
  • Repository (7-56)
mind_matter_api/api/campaigns.py (2)
  • get_survey_responses_count (21-22)
  • get_campaign_participation (26-27)
mind_matter_api/services/campaigns.py (2)
  • get_survey_responses_count (13-15)
  • get_campaign_participation (17-19)
mind_matter_api/api/campaigns.py (3)
mind_matter_api/services/campaigns.py (4)
  • CampaignsService (5-32)
  • get_campaigns (9-11)
  • get_survey_responses_count (13-15)
  • get_campaign_participation (17-19)
mind_matter_api/utils/decorators.py (1)
  • require_auth (8-13)
mind_matter_api/repositories/campaigns.py (2)
  • get_survey_responses_count (41-42)
  • get_campaign_participation (44-45)
🪛 Ruff (0.11.9)
mind_matter_api/api/campaigns.py

1-1: flask.jsonify imported but unused

Remove unused import

(F401)


1-1: flask.request imported but unused

Remove unused import

(F401)


1-1: flask.current_app imported but unused

Remove unused import

(F401)


2-2: marshmallow.ValidationError imported but unused

Remove unused import: marshmallow.ValidationError

(F401)


5-5: mind_matter_api.utils.decorators.require_owner imported but unused

Remove unused import: mind_matter_api.utils.decorators.require_owner

(F401)


6-6: mind_matter_api.utils.auth.is_user_owner imported but unused

Remove unused import

(F401)


6-6: mind_matter_api.utils.auth.is_user_admin imported but unused

Remove unused import

(F401)

🔇 Additional comments (3)
mind_matter_api/api/__init__.py (1)

15-19: LGTM: Properly importing campaign-related modules.

The imports follow the application's convention and include all necessary modules for the campaign feature.

mind_matter_api/services/campaigns.py (1)

2-2: LGTM: Proper model import.

Correctly importing the required models.

mind_matter_api/repositories/campaigns.py (1)

2-3: LGTM: Proper imports.

Imports are correct and include all necessary models and base classes.

Comment on lines +41 to +42
def get_survey_responses_count(self, campaign_id: str) -> int:
return self.session.query(Campaign).filter(Campaign.campaign_id == campaign_id).count()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Implementation doesn't match the method's intent.

This method is supposed to count survey responses for a campaign, but it's actually counting campaign records filtered by ID, which will always return 0 or 1. This doesn't align with the PR objective of tracking survey response counts.

The implementation should likely count entries in a survey responses table that are associated with surveys in this campaign:

- def get_survey_responses_count(self, campaign_id: str) -> int:
-     return self.session.query(Campaign).filter(Campaign.campaign_id == campaign_id).count()
+ def get_survey_responses_count(self, campaign_id: int) -> int:
+     # Get the campaign
+     campaign = self.session.query(Campaign).get(campaign_id)
+     if not campaign:
+         return 0
+     # Count responses for all surveys in this campaign
+     from mind_matter_api.models.surveys import Survey, SurveyResponse
+     return self.session.query(SurveyResponse).\
+         join(Survey, SurveyResponse.survey_id == Survey.survey_id).\
+         join(campaign_surveys, Survey.survey_id == campaign_surveys.c.survey_id).\
+         filter(campaign_surveys.c.campaign_id == campaign_id).\
+         count()

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In mind_matter_api/repositories/campaigns.py around lines 41 to 42, the method
get_survey_responses_count incorrectly counts Campaign records instead of survey
responses. To fix this, update the query to count entries from the survey
responses table that are linked to surveys belonging to the specified
campaign_id, ensuring the count reflects actual survey responses associated with
that campaign.

Comment on lines +44 to +45
def get_campaign_participation(self, campaign_id: str) -> CampaignParticipation:
return self.session.query(CampaignParticipation).filter(CampaignParticipation.campaign_id == campaign_id).all()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Return type doesn't match the actual return value.

This method returns a list of CampaignParticipation objects with all(), but the return type is specified as a single CampaignParticipation object. Also, the campaign_id parameter is typed as str but used to filter an integer column.

- def get_campaign_participation(self, campaign_id: str) -> CampaignParticipation:
+ def get_campaign_participation(self, campaign_id: int) -> List[CampaignParticipation]:

Also, add the missing import:

+ from typing import List
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def get_campaign_participation(self, campaign_id: str) -> CampaignParticipation:
return self.session.query(CampaignParticipation).filter(CampaignParticipation.campaign_id == campaign_id).all()
# Add at the top of mind_matter_api/repositories/campaigns.py
from typing import List
def get_campaign_participation(self, campaign_id: int) -> List[CampaignParticipation]:
return self.session.query(CampaignParticipation) \
.filter(CampaignParticipation.campaign_id == campaign_id) \
.all()
🤖 Prompt for AI Agents
In mind_matter_api/repositories/campaigns.py around lines 44 to 45, the method
get_campaign_participation is declared to return a single CampaignParticipation
but actually returns a list due to using all(). Change the return type
annotation to List[CampaignParticipation] to match the returned list. Also,
update the campaign_id parameter type from str to int to match the integer
column used in the filter. Finally, add the missing import for List from typing
at the top of the file.

Comment on lines +24 to +27
@app.route('/campaigns/<int:campaign_id>/participation', methods=['GET'])
@require_auth
def get_campaign_participation(campaign_id):
return campaign_service.get_campaign_participation(campaign_id)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling and owner verification.

Similar to the previous endpoint, this one should verify user permissions and include error handling.

@app.route('/campaigns/<int:campaign_id>/participation', methods=['GET'])
@require_auth
def get_campaign_participation(campaign_id):
-    return campaign_service.get_campaign_participation(campaign_id)
+    try:
+        # Verify user has access to this campaign
+        user_campaigns = campaign_service.get_campaigns(user_id)
+        if not any(c.campaign_id == campaign_id for c in user_campaigns):
+            return jsonify({"error": "Access denied"}), 403
+            
+        participations = campaign_service.get_campaign_participation(campaign_id)
+        return jsonify(participations)
+    except Exception as e:
+        logging.error(f"Error retrieving campaign participation: {str(e)}")
+        return jsonify({"error": "Failed to retrieve campaign participation"}), 500

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In mind_matter_api/api/campaigns.py around lines 24 to 27, the
get_campaign_participation endpoint lacks error handling and user permission
verification. Update the function to check if the authenticated user is the
owner of the campaign before proceeding. Add try-except blocks to handle
potential errors from the service call and return appropriate error responses.

Comment on lines +19 to +23
@app.route('/campaigns/<int:campaign_id>/survey-responses-count', methods=['GET'])
@require_auth
def get_survey_responses_count(campaign_id):
return campaign_service.get_survey_responses_count(campaign_id)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling and owner verification.

This endpoint should verify that the user has permission to view the campaign data and include error handling.

@app.route('/campaigns/<int:campaign_id>/survey-responses-count', methods=['GET'])
@require_auth
def get_survey_responses_count(campaign_id):
-    return campaign_service.get_survey_responses_count(campaign_id)
+    try:
+        # Verify user has access to this campaign
+        user_campaigns = campaign_service.get_campaigns(user_id)
+        if not any(c.campaign_id == campaign_id for c in user_campaigns):
+            return jsonify({"error": "Access denied"}), 403
+            
+        count = campaign_service.get_survey_responses_count(campaign_id)
+        return jsonify({"survey_responses_count": count})
+    except Exception as e:
+        logging.error(f"Error retrieving survey responses count: {str(e)}")
+        return jsonify({"error": "Failed to retrieve survey responses count"}), 500

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In mind_matter_api/api/campaigns.py around lines 19 to 23, the
get_survey_responses_count endpoint lacks error handling and does not verify if
the requesting user owns or has permission to access the campaign data. Add a
check to confirm the authenticated user's ownership or permission for the
campaign before returning the count. Also, wrap the service call in a try-except
block to handle potential errors gracefully, returning appropriate HTTP error
responses when permission is denied or other exceptions occur.

Comment on lines +14 to +18
@app.route('/campaigns', methods=['GET'])
@require_auth
def get_campaigns(user_id):
return campaign_service.get_campaigns(user_id)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling and response formatting.

The endpoint lacks error handling and proper response formatting. If get_campaigns fails or returns None, it could result in a 500 error.

@app.route('/campaigns', methods=['GET'])
@require_auth
def get_campaigns(user_id):
-    return campaign_service.get_campaigns(user_id)
+    try:
+        campaigns = campaign_service.get_campaigns(user_id)
+        return jsonify(campaigns)
+    except Exception as e:
+        logging.error(f"Error retrieving campaigns: {str(e)}")
+        return jsonify({"error": "Failed to retrieve campaigns"}), 500
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@app.route('/campaigns', methods=['GET'])
@require_auth
def get_campaigns(user_id):
return campaign_service.get_campaigns(user_id)
@app.route('/campaigns', methods=['GET'])
@require_auth
def get_campaigns(user_id):
try:
campaigns = campaign_service.get_campaigns(user_id)
return jsonify(campaigns)
except Exception as e:
logging.error(f"Error retrieving campaigns: {str(e)}")
return jsonify({"error": "Failed to retrieve campaigns"}), 500
🤖 Prompt for AI Agents
In mind_matter_api/api/campaigns.py around lines 14 to 18, the get_campaigns
endpoint lacks error handling and response formatting. Modify the function to
catch exceptions from campaign_service.get_campaigns and return a proper JSON
response with an appropriate HTTP status code. Also, handle the case where
get_campaigns returns None by returning a 404 or an empty list with a 200
status, ensuring the endpoint never returns an unhandled 500 error.

@rubybui rubybui merged commit b68167f into main May 21, 2025
1 check was pending
@rubybui
Copy link
Owner Author

rubybui commented May 22, 2025

#10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants