BOOM
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
use crate::models::{AutoIssuedTicket, IssuedTicket, NewTicket, Ticket};
|
||||
use crate::{
|
||||
models::{AutoIssuedTicket, IssuedTicket, NewTicket, Ticket},
|
||||
schema::{
|
||||
drivers,
|
||||
issued_tickets::{self, driver},
|
||||
tickets,
|
||||
},
|
||||
};
|
||||
use common::CommonTicket;
|
||||
use diesel::prelude::*;
|
||||
|
||||
@@ -10,20 +17,30 @@ pub fn create_ticket(connection: &mut PgConnection, ticket: NewTicket) {
|
||||
.expect("Didn't save ticket AAAAAA");
|
||||
}
|
||||
|
||||
pub fn get_tickets(connection: &mut PgConnection, amount: i64) -> Vec<CommonTicket> {
|
||||
use crate::schema::tickets::dsl::*;
|
||||
let results = tickets
|
||||
.limit(amount)
|
||||
.load::<Ticket>(connection)
|
||||
.expect("KANKER TIKET");
|
||||
return results
|
||||
pub fn get_tickets(connection: &mut PgConnection, driver_id: i32) -> Vec<CommonTicket> {
|
||||
//Chonky join function for the sake of my life :))
|
||||
let join = tickets::table
|
||||
.left_join(
|
||||
issued_tickets::table.on(tickets::id
|
||||
.eq(issued_tickets::ticket)
|
||||
.and(issued_tickets::driver.eq(driver_id))),
|
||||
)
|
||||
.select((
|
||||
tickets::id,
|
||||
tickets::category,
|
||||
tickets::description,
|
||||
tickets::issue_date, //only selecting the ticket tho :D
|
||||
));
|
||||
let tickets_by_driver = join.load::<Ticket>(connection).expect("oh no!");
|
||||
let common_ticket_output = tickets_by_driver
|
||||
.iter()
|
||||
.map(|ticket| CommonTicket {
|
||||
id: ticket.id,
|
||||
category: String::from(&ticket.category),
|
||||
description: String::from(&ticket.description),
|
||||
})
|
||||
.collect(); //Shoves everything to a vector
|
||||
.collect();
|
||||
return common_ticket_output;
|
||||
}
|
||||
|
||||
pub fn get_ticket(connection: &mut PgConnection, tickid: i32) -> CommonTicket {
|
||||
|
||||
Reference in New Issue
Block a user