Skip to content

[History] Implement "History of Viewed Startups" Functionality #87

Description

@mehalyna

User Story:

As an investor
I want to see a list of the startups I recently viewed
So that I can easily go back to startups I am considering without needing to search for them again.

The goal is to create a simple feature that tracks the last few startups an investor has viewed. This feature will allow investors to quickly access recently viewed startups and also give them the option to clear their viewing history.


Steps:

1. Database Setup: Create a Model to Track Viewed Startups

  • Create a ViewedStartup model to log each time an investor views a startup.
  • Fields for the model:
    • user (ForeignKey to the User model, only for users with the role of "investor")
    • startup (ForeignKey to the Startup model)
    • viewed_at (DateTimeField to record when the startup was viewed)
  • Constraints:
    • Ensure that each record is unique for a combination of user and startup.
  • Order the records by viewed_at in descending order to track the most recent views.

2. API Endpoints: Create Endpoints for Viewing and Clearing History

  • Endpoint 1: GET /api/v1/startups/viewed:
    • Functionality: Retrieve a list of recently viewed startups for the authenticated investor.
    • Parameters:
      • Pagination support (optional, to limit results per page)
      • Optional limit on the number of items returned (e.g., last 10 viewed startups).
    • Response: Return a serialized list of viewed startups, including basic details such as startup_id, company_name, and viewed_at.
  • Endpoint 2: POST /api/v1/startups/view/{startup_id}:
    • Functionality: Log that a specific startup was viewed by the investor.
    • Parameters:
      • startup_id (UUID or ID of the startup being viewed)
    • Response: A success message confirming the record was added.
  • Endpoint 3: DELETE /api/v1/startups/viewed/clear:
    • Functionality: Allow the investor to clear their viewed startups history.
    • Response: A success message confirming the history was cleared.

3. View Logic: Track Viewed Startups in Views

  • In the StartupViewSet or relevant views where a startup profile is retrieved:
    • On retrieval of a startup profile, log the view by calling the POST /api/v1/startups/view/{startup_id} endpoint.
    • Use signals (optional) to automatically track views when the retrieve method is called.

4. Permissions: Ensure Access Control for Investor Users

  • Only allow users with the "investor" role to access the viewing history.
  • Add appropriate permission checks in the endpoints to ensure only authenticated investors can view or modify the history.

5. Frontend Integration: Update UI to Display and Clear History (Optional)

  • Display History:
    • On the investor's dashboard or profile page, add a "Recently Viewed Startups" section.
    • Fetch data from the GET /api/v1/startups/viewed endpoint and display the recently viewed startups in a simple list.
  • Clear History:
    • Add a "Clear History" button in the "Recently Viewed Startups" section.
    • On clicking "Clear History," send a request to the DELETE /api/v1/startups/viewed/clear endpoint.

6. Testing:

  • Write unit tests for the new model to ensure the unique constraint works.
  • Write tests for each endpoint:
    • Test that recently viewed startups are recorded correctly.
    • Test that the list of recently viewed startups is retrieved correctly.
    • Test that the history can be cleared.
    • Test permissions to ensure only investors can access these endpoints.

7. Documentation:

  • Update the API documentation to include the new endpoints.
  • Provide example requests and responses for viewing and clearing history.

Acceptance Criteria:

  • Investors can view a list of recently viewed startups.
  • Each view of a startup by an investor is recorded.
  • Investors can clear their viewed history.
  • Only investors have access to the viewing history functionality.
  • API is fully documented, and endpoints are tested.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions