Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
httpd: Conform response from issue handlers to previous model
xphoniex committed 3 years ago
commit a40d53743dab8133d4ede6a5573e3f6e6f388c17
parent 3f4aecfadf254c92fcfcd3ef31c1fcca9acb529b
1 file changed +44 -6
modified radicle-httpd/src/api/v1/projects.rs
@@ -11,8 +11,10 @@ use serde_json::json;
use tower_http::set_header::SetResponseHeaderLayer;

use radicle::cob::issue::Issues;
+
use radicle::cob::thread::{self, CommentId};
+
use radicle::cob::Timestamp;
use radicle::git::raw::BranchType;
-
use radicle::identity::{Doc, Id};
+
use radicle::identity::{Doc, Id, PublicKey};
use radicle::node::NodeId;
use radicle::storage::{Oid, ReadRepository, WriteRepository, WriteStorage};
use radicle_surf::git::History;
@@ -330,11 +332,11 @@ async fn issues_handler(
        .filter_map(|r| r.ok())
        .map(|(id, issue, _)| {
            json!({
-
                "id": id,
+
                "id": id.to_string(),
                "author": issue.author(),
                "title": issue.title(),
-
                "status": issue.state(),
-
                "discussion": issue.comments().collect::<Vec<_>>(),
+
                "state": issue.state(),
+
                "discussion": issue.comments().collect::<Comments>(),
                "tags": issue.tags().collect::<Vec<_>>(),
            })
        })
@@ -360,8 +362,8 @@ async fn issue_handler(
        "id": issue_id,
        "author": issue.author(),
        "title": issue.title(),
-
        "status": issue.state(),
-
        "discussion": issue.comments().collect::<Vec<_>>(),
+
        "state": issue.state(),
+
        "discussion": issue.comments().collect::<Comments>(),
        "tags": issue.tags().collect::<Vec<_>>(),
    });

@@ -369,6 +371,42 @@ async fn issue_handler(
}

#[derive(Serialize)]
+
struct Author {
+
    id: PublicKey,
+
}
+

+
#[derive(Serialize)]
+
#[serde(rename_all = "camelCase")]
+
struct Comment {
+
    author: Author,
+
    body: String,
+
    reactions: [String; 0],
+
    timestamp: Timestamp,
+
    reply_to: Option<CommentId>,
+
}
+

+
#[derive(Serialize)]
+
struct Comments(Vec<Comment>);
+

+
impl<'a> FromIterator<(&'a CommentId, &'a thread::Comment)> for Comments {
+
    fn from_iter<I: IntoIterator<Item = (&'a CommentId, &'a thread::Comment)>>(iter: I) -> Self {
+
        let mut comments = Vec::new();
+

+
        for (comment_id, comment) in iter {
+
            comments.push(Comment {
+
                author: Author { id: comment_id.1 },
+
                body: comment.body.to_owned(),
+
                reactions: [],
+
                timestamp: comment.timestamp,
+
                reply_to: comment.reply_to,
+
            });
+
        }
+

+
        Comments(comments)
+
    }
+
}
+

+
#[derive(Serialize)]
struct Stats {
    branches: usize,
    commits: usize,