Start work on todo list support for dashboard
This commit is contained in:
		@@ -3,6 +3,7 @@ mod emojis;
 | 
			
		||||
mod reminders;
 | 
			
		||||
mod roles;
 | 
			
		||||
mod templates;
 | 
			
		||||
mod todos;
 | 
			
		||||
 | 
			
		||||
use std::env;
 | 
			
		||||
 | 
			
		||||
@@ -16,6 +17,7 @@ use serenity::{
 | 
			
		||||
    model::id::{GuildId, RoleId},
 | 
			
		||||
};
 | 
			
		||||
pub use templates::*;
 | 
			
		||||
pub use todos::{create_todo, delete_todo, get_todo, update_todo};
 | 
			
		||||
 | 
			
		||||
use crate::web::{check_authorization, routes::JsonResult};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										66
									
								
								src/web/routes/dashboard/api/guild/todos.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								src/web/routes/dashboard/api/guild/todos.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,66 @@
 | 
			
		||||
use rocket::{
 | 
			
		||||
    delete, get,
 | 
			
		||||
    http::CookieJar,
 | 
			
		||||
    patch, post,
 | 
			
		||||
    serde::json::{json, Json},
 | 
			
		||||
    State,
 | 
			
		||||
};
 | 
			
		||||
use serde::Deserialize;
 | 
			
		||||
use serenity::prelude::Context;
 | 
			
		||||
 | 
			
		||||
use crate::web::{check_authorization, guards::transaction::Transaction, routes::JsonResult};
 | 
			
		||||
 | 
			
		||||
#[derive(Deserialize)]
 | 
			
		||||
struct CreateTodo {
 | 
			
		||||
    channel_id: Option<u64>,
 | 
			
		||||
    value: String,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[post("/api/guild/<id>/todos", data = "<todo>")]
 | 
			
		||||
pub async fn create_todo(
 | 
			
		||||
    id: u64,
 | 
			
		||||
    todo: Json<CreateTodo>,
 | 
			
		||||
    cookies: &CookieJar<'_>,
 | 
			
		||||
    ctx: &State<Context>,
 | 
			
		||||
    mut transaction: Transaction<'_>,
 | 
			
		||||
) -> JsonResult {
 | 
			
		||||
    check_authorization(cookies, ctx.inner(), id).await?;
 | 
			
		||||
 | 
			
		||||
    Ok(json!({}))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[get("/api/guild/<id>/todos")]
 | 
			
		||||
pub async fn get_todo(
 | 
			
		||||
    id: u64,
 | 
			
		||||
    cookies: &CookieJar<'_>,
 | 
			
		||||
    ctx: &State<Context>,
 | 
			
		||||
    mut transaction: Transaction<'_>,
 | 
			
		||||
) -> JsonResult {
 | 
			
		||||
    check_authorization(cookies, ctx.inner(), id).await?;
 | 
			
		||||
 | 
			
		||||
    Ok(json!([]))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[patch("/api/guild/<id>/todos")]
 | 
			
		||||
pub async fn update_todo(
 | 
			
		||||
    id: u64,
 | 
			
		||||
    cookies: &CookieJar<'_>,
 | 
			
		||||
    ctx: &State<Context>,
 | 
			
		||||
    mut transaction: Transaction<'_>,
 | 
			
		||||
) -> JsonResult {
 | 
			
		||||
    check_authorization(cookies, ctx.inner(), id).await?;
 | 
			
		||||
 | 
			
		||||
    Ok(json!({}))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[delete("/api/guild/<id>/todos")]
 | 
			
		||||
pub async fn delete_todo(
 | 
			
		||||
    id: u64,
 | 
			
		||||
    cookies: &CookieJar<'_>,
 | 
			
		||||
    ctx: &State<Context>,
 | 
			
		||||
    mut transaction: Transaction<'_>,
 | 
			
		||||
) -> JsonResult {
 | 
			
		||||
    check_authorization(cookies, ctx.inner(), id).await?;
 | 
			
		||||
 | 
			
		||||
    Ok(json!({}))
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user