Skip to content

refactor: Break out endpoint's business logic - #2676

Merged
hampuslavin merged 30 commits into
serverpod:mainfrom
hampuslavin:hl_test_framework_part1
Aug 30, 2024
Merged

hampuslavin merged 30 commits into
serverpod:mainfrom
hampuslavin:hl_test_framework_part1

Conversation

@hampuslavin

@hampuslavin hampuslavin commented Aug 27, 2024 •

Copy link
Copy Markdown
Contributor

Description

  • This PR attempts to break out the business logic from the three different entry points into an Endpoint:
    • standard method
    • new streaming method
    • old handleStreamMessage method (to-be deprecated at some point)
  • Business logic is defined here as: all logic that is not related to the transport layer

Changes

  • Breaks out the following business logic into a single place:
    • input parameter validation
    • retrieving the endpoint
    • retrieving the endpoint method
    • checking if the user is authorized

Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

@hampuslavin
hampuslavin force-pushed the hl_test_framework_part1 branch from 46b6267 to 7c85c9f Compare August 27, 2024 12:40
@hampuslavin
hampuslavin marked this pull request as ready for review August 27, 2024 13:36

@Isakdl Isakdl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Always nice to break things out! :) Very nice improvements for the code base.
I have a few thoughts and comments.

@SandPod SandPod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A couple of comments and questions.
Overall, it looks good!

Leaving the session logging thoughts to Isak since he has been reworking that a bit.

@hampuslavin
hampuslavin force-pushed the hl_test_framework_part1 branch from ab90839 to 5aa316c Compare August 28, 2024 09:09
@hampuslavin
hampuslavin force-pushed the hl_test_framework_part1 branch from 5aa316c to dd04aa9 Compare August 28, 2024 09:10
@hampuslavin hampuslavin mentioned this pull request Aug 28, 2024
4 of 6 tasks

@SandPod SandPod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A couple of additional comments.

Most importantly we need to remember to close the session in all cases if a call fails.

The idea is that these should be able to validate an arbitrary amount of things and own all business logic for endpoints. Therefore it is clearer and more future proof to be intentionally opaque. Together with the new return type `MethodCallContext`, it should be clear to the user of this function what the intent is.
@hampuslavin
hampuslavin force-pushed the hl_test_framework_part1 branch from e2874a9 to 0644420 Compare August 29, 2024 14:36

@SandPod SandPod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One last critical thing around the session.

@SandPod SandPod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

Left two minor non blocking NIT suggestions you are free to discard if you don't agree with them.

@hampuslavin
hampuslavin merged commit dd1258c into serverpod:main Aug 30, 2024
@hampuslavin
hampuslavin deleted the hl_test_framework_part1 branch August 30, 2024 11:31
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants