aboutsummaryrefslogtreecommitdiffstats
path: root/src/web_server/default.rs
diff options
context:
space:
mode:
authorJokler <jokler@protonmail.com>2020-10-14 00:19:27 +0200
committerJokler <jokler@protonmail.com>2020-10-15 01:45:29 +0200
commit4e1c2b9f04073294ecb8402486c20d9c01721598 (patch)
tree93fe1d75477ae3d1c8466611a2cedd7bed316aa2 /src/web_server/default.rs
parent23671b51b4e207574a63bce820acbf43169e2b6c (diff)
downloadpokebot-4e1c2b9f04073294ecb8402486c20d9c01721598.tar.gz
pokebot-4e1c2b9f04073294ecb8402486c20d9c01721598.zip
Replace channels&locks with actors & log with slog
Diffstat (limited to 'src/web_server/default.rs')
-rw-r--r--src/web_server/default.rs17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/web_server/default.rs b/src/web_server/default.rs
index 542dade..6b15784 100644
--- a/src/web_server/default.rs
+++ b/src/web_server/default.rs
@@ -1,9 +1,9 @@
-use actix::Addr;
use actix_web::{http::header, web, Error, HttpResponse};
-use askama::Template;
-use askama_actix::TemplateIntoResponse;
+use askama_actix::{Template, TemplateIntoResponse};
+use xtra::WeakAddress;
-use crate::web_server::{filters, BotData, BotDataRequest, BotExecutor, BotNameListRequest};
+use crate::web_server::{filters, BotData, BotDataRequest, BotNameListRequest};
+use crate::MasterBot;
#[derive(Template)]
#[template(path = "index.htm")]
@@ -12,8 +12,8 @@ struct OverviewTemplate<'a> {
bot: Option<&'a BotData>,
}
-pub async fn index(bot: web::Data<Addr<BotExecutor>>) -> Result<HttpResponse, Error> {
- let bot_names = bot.send(BotNameListRequest).await.unwrap().unwrap();
+pub async fn index(bot: web::Data<WeakAddress<MasterBot>>) -> Result<HttpResponse, Error> {
+ let bot_names = bot.send(BotNameListRequest).await.unwrap();
OverviewTemplate {
bot_names: &bot_names,
@@ -23,10 +23,10 @@ pub async fn index(bot: web::Data<Addr<BotExecutor>>) -> Result<HttpResponse, Er
}
pub async fn get_bot(
- bot: web::Data<Addr<BotExecutor>>,
+ bot: web::Data<WeakAddress<MasterBot>>,
name: String,
) -> Result<HttpResponse, Error> {
- let bot_names = bot.send(BotNameListRequest).await.unwrap().unwrap();
+ let bot_names = bot.send(BotNameListRequest).await.unwrap();
if let Some(bot) = bot.send(BotDataRequest(name)).await.unwrap() {
OverviewTemplate {
@@ -35,7 +35,6 @@ pub async fn get_bot(
}
.into_response()
} else {
- // TODO to 404 or not to 404
Ok(HttpResponse::Found().header(header::LOCATION, "/").finish())
}
}