fix: user page not found (#3736)

#### What type of PR is this?
/kind bug
/area core

#### What this PR does / why we need it:
修复作者页无法访问的问题

#### Which issue(s) this PR fixes:
Fixes #3718

#### Does this PR introduce a user-facing change?
```release-note
修复作者页无法访问的问题
```
pull/3740/head
guqing 2023-04-14 16:12:47 +08:00 committed by GitHub
parent d7bfbef149
commit d1651aa671
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 2 deletions

View File

@ -127,6 +127,7 @@ public class ThemeCompositeRouterFunction implements RouterFunction<ServerRespon
// Add the index route to the end to prevent conflict with the queryParam rule of the post // Add the index route to the end to prevent conflict with the queryParam rule of the post
routePatterns.add(new RoutePattern(DefaultTemplateEnum.INDEX, "/")); routePatterns.add(new RoutePattern(DefaultTemplateEnum.INDEX, "/"));
routePatterns.add(new RoutePattern(DefaultTemplateEnum.AUTHOR, ""));
return routePatterns; return routePatterns;
} }
} }

View File

@ -18,6 +18,7 @@ import run.halo.app.core.extension.User;
import run.halo.app.extension.ReactiveExtensionClient; import run.halo.app.extension.ReactiveExtensionClient;
import run.halo.app.infra.SystemConfigurableEnvironmentFetcher; import run.halo.app.infra.SystemConfigurableEnvironmentFetcher;
import run.halo.app.infra.SystemSetting; import run.halo.app.infra.SystemSetting;
import run.halo.app.infra.exception.NotFoundException;
import run.halo.app.theme.DefaultTemplateEnum; import run.halo.app.theme.DefaultTemplateEnum;
import run.halo.app.theme.finders.PostFinder; import run.halo.app.theme.finders.PostFinder;
import run.halo.app.theme.finders.vo.ListedPostVo; import run.halo.app.theme.finders.vo.ListedPostVo;
@ -73,7 +74,8 @@ public class AuthorPostsRouteFactory implements RouteFactory {
} }
private Mono<UserVo> getByName(String name) { private Mono<UserVo> getByName(String name) {
return client.get(User.class, name) return client.fetch(User.class, name)
.switchIfEmpty(Mono.error(() -> new NotFoundException("Author page not found.")))
.map(UserVo::from); .map(UserVo::from);
} }
} }

View File

@ -33,7 +33,7 @@ class AuthorPostsRouteFactoryTest extends RouteFactoryTestSuite {
RouterFunction<ServerResponse> routerFunction = authorPostsRouteFactory.create(null); RouterFunction<ServerResponse> routerFunction = authorPostsRouteFactory.create(null);
WebTestClient webClient = getWebTestClient(routerFunction); WebTestClient webClient = getWebTestClient(routerFunction);
when(client.get(eq(User.class), eq("fake-user"))) when(client.fetch(eq(User.class), eq("fake-user")))
.thenReturn(Mono.just(new User())); .thenReturn(Mono.just(new User()));
webClient.get() webClient.get()
.uri("/authors/fake-user") .uri("/authors/fake-user")