Nekrocuck
This commit is contained in:
46
src/web/actions/mod.rs
Normal file
46
src/web/actions/mod.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
use askama::Template;
|
||||
use sqlx::query_as;
|
||||
|
||||
use super::tcx::TemplateCtx;
|
||||
use crate::{ctx::Ctx, db::models::Post};
|
||||
|
||||
pub mod appeal_ban;
|
||||
pub mod create_post;
|
||||
pub mod edit_posts;
|
||||
pub mod report_posts;
|
||||
pub mod staff_post_actions;
|
||||
pub mod user_post_actions;
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "action.html")]
|
||||
pub struct ActionTemplate {
|
||||
pub tcx: TemplateCtx,
|
||||
pub response: String,
|
||||
}
|
||||
|
||||
pub async fn get_posts_from_ids(ctx: &Ctx, ids: &Vec<String>) -> Vec<Post> {
|
||||
let mut posts = Vec::new();
|
||||
|
||||
for id in ids {
|
||||
if let Some((board, id)) = parse_id(id) {
|
||||
if let Ok(Some(post)) = query_as("SELECT * FROM overboard WHERE board = $1 AND id = $2")
|
||||
.bind(board)
|
||||
.bind(id)
|
||||
.fetch_optional(ctx.db())
|
||||
.await
|
||||
{
|
||||
posts.push(post);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
posts
|
||||
}
|
||||
|
||||
fn parse_id(id: &str) -> Option<(String, i64)> {
|
||||
let (board, id) = id.split_once('/')?;
|
||||
let board = board.to_owned();
|
||||
let id = id.parse().ok()?;
|
||||
|
||||
Some((board, id))
|
||||
}
|
||||
Reference in New Issue
Block a user