Skip to content

Commit

Permalink
front controller path/routing adjustment (#687)
Browse files Browse the repository at this point in the history
the new filter ui changes also introduces a couple more filtering
parameters in the form of controller path params, for threads/entries
listing it looks fine and relatively staightforward, but for microblog
posts listing, what used to be a simple `/microblog` is now something
like `/all/hot/∞/all/all/microblog`, which hinders the user experience
on url readability and memorability compared to the previous scheme, for
those who still care

this changes tries to adjust the path/routing of these front controller
especially for the microblog part, to make it more simpler and could
omit some default filter parameters if they aren't set, similar to the
previous path scheme

Co-authored-by: e-five <146029455+e-five256@users.noreply.github.com>
  • Loading branch information
asdfzdfj and e-five256 committed May 15, 2024
1 parent 0ca9585 commit 5431dc3
Show file tree
Hide file tree
Showing 12 changed files with 313 additions and 164 deletions.
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

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

0 comments on commit 5431dc3

Please sign in to comment.