From 33b87312f4418b056f48db40c00fa3df075f3a19 Mon Sep 17 00:00:00 2001 From: Athou Date: Sat, 13 Aug 2022 17:41:31 +0200 Subject: [PATCH] redirect to new feed after subscribe --- commafeed-client/src/app/client.ts | 2 +- .../src/components/content/add/Subscribe.tsx | 6 +++--- .../backend/service/FeedSubscriptionService.java | 8 ++++---- .../com/commafeed/frontend/resource/FeedREST.java | 4 ++-- .../java/com/commafeed/integration/FeedIT.java | 15 +++------------ 5 files changed, 13 insertions(+), 22 deletions(-) diff --git a/commafeed-client/src/app/client.ts b/commafeed-client/src/app/client.ts index 6366472e..a59b5bc9 100644 --- a/commafeed-client/src/app/client.ts +++ b/commafeed-client/src/app/client.ts @@ -50,7 +50,7 @@ export const client = { getEntries: (req: GetEntriesPaginatedRequest) => axiosInstance.get("feed/entries", { params: req }), markEntries: (req: MarkRequest) => axiosInstance.post("feed/mark", req), fetchFeed: (req: FeedInfoRequest) => axiosInstance.post("feed/fetch", req), - subscribe: (req: SubscribeRequest) => axiosInstance.post("feed/subscribe", req), + subscribe: (req: SubscribeRequest) => axiosInstance.post("feed/subscribe", req), unsubscribe: (req: IDRequest) => axiosInstance.post("feed/unsubscribe", req), importOpml: (req: File) => { const formData = new FormData() diff --git a/commafeed-client/src/components/content/add/Subscribe.tsx b/commafeed-client/src/components/content/add/Subscribe.tsx index ba651f66..b8bac67b 100644 --- a/commafeed-client/src/components/content/add/Subscribe.tsx +++ b/commafeed-client/src/components/content/add/Subscribe.tsx @@ -3,7 +3,7 @@ import { Box, Button, Group, Stack, Stepper, TextInput } from "@mantine/core" import { useForm } from "@mantine/form" import { client, errorsToStrings, errorToStrings } from "app/client" import { Constants } from "app/constants" -import { redirectToSelectedSource } from "app/slices/redirect" +import { redirectToFeed, redirectToSelectedSource } from "app/slices/redirect" import { reloadTree } from "app/slices/tree" import { useAppDispatch } from "app/store" import { FeedInfoRequest, SubscribeRequest } from "app/types" @@ -39,9 +39,9 @@ export function Subscribe() { }, }) const [subscribe, subscribeResult] = useMutation(client.feed.subscribe, { - onSuccess: () => { + onSuccess: sub => { dispatch(reloadTree()) - dispatch(redirectToSelectedSource()) + dispatch(redirectToFeed(sub.data.data.id)) }, }) const errors = errorsToStrings([fetchFeedResult.error, errorToStrings(subscribeResult.error)]) diff --git a/commafeed-server/src/main/java/com/commafeed/backend/service/FeedSubscriptionService.java b/commafeed-server/src/main/java/com/commafeed/backend/service/FeedSubscriptionService.java index 90454db5..8fb1d07c 100644 --- a/commafeed-server/src/main/java/com/commafeed/backend/service/FeedSubscriptionService.java +++ b/commafeed-server/src/main/java/com/commafeed/backend/service/FeedSubscriptionService.java @@ -39,15 +39,15 @@ public class FeedSubscriptionService { private final CacheService cache; private final CommaFeedConfiguration config; - public Feed subscribe(User user, String url, String title) { + public FeedSubscription subscribe(User user, String url, String title) { return subscribe(user, url, title, null, 0); } - public Feed subscribe(User user, String url, String title, FeedCategory parent) { + public FeedSubscription subscribe(User user, String url, String title, FeedCategory parent) { return subscribe(user, url, title, parent, 0); } - public Feed subscribe(User user, String url, String title, FeedCategory category, int position) { + public FeedSubscription subscribe(User user, String url, String title, FeedCategory category, int position) { final String pubUrl = config.getApplicationSettings().getPublicUrl(); if (StringUtils.isBlank(pubUrl)) { @@ -78,7 +78,7 @@ public class FeedSubscriptionService { queues.add(feed, false); cache.invalidateUserRootCategory(user); - return feed; + return sub; } public boolean unsubscribe(User user, Long subId) { diff --git a/commafeed-server/src/main/java/com/commafeed/frontend/resource/FeedREST.java b/commafeed-server/src/main/java/com/commafeed/frontend/resource/FeedREST.java index 1ab77114..f3633b1e 100644 --- a/commafeed-server/src/main/java/com/commafeed/frontend/resource/FeedREST.java +++ b/commafeed-server/src/main/java/com/commafeed/frontend/resource/FeedREST.java @@ -399,12 +399,12 @@ public class FeedREST { category = feedCategoryDAO.findById(Long.valueOf(req.getCategoryId())); } FeedInfo info = fetchFeedInternal(url); - feedSubscriptionService.subscribe(user, info.getUrl(), req.getTitle(), category); + FeedSubscription subscription = feedSubscriptionService.subscribe(user, info.getUrl(), req.getTitle(), category); + return Response.ok(subscription).build(); } catch (Exception e) { log.error("Failed to subscribe to URL {}: {}", url, e.getMessage(), e); return Response.status(Status.SERVICE_UNAVAILABLE).entity("Failed to subscribe to URL " + url + ": " + e.getMessage()).build(); } - return Response.ok().build(); } @GET diff --git a/commafeed-server/src/test/java/com/commafeed/integration/FeedIT.java b/commafeed-server/src/test/java/com/commafeed/integration/FeedIT.java index da232124..6ae8ff42 100644 --- a/commafeed-server/src/test/java/com/commafeed/integration/FeedIT.java +++ b/commafeed-server/src/test/java/com/commafeed/integration/FeedIT.java @@ -24,7 +24,6 @@ import org.mockserver.model.HttpResponse; import com.commafeed.CommaFeedApplication; import com.commafeed.CommaFeedConfiguration; -import com.commafeed.frontend.model.Category; import com.commafeed.frontend.model.Entries; import com.commafeed.frontend.model.Subscription; import com.commafeed.frontend.model.request.SubscribeRequest; @@ -62,15 +61,14 @@ class FeedIT { String feedUrl = "http://localhost:" + this.mockServerClient.getPort(); - subscribe(client, feedUrl); - Subscription subscription = getSubscription(client, feedUrl); + Subscription subscription = subscribe(client, feedUrl); Awaitility.await() .atMost(Duration.ofSeconds(15)) .pollInterval(Duration.ofMillis(500)) .until(() -> getFeedEntries(client, subscription), e -> e.getEntries().size() == 2); } - private void subscribe(Client client, String feedUrl) { + private Subscription subscribe(Client client, String feedUrl) { SubscribeRequest subscribeRequest = new SubscribeRequest(); subscribeRequest.setUrl(feedUrl); subscribeRequest.setTitle("my title for this feed"); @@ -78,14 +76,7 @@ class FeedIT { .request() .post(Entity.json(subscribeRequest)); Assertions.assertEquals(HttpStatus.OK_200, response.getStatus()); - } - - private Subscription getSubscription(Client client, String feedUrl) { - Response response = client.target(String.format("http://localhost:%d/rest/category/get", EXT.getLocalPort())).request().get(); - Category category = response.readEntity(Category.class); - Subscription subscription = category.getFeeds().stream().findFirst().orElse(null); - Assertions.assertNotNull(subscription); - return subscription; + return response.readEntity(Subscription.class); } private Entries getFeedEntries(Client client, Subscription subscription) {