API frame needs some way of setting up all the things in the db before we can use it'
This commit is contained in:
		
						commit
						2c3c2efd03
					
				
							
								
								
									
										1602
									
								
								api/Cargo.lock
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										1602
									
								
								api/Cargo.lock
									
									
									
										generated
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										9
									
								
								api/Cargo.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								api/Cargo.toml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					[package]
 | 
				
			||||||
 | 
					name = "bubble"
 | 
				
			||||||
 | 
					version = "0.1.0"
 | 
				
			||||||
 | 
					edition = "2021"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[dependencies]
 | 
				
			||||||
 | 
					tokio = { version = "1", features = [ "full" ] }
 | 
				
			||||||
 | 
					serde = "1.0.213"
 | 
				
			||||||
 | 
					rocket = { version = "0.5.1", features = [ "json" ] }
 | 
				
			||||||
							
								
								
									
										41
									
								
								api/src/channels.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								api/src/channels.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,41 @@
 | 
				
			|||||||
 | 
					use serde::Serialize;
 | 
				
			||||||
 | 
					use rocket::serde::json::Json;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(Serialize)]
 | 
				
			||||||
 | 
					enum Type {
 | 
				
			||||||
 | 
					    Voice,
 | 
				
			||||||
 | 
					    Text,
 | 
				
			||||||
 | 
					    Video
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#[derive(Serialize)]
 | 
				
			||||||
 | 
					struct Channel {
 | 
				
			||||||
 | 
					    id: i64,
 | 
				
			||||||
 | 
					    name: String,
 | 
				
			||||||
 | 
					    desc: Option<String>,
 | 
				
			||||||
 | 
					    r#type: Type
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[get("/list")]
 | 
				
			||||||
 | 
					pub async fn list() -> Json<Vec<Channel>> {
 | 
				
			||||||
 | 
					    // TODO
 | 
				
			||||||
 | 
					    Json(vec![])
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[post("/create")]
 | 
				
			||||||
 | 
					pub async fn create() -> Json<Option<Channel>> {
 | 
				
			||||||
 | 
					    // TODO
 | 
				
			||||||
 | 
					    Json(None)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[delete("/delete")]
 | 
				
			||||||
 | 
					pub async fn delete() -> Json<Option<i64>> {
 | 
				
			||||||
 | 
					    // TODO
 | 
				
			||||||
 | 
					    Json(None)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[post("/update")]
 | 
				
			||||||
 | 
					pub async fn update() -> Json<Option<Channel>> {
 | 
				
			||||||
 | 
					    // TODO
 | 
				
			||||||
 | 
					    Json(None)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										14
									
								
								api/src/invites.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								api/src/invites.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,14 @@
 | 
				
			|||||||
 | 
					use rocket::serde::json::Json;
 | 
				
			||||||
 | 
					use serde::Serialize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(Serialize)]
 | 
				
			||||||
 | 
					pub struct User {
 | 
				
			||||||
 | 
					    id: i64,
 | 
				
			||||||
 | 
					    name: String,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[get("/<id>")]
 | 
				
			||||||
 | 
					pub async fn invite_user(id: i64) -> Json<Option<User>> {
 | 
				
			||||||
 | 
					    // First we check to see if the id is present in the invites table
 | 
				
			||||||
 | 
					    Json(None)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										17
									
								
								api/src/main.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								api/src/main.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					#[macro_use] extern crate rocket;
 | 
				
			||||||
 | 
					mod invites;
 | 
				
			||||||
 | 
					mod channels;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[rocket::main]
 | 
				
			||||||
 | 
					async fn main() -> Result<(), rocket::Error> {
 | 
				
			||||||
 | 
					    let _ = rocket::build()
 | 
				
			||||||
 | 
					        .mount("/channels", routes![
 | 
				
			||||||
 | 
					               channels::list,
 | 
				
			||||||
 | 
					               channels::create,
 | 
				
			||||||
 | 
					               channels::delete
 | 
				
			||||||
 | 
					        ])
 | 
				
			||||||
 | 
					        .mount("/invite", routes![invites::invite_user])
 | 
				
			||||||
 | 
					        .ignite().await?
 | 
				
			||||||
 | 
					        .launch().await?;
 | 
				
			||||||
 | 
					    Ok(())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user