bum
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
/target
|
||||
.env
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::models::{Admin, AdminEmail, NewAdmin, NewAdminEmail};
|
||||
use common::CommonAdmin;
|
||||
use diesel::prelude::*;
|
||||
|
||||
pub fn listadmins(connection: &mut PgConnection) -> String {
|
||||
@@ -38,3 +39,17 @@ pub fn listadminmails(connection: &mut PgConnection) {
|
||||
println!("{} {}", addmail.email, addmail.admin_id);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_admin(connection: &mut PgConnection, admin_id: i32) -> CommonAdmin {
|
||||
use crate::schema::admins::dsl::*;
|
||||
let admin = &mut admins
|
||||
.filter(id.eq(admin_id))
|
||||
.limit(1)
|
||||
.load::<Admin>(connection)
|
||||
.expect("no admins :(")[0];
|
||||
return CommonAdmin {
|
||||
id: admin.id,
|
||||
name: String::from(&admin.name),
|
||||
address: String::from(&admin.address),
|
||||
};
|
||||
}
|
||||
|
||||
18
src/main.rs
18
src/main.rs
@@ -3,8 +3,9 @@ use actix_web::{
|
||||
web::{self, Json},
|
||||
App, HttpServer,
|
||||
};
|
||||
use backend::{establish_connection, ticket_data::get_ticket};
|
||||
use backend::{establish_connection, ticket_data::get_ticket, admin_data::get_admin};
|
||||
use common::CommonTicket;
|
||||
use common::CommonAdmin;
|
||||
|
||||
// //Admin Services
|
||||
// #[get("/api/admin/{id}")]
|
||||
@@ -18,15 +19,24 @@ use common::CommonTicket;
|
||||
|
||||
//Ticket Table Services
|
||||
#[get("api/ticket/{id}")]
|
||||
async fn ticket(id: web::Path<i32>) -> Json<CommonTicket> {
|
||||
async fn get_ticket(id: web::Path<i32>) -> Json<CommonTicket> {
|
||||
let fetched_ticket = get_ticket(&mut establish_connection(), *id);
|
||||
Json(fetched_ticket)
|
||||
}
|
||||
|
||||
// Getting admin data or smth idk
|
||||
#[get("api/admin/{id}")]
|
||||
async fn get_admin(id: web::Path<i32>) -> Json<CommonAdmin> {
|
||||
let fetched_admin_data = get_admin(&mut establish_connection(), *id);
|
||||
Json(fetched_admin_data)
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| App::new().service(ticket))
|
||||
.bind(("127.0.0.1", 8081))?
|
||||
HttpServer::new(|| App::new()
|
||||
.service(get_ticket)
|
||||
.service(get_admin))
|
||||
.bind(("0.0.0.0", 48590))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user