30 lines
774 B
Rust
30 lines
774 B
Rust
use actix_web::http::StatusCode;
|
|
use actix_web::{HttpResponse, Responder};
|
|
use serde::Serialize;
|
|
|
|
#[derive(Serialize)]
|
|
pub struct FeedInfo {
|
|
pub id: i32,
|
|
pub title: String,
|
|
pub url: String,
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
pub struct FeedInfoList {
|
|
pub feeds: Vec<FeedInfo>,
|
|
}
|
|
|
|
impl Responder for FeedInfoList {
|
|
type Body = String;
|
|
|
|
fn respond_to(self, _req: &actix_web::HttpRequest) -> actix_web::HttpResponse<Self::Body> {
|
|
match serde_json::to_string(&self) {
|
|
Ok(body) => HttpResponse::with_body(StatusCode::OK, body),
|
|
Err(err) => {
|
|
log::error!("Failed to serialize response: {}", err);
|
|
HttpResponse::with_body(StatusCode::INTERNAL_SERVER_ERROR, String::new())
|
|
}
|
|
}
|
|
}
|
|
}
|