forked from Archives/Athou_commafeed
redirect to new feed after subscribe
This commit is contained in:
@@ -50,7 +50,7 @@ export const client = {
|
||||
getEntries: (req: GetEntriesPaginatedRequest) => axiosInstance.get<Entries>("feed/entries", { params: req }),
|
||||
markEntries: (req: MarkRequest) => axiosInstance.post("feed/mark", req),
|
||||
fetchFeed: (req: FeedInfoRequest) => axiosInstance.post<FeedInfo>("feed/fetch", req),
|
||||
subscribe: (req: SubscribeRequest) => axiosInstance.post("feed/subscribe", req),
|
||||
subscribe: (req: SubscribeRequest) => axiosInstance.post<Subscription>("feed/subscribe", req),
|
||||
unsubscribe: (req: IDRequest) => axiosInstance.post("feed/unsubscribe", req),
|
||||
importOpml: (req: File) => {
|
||||
const formData = new FormData()
|
||||
|
||||
@@ -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)])
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user