feat: introduce new starchart nodes to other starchart nodes
This commit is contained in:
parent
a155ab9d26
commit
2c4344a23f
3 changed files with 33 additions and 3 deletions
|
@ -36,12 +36,14 @@ impl Search {
|
||||||
#[derive(Deserialize, Serialize, Clone, Debug, Eq, PartialEq)]
|
#[derive(Deserialize, Serialize, Clone, Debug, Eq, PartialEq)]
|
||||||
pub struct Introducer {
|
pub struct Introducer {
|
||||||
pub list: &'static str,
|
pub list: &'static str,
|
||||||
|
pub introduce: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Introducer {
|
impl Introducer {
|
||||||
const fn new() -> Introducer {
|
const fn new() -> Introducer {
|
||||||
let list = "/api/v1/introducer/list";
|
let list = "/api/v1/introducer/list";
|
||||||
Introducer { list }
|
let introduce = "/api/v1/introducer/new";
|
||||||
|
Introducer { list, introduce }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* ForgeFlux StarChart - A federated software forge spider
|
* ForgeFlux StarChart - A federated software forge spider
|
||||||
* Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
* Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
@ -44,6 +44,7 @@ pub async fn lastest(federate: WebFederate) -> ServiceResult<impl Responder> {
|
||||||
Ok(HttpResponse::Ok().json(latest))
|
Ok(HttpResponse::Ok().json(latest))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn services(cfg: &mut web::ServiceConfig) {
|
pub fn services(cfg: &mut web::ServiceConfig) {
|
||||||
cfg.service(lastest);
|
cfg.service(lastest);
|
||||||
cfg.service(forges);
|
cfg.service(forges);
|
||||||
|
|
|
@ -20,6 +20,7 @@ use std::collections::HashSet;
|
||||||
use actix_web::web;
|
use actix_web::web;
|
||||||
use actix_web::{HttpResponse, Responder};
|
use actix_web::{HttpResponse, Responder};
|
||||||
use actix_web_codegen_const_routes::get;
|
use actix_web_codegen_const_routes::get;
|
||||||
|
use actix_web_codegen_const_routes::post;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
pub use api_routes::*;
|
pub use api_routes::*;
|
||||||
|
@ -81,8 +82,19 @@ pub async fn list_introductions(
|
||||||
Ok(HttpResponse::Ok().json(starcharts))
|
Ok(HttpResponse::Ok().json(starcharts))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[post(path = "ROUTES.introducer.introduce")]
|
||||||
|
pub async fn new_introduction(
|
||||||
|
db: WebDB,
|
||||||
|
payload: web::Json<Starchart>,
|
||||||
|
) -> ServiceResult<impl Responder> {
|
||||||
|
db.add_starchart_to_introducer(&Url::parse(&payload.instance_url)?)
|
||||||
|
.await?;
|
||||||
|
Ok(HttpResponse::Ok())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn services(cfg: &mut web::ServiceConfig) {
|
pub fn services(cfg: &mut web::ServiceConfig) {
|
||||||
cfg.service(list_introductions);
|
cfg.service(list_introductions);
|
||||||
|
cfg.service(new_introduction);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -93,7 +105,6 @@ mod tests {
|
||||||
|
|
||||||
use actix_web::http::StatusCode;
|
use actix_web::http::StatusCode;
|
||||||
use actix_web::test;
|
use actix_web::test;
|
||||||
use db_core::prelude::*;
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
|
@ -105,6 +116,22 @@ mod tests {
|
||||||
db.add_starchart_to_introducer(&Url::parse(STARCHART_URL).unwrap())
|
db.add_starchart_to_introducer(&Url::parse(STARCHART_URL).unwrap())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
let payload = Starchart {
|
||||||
|
instance_url: STARCHART_URL.into(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let resp = test::call_service(
|
||||||
|
&app,
|
||||||
|
post_request!(&payload, ROUTES.introducer.introduce).to_request(),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
if resp.status() != StatusCode::OK {
|
||||||
|
let resp_err: ErrorToResponse = test::read_body_json(resp).await;
|
||||||
|
panic!("{}", resp_err.error);
|
||||||
|
}
|
||||||
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
|
|
||||||
let introductions_resp = get_request!(&app, ROUTES.introducer.list);
|
let introductions_resp = get_request!(&app, ROUTES.introducer.list);
|
||||||
assert_eq!(introductions_resp.status(), StatusCode::OK);
|
assert_eq!(introductions_resp.status(), StatusCode::OK);
|
||||||
let introductions: Vec<Starchart> = test::read_body_json(introductions_resp).await;
|
let introductions: Vec<Starchart> = test::read_body_json(introductions_resp).await;
|
||||||
|
|
Loading…
Reference in a new issue