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

front controller path/routing adjustment #687

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions config/kbin_routes/domain.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
domain_entries:
controller: App\Controller\Domain\DomainFrontController
defaults: { sortBy: hot, time: '∞', type: ~ }
path: /d/{name}/{sortBy}/{time}/{type}
defaults: { sortBy: hot, time: '∞'}
path: /d/{name}/{sortBy}/{time}
methods: [ GET ]
requirements:
sortBy: "%default_sort_options%"
time: "%default_time_options%"
type: "%default_type_options%"

domain_comments:
controller: App\Controller\Domain\DomainCommentFrontController
Expand Down
77 changes: 43 additions & 34 deletions config/kbin_routes/front.yaml
Original file line number Diff line number Diff line change
@@ -1,85 +1,94 @@
front:
controller: App\Controller\Entry\EntryFrontController::front
defaults: { subscription: home, sortBy: hot, time: '∞', type: all, federation: all, content: threads }
path: /{subscription}/{sortBy}/{time}/{type}/{federation}/{content}
defaults: &front_defaults { subscription: home, content: threads, sortBy: hot, time: '∞', federation: all }
path: /{subscription}/{content}/{sortBy}/{time}/{federation}
methods: [GET]
requirements:
requirements: &front_requirement
subscription: "%default_subscription_options%"
sortBy: "%default_sort_options%"
time: "%default_time_options%"
type: "%default_type_options%"
federation: "%default_federation_options%"
content: "%default_content_options%"

front_redirect:
controller: App\Controller\Entry\EntryFrontController::front_redirect
defaults: { sortBy: hot, time: '∞', type: all, federation: all, content: threads }
path: /{sortBy}/{time}/{type}/{federation}/{content}
front_sub:
controller: App\Controller\Entry\EntryFrontController::front
defaults: *front_defaults
path: /{subscription}/{sortBy}/{time}/{federation}
methods: [GET]
requirements:
sortBy: "%default_sort_options%"
time: "%default_time_options%"
type: "%default_type_options%"
federation: "%default_federation_options%"
content: "%default_content_options%"
requirements: *front_requirement
Copy link
Member

Choose a reason for hiding this comment

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

I appreciate how you find these things that can be refactored into less copy paste

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thankfully this is one of the simpler ones, yaml anchors can be quite confusing at time, especially when you also add merge keys to the mix

technically this could go a step further by using merge keys referencing first full front route definition then overwrite path with different routes (iirc the old front routing before ui filter patch actually does this)


front_content:
controller: App\Controller\Entry\EntryFrontController::front
defaults: *front_defaults
path: /{content}/{sortBy}/{time}/{federation}
methods: [GET]
requirements: *front_requirement

front_short:
controller: App\Controller\Entry\EntryFrontController::front
defaults: *front_defaults
path: /{sortBy}/{time}/{federation}
methods: [GET]
requirements: *front_requirement

front_magazine:
controller: App\Controller\Entry\EntryFrontController::magazine
defaults: { sortBy: hot, time: '∞', type: all, federation: all, content: threads }
path: /m/{name}/{sortBy}/{time}/{type}/{federation}/{content}
defaults: &front_magazine_defaults { content: threads, sortBy: hot, time: '∞', federation: all }
path: /m/{name}/{content}/{sortBy}/{time}/{federation}
methods: [GET]
requirements:
sortBy: "%default_sort_options%"
time: "%default_time_options%"
type: "%default_type_options%"
federation: "%default_federation_options%"
content: "%default_content_options%"
requirements: *front_requirement

front_magazine_short:
controller: App\Controller\Entry\EntryFrontController::magazine
defaults: &front_magazine_defaults
path: /m/{name}/{sortBy}/{time}/{federation}
methods: [GET]
requirements: *front_requirement

# Microblog compatibility stuff, redirects from the old routes' URLs

posts_front:
controller: App\Controller\Entry\EntryFrontController::front_redirect
defaults: { sortBy: hot, time: '∞', type: all, federation: all, content: microblog }
controller: App\Controller\Entry\EntryFrontController::frontRedirect
defaults: { sortBy: hot, time: '∞', federation: all, content: microblog }
path: /microblog/{sortBy}/{time}
methods: [ GET ]
requirements:
sortBy: "%default_sort_options%"
time: "%default_time_options%"

posts_subscribed:
controller: App\Controller\Entry\EntryFrontController::front_redirect
defaults: { sortBy: hot, time: '∞', type: all, federation: all, content: microblog, subscription: 'sub' }
controller: App\Controller\Entry\EntryFrontController::frontRedirect
defaults: { sortBy: hot, time: '∞', federation: all, content: microblog, subscription: 'sub' }
path: /sub/microblog/{sortBy}/{time}
methods: [ GET ]
requirements:
sortBy: "%default_sort_options%"
time: "%default_time_options%"

posts_moderated:
controller: App\Controller\Entry\EntryFrontController::front_redirect
defaults: { sortBy: hot, time: '∞', type: all, federation: all, content: microblog, subscription: 'mod' }
controller: App\Controller\Entry\EntryFrontController::frontRedirect
defaults: { sortBy: hot, time: '∞', federation: all, content: microblog, subscription: 'mod' }
path: /mod/microblog/{sortBy}/{time}
methods: [ GET ]
requirements:
sortBy: "%default_sort_options%"
time: "%default_time_options%"

posts_favourite:
controller: App\Controller\Entry\EntryFrontController::front_redirect
defaults: { sortBy: hot, time: '∞', type: all, federation: all, content: microblog, subscription: 'fav' }
controller: App\Controller\Entry\EntryFrontController::frontRedirect
defaults: { sortBy: hot, time: '∞', federation: all, content: microblog, subscription: 'fav' }
path: /fav/microblog/{sortBy}/{time}
methods: [ GET ]
requirements:
sortBy: "%default_sort_options%"
time: "%default_time_options%"

magazine_posts:
controller: App\Controller\Entry\EntryFrontController::front_redirect
defaults: { sortBy: hot, time: '∞', type: all, federation: all, content: microblog }
path: /m/{name}/microblog/{sortBy}/{time}/{type}/{federation}
controller: App\Controller\Entry\EntryFrontController::magazineRedirect
defaults: { sortBy: hot, time: '∞', federation: all, content: microblog }
path: /m/{name}/microblog/{sortBy}/{time}/{federation}
methods: [ GET ]
requirements:
sortBy: "%default_sort_options%"
time: "%default_time_options%"
type: "%default_type_options%"
federation: "%default_federation_options%"
11 changes: 9 additions & 2 deletions src/Controller/Domain/DomainFrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;

class DomainFrontController extends AbstractController
{
Expand All @@ -22,8 +23,14 @@ public function __construct(
) {
}

public function __invoke(?string $name, ?string $sortBy, ?string $time, ?string $type, Request $request): Response
{
public function __invoke(
?string $name,
?string $sortBy,
?string $time,
#[MapQueryParameter]
?string $type,
Request $request
): Response {
if (!$domain = $this->domainRepository->findOneBy(['name' => $name])) {
throw $this->createNotFoundException();
}
Expand Down
Loading
Loading