Skip to content

Commit

Permalink
refactor(api): use FeedUrl instead of String
Browse files Browse the repository at this point in the history
  • Loading branch information
ymgyt committed Apr 20, 2024
1 parent 759950b commit 95bb5ea
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions crates/synd_api/src/gql/mutation/subscribe_feed.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use async_graphql::{InputObject, Object, Union};
use synd_feed::{
feed::parser::FetchFeedError,
types::{Category, Requirement},
types::{Category, FeedUrl, Requirement},
};

use crate::{
Expand All @@ -15,7 +15,7 @@ use crate::{
#[derive(InputObject, Debug)]
pub struct SubscribeFeedInput {
/// Feed url to subscribe
pub url: String,
pub url: FeedUrl,
/// Requirement level for feed
pub requirement: Option<Requirement>,
/// Feed category
Expand Down
3 changes: 2 additions & 1 deletion crates/synd_api/src/gql/mutation/unsubscribe_feed.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use async_graphql::{InputObject, Object, Union};
use synd_feed::types::FeedUrl;

use crate::{gql::mutation::ResponseStatus, usecase};

#[derive(InputObject)]
pub struct UnsubscribeFeedInput {
/// Feed url to unsubscribe
pub url: String,
pub url: FeedUrl,
}

impl From<UnsubscribeFeedInput> for usecase::UnsubscribeFeedInput {
Expand Down
6 changes: 3 additions & 3 deletions crates/synd_api/src/gql/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use async_graphql::{
Enum, Object, SimpleObject, ID,
};
use feed_rs::model as feedrs;
use synd_feed::types::{self, Annotated, Category, Requirement};
use synd_feed::types::{self, Annotated, Category, FeedUrl, Requirement};

use crate::gql::scalar;

Expand Down Expand Up @@ -107,7 +107,7 @@ impl Feed {
}

/// Feed URL
async fn url(&self) -> &str {
async fn url(&self) -> &FeedUrl {
self.0.feed.meta().url()
}

Expand Down Expand Up @@ -237,7 +237,7 @@ impl<'a> FeedMeta<'a> {
}

/// Url of the feed
async fn url(&self) -> &str {
async fn url(&self) -> &FeedUrl {
self.0.feed.url()
}

Expand Down
2 changes: 1 addition & 1 deletion crates/synd_api/src/gql/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl Subscription {
let edges = feeds
.into_iter()
.take(first)
.map(|feed| (feed.feed.meta().url().to_owned(), feed))
.map(|feed| (feed.feed.meta().url().as_str().to_owned(), feed))
.map(|(cursor, feed)| (cursor, object::Feed::from(feed)))
.map(|(cursor, feed)| Edge::new(cursor, feed));

Expand Down
8 changes: 4 additions & 4 deletions crates/synd_api/src/repository/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{collections::HashMap, sync::Arc};

use kvsd::Value;
use serde::{Deserialize, Serialize};
use synd_feed::types::{self, Annotated, Category, Requirement};
use synd_feed::types::{self, Annotated, Category, FeedUrl, Requirement};

use crate::repository::RepositoryError;

Expand All @@ -15,15 +15,15 @@ pub struct Feed {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FeedSubscription {
pub user_id: String,
pub url: String,
pub url: FeedUrl,
pub requirement: Option<Requirement>,
pub category: Option<Category<'static>>,
}

#[derive(Serialize, Deserialize, Debug, Default)]
pub struct SubscribedFeeds {
pub urls: Vec<String>,
pub annotations: Option<HashMap<String, FeedAnnotations>>,
pub urls: Vec<FeedUrl>,
pub annotations: Option<HashMap<FeedUrl, FeedAnnotations>>,
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion crates/synd_api/src/usecase/fetch_subscribed_feeds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Usecase for FetchSubscribedFeeds {
feeds
.urls
.iter()
.position(|url| url == &after)
.position(|url| url.as_str() == after)
.map(|p| p + 1)
})
.unwrap_or(0);
Expand Down
4 changes: 2 additions & 2 deletions crates/synd_api/src/usecase/subscribe_feed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;

use synd_feed::{
feed::{cache::FetchCachedFeed, parser::FetchFeedError},
types::{Annotated, Category, Feed, Requirement},
types::{Annotated, Category, Feed, FeedUrl, Requirement},
};
use synd_o11y::metric;
use thiserror::Error;
Expand All @@ -21,7 +21,7 @@ pub struct SubscribeFeed {
}

pub struct SubscribeFeedInput {
pub url: String,
pub url: FeedUrl,
pub requirement: Option<Requirement>,
pub category: Option<Category<'static>>,
}
Expand Down
3 changes: 2 additions & 1 deletion crates/synd_api/src/usecase/unsubscribe_feed.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::Arc;

use synd_feed::types::FeedUrl;
use synd_o11y::metric;

use crate::{
Expand All @@ -15,7 +16,7 @@ pub struct UnsubscribeFeed {
}

pub struct UnsubscribeFeedInput {
pub url: String,
pub url: FeedUrl,
}

pub struct UnsubscribeFeedOutput {}
Expand Down

0 comments on commit 95bb5ea

Please sign in to comment.