Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFERENCE] feat: introduce Gateway Aggregation / Backend-for-Frontend abstraction via LearnerPortalBFFAPIView #572

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

adamstankiewicz
Copy link
Member

@adamstankiewicz adamstankiewicz commented Oct 9, 2024

Description

[Context] Tech Spec

This PR introduces the LearnerPortalBFFAPIView as part of a new Gateway Aggregation / Backend-for-Frontend (BFF) abstraction. This new view aims to simplify the interaction between the frontend and multiple backend services, enhancing the overall architecture and making it easier to manage and extend.

Key features

  • Gateway Aggregation: Centralizes multiple backend service calls into a single endpoint, reducing the complexity and number of network requests required by the frontend.
  • Backend-for-Frontend (BFF) Abstraction: Provides a tailored API specifically designed to meet the needs of the frontend, improving performance and developer experience.

High-level overview

  • The LearnerPortalBFFAPIView exposes a POST API endpoint with a dynamic page_route route parameter.
  • It creates a HandlerContext, passing the originating request and page_route as attributes. The HandlerContext is responsible for keeping a shared data structure that the route handlers can mutate while loading/processing data. It also exposes an add_error helper method for route handlers to use to aggregate errors. This shared context is passed to the appropriate route-specific handler (e.g., DashboardHandler). The route handler's implemented load_and_process method is called, which mutates the shared context for the route handler.
  • It also gets the appropriate response builder class (e.g., LearnerDashboardResponseBuilder), which exposes a .build() method called, extracting the pertinent metadata from the shared context object to return in the response. This is a clean separation of concerns between loading/processing dependent data vs. creating the desired response structure.
  • The resulting response data is returned in a Response.

Jira

ENT-9427

Merge checklist:

  • ./manage.py makemigrations has been run
    • Note: This must be run if you modified any models.
      • It may or may not make a migration depending on exactly what you modified, but it should still be run.

Post merge:

  • Ensure that your changes went out to the stage instance
  • Deploy to prod instance

@adamstankiewicz adamstankiewicz changed the title feat: introduce Gateway Aggregation / Backend-for-Frontend abstraction via LearnerPortalBFFAPIView [REFERENCE] feat: introduce Gateway Aggregation / Backend-for-Frontend abstraction via LearnerPortalBFFAPIView Oct 9, 2024
@adamstankiewicz adamstankiewicz force-pushed the ags/poc-learner-portal-bff branch 2 times, most recently from fcb96e8 to 023a9d7 Compare October 9, 2024 20:04
Comment on lines +8 to +16
def get_request_id():
"""
Helper to get the request id - usually set via an X-Request-ID header
"""
request = crum.get_current_request()
if request is not None and request.headers is not None:
return request.headers.get('X-Request-ID')
else:
return None
Copy link
Member Author

Choose a reason for hiding this comment

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

[inform] Replicated from here

@adamstankiewicz adamstankiewicz force-pushed the ags/poc-learner-portal-bff branch from 023a9d7 to 4dabe51 Compare October 9, 2024 21:24
Comment on lines +135 to +144
{
'uuid': subscription_license.get('uuid'),
'status': subscription_license.get('status'),
'user_email': subscription_license.get('user_email'),
'activation_date': subscription_license.get('activation_date'),
'last_remind_date': subscription_license.get('last_remind_date'),
'revoked_date': subscription_license.get('revoked_date'),
'activation_key': subscription_license.get('activation_key'),
'subscription_plan': subscription_license.get('subscription_plan', {}),
}
Copy link
Member Author

Choose a reason for hiding this comment

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

[inform] Extract only the fields the frontend really needs.

and customer_agreement.get('net_days_until_expiration') > 0
)
idp_or_univeral_link_enabled = (
# TODO: IDP from customer
Copy link
Member Author

Choose a reason for hiding this comment

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

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.

1 participant