~vpzom/lotide

11545b2b1ae448769313d306c8eda38c6ef33536 — Colin Reeder 3 months ago 746f882
Add in_any_local_community parameter to posts list
2 files changed, 16 insertions(+), 1 deletions(-)

M openapi/openapi.json
M src/routes/api/posts.rs
M openapi/openapi.json => openapi/openapi.json +7 -0
@@ 1108,6 1108,13 @@
						"in": "query",
						"required": false,
						"schema": {"type": "string"}
					},
					{
						"name": "in_any_local_community",
						"in": "query",
						"required": false,
						"schema": {"type": "string"},
						"description": "Filter by whether the post is approved in a local community"
					}
				],
				"responses": {

M src/routes/api/posts.rs => src/routes/api/posts.rs +9 -1
@@ 132,7 132,7 @@ async fn route_unstable_posts_list(

    #[derive(Deserialize)]
    struct PostsListQuery<'a> {
        #[serde(default)]
        in_any_local_community: Option<bool>,
        search: Option<Cow<'a, str>>,

        #[serde(default)]


@@ 178,6 178,14 @@ async fn route_unstable_posts_list(
        search_value_idx = Some(values.len());
        write!(sql, " AND to_tsvector('english', title || ' ' || COALESCE(content_text, content_markdown, content_html, '')) @@ plainto_tsquery('english', ${})", values.len()).unwrap();
    }
    if let Some(value) = query.in_any_local_community {
        write!(
            sql,
            " AND {}(community.local AND post.approved)",
            if value { "" } else { "NOT " }
        )
        .unwrap();
    }
    sql.push_str(" ORDER BY ");
    match query.sort {
        PostsListSortType::Normal(ty) => sql.push_str(ty.post_sort_sql()),