aboutsummaryrefslogtreecommitdiffstats
path: root/src/web_server/default.rs
blob: b3c829188ec66a3924fd96841b53bc57158c09ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use actix::Addr;
use actix_web::{web, Error, HttpResponse};
use askama::actix_web::TemplateIntoResponse;
use askama::Template;

use crate::web_server::{filters, BotData, BotDataListRequest, BotExecutor};

#[derive(Template)]
#[template(path = "index.htm")]
struct OverviewTemplate<'a> {
    bots: &'a [BotData],
}

pub async fn index(bot: web::Data<Addr<BotExecutor>>) -> Result<HttpResponse, Error> {
    let bot_datas = match bot.send(BotDataListRequest).await.unwrap() {
        Ok(data) => data,
        Err(_) => Vec::with_capacity(0),
    };

    OverviewTemplate {
        bots: &bot_datas[..],
    }
    .into_response()
}