Skip to content
This repository has been archived by the owner on Oct 16, 2023. It is now read-only.

Feature: create simple routing api and replace existing routes #111

Merged
merged 3 commits into from
Jan 10, 2023

Conversation

jonwaldstein
Copy link
Contributor

@jonwaldstein jonwaldstein commented Jan 9, 2023

Description

This introduces a basic routing api and replaces existing Next Gen form routes with the givewp-route param.

It's purpose is to clean up how we're handling our custom query param based routing so it's easier to create and understand them.

When declaring a route, the uri will turn into /?givewp-route=$uri.

Example:

Get route url

Route::url('donate') // http://{givewp.com}/?givewp-route=donate

Simple GET route using invokable class

Route::get('donation-form-view', InvokableDonationFormViewController::class);

This will call give(InvokableDonationFormViewController::class)->__invoke(array $request);

GET Route using callable

Route::get('donation-form-view', static function (array $request) {
    $routeData = DonationFormViewRouteData::fromRequest($request);

    return give(DonationFormViewController::class)->show($routeData);
});

POST Route using callable

Route::post('donation-form-view-preview', static function (array $request) {
  $routeData = DonationFormPreviewRouteData::fromRequest($request);

  return give(DonationFormViewController::class)->preview($routeData);
});

Affects

This does technically touch all the working Next Gen routes for viewing, previewing, and donating.

Visuals

N/A

Testing Instructions

Just make sure viewing, previewing, and donating a next gen form still works properly.

Pre-review Checklist

  • Acceptance criteria satisfied and marked in related issue
  • Relevant @unreleased tags included in DocBlocks
  • Includes unit tests
  • Reviewed by the designer (if follows a design)
  • Self Review of code and UX completed

@jonwaldstein jonwaldstein marked this pull request as ready for review January 9, 2023 23:16
@jonwaldstein jonwaldstein requested a review from kjohnson January 9, 2023 23:17
@jonwaldstein
Copy link
Contributor Author

@kjohnson this is ready for review. It's not meant to be full-featured, just useful enough for our use cases and we can expand later if need be. I'll be using this for the new receipt routing.

Copy link
Contributor

@kjohnson kjohnson left a comment

Choose a reason for hiding this comment

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

This looks great. Nice to see a Route::get() syntax that is clean and easy to reason about.

/**
* @unreleased
*/
Route::post('donation-form-view-preview', static function (array $request) {
Copy link
Contributor

Choose a reason for hiding this comment

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

These inline routes are beautiful.

Copy link
Contributor Author

@jonwaldstein jonwaldstein Jan 10, 2023

Choose a reason for hiding this comment

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

I know right?! It's a start lol

@jonwaldstein jonwaldstein merged commit ebba953 into develop Jan 10, 2023
@jonwaldstein jonwaldstein deleted the feature/route-api branch January 10, 2023 19:47
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.

2 participants