PublicDataWorks / verdad-frontend

MIT License
0 stars 0 forks source link

[Backend] Implement APIs for `upvote-label` Feature #4

Closed linear[bot] closed 5 hours ago

linear[bot] commented 5 hours ago

Implement the backend APIs required to support the upvote-label feature. This includes creating endpoints to retrieve snippet labels, upvote labels, undo label upvotes, and create/apply/upvote new labels. These APIs will facilitate user interactions with labels on detected snippets, including fetching label details, upvoting, and applying new labels.

Requirements:

  1. API Endpoints:

    • get_snippet_labels(snippet_id)

      • Functionality: Retrieve all labels applied to a given snippet along with their metadata.
      • Response Example:
      {
         "snippet_id": "56a54414-c8a0-4442-8985-6a516418a084",
         "labels": [
             {
                 "id": "210abb90-79c7-4286-a935-4b851a7e3bda",
                 "text": "Healthcare Reform",
                 "applied_at": "2024-10-18T18:18:33.3581+00:00",
                 "applied_by": null,
                 "created_by": null,
                 "upvoted_by": [
                     {
                         "id": "d41b5267-d2ae-4da0-bdb5-329457680868",
                         "email": "dat.h.tran@stanyangroup.com",
                         "upvoted_at": "2024-10-19T12:34:48.280939+00:00"
                     }
                 ],
                 "is_ai_suggested": true
             }
         ]
      }
    • upvote_label(snippet_id, label_text)
      • Functionality: Upvote a label with the specified text for a given snippet.
      • Response: Same as get_snippet_labels() response.
    • undo_upvote_label(snippet_id, label_text)
      • Functionality: Reverse the upvote action for a specified label.
      • Response: Same as get_snippet_labels() response.
    • create_apply_and_upvote_label(snippet_id, label_text)
      • Functionality: Create a new label, apply it to the snippet, and upvote it.
      • Response: Same as get_snippet_labels() response.
  2. Implementation Details:
    • Use Supabase RPC functions for implementing these APIs.
    • Ensure inclusion of access token in requests for user authentication.
    • Implement error handling for scenarios like invalid snippet IDs or label texts.
  3. Code Examples:

    def get_snippet_labels(self, snippet_id):
       result = self.client.rpc('get_snippet_labels', {'snippet_id': snippet_id}).execute()
       return result.data
    def upvote_label(self, snippet_id, label_text):
       result = self.client.rpc('upvote_label', {'snippet_id': snippet_id, 'label_text': label_text}).execute()
       return result.data
    def undo_upvote_label(self, snippet_id, label_text):
       result = self.client.rpc('undo_upvote_label', {'snippet_id': snippet_id, 'label_text': label_text}).execute()
       return result.data
    def create_apply_and_upvote_label(self, snippet_id, label_text):
       result = self.client.rpc('create_apply_and_upvote_label', {'snippet_id': snippet_id, 'label_text': label_text}).execute()
       return result.data
    def get_all_labels(self):
       result = self.client.table("labels").select("*").execute()
       return result.data
  4. Testing:
    • Ensure each API endpoint is tested for successful execution and error handling.
    • Validate responses against example outputs.
  5. Notes:
    • Fetch all available labels using Supabase select function for autocomplete features.
    • Ensure API documentation is updated to reflect these new endpoints and their usage.

Acceptance Criteria:

linear[bot] commented 5 hours ago

VER-65 [Backend] Implement APIs for `upvote-label` Feature