Move GraphQL-related model code to a separate module
This commit is contained in:
parent
63fc7a0721
commit
fe13723323
|
@ -1,7 +1,6 @@
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use juniper::FieldResult;
|
use juniper_codegen::GraphQLInputObject;
|
||||||
use juniper_codegen::{object, GraphQLInputObject};
|
|
||||||
|
|
||||||
use crate::models::{Invoice, Task};
|
use crate::models::{Invoice, Task};
|
||||||
use crate::schema::customers;
|
use crate::schema::customers;
|
||||||
|
@ -54,19 +53,6 @@ impl Customer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[object(Context = DbConn)]
|
|
||||||
impl Customer {
|
|
||||||
/// Returns the invoices billed to the customer.
|
|
||||||
fn invoices(&self, context: &DbConn) -> FieldResult<Vec<Invoice>> {
|
|
||||||
self.invoices(context).map_err(Into::into)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the project/tasks associated with the customer.
|
|
||||||
fn tasks(&self, context: &DbConn) -> FieldResult<Vec<Task>> {
|
|
||||||
self.tasks(context).map_err(Into::into)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The new customer model
|
/// The new customer model
|
||||||
///
|
///
|
||||||
/// This model represents a new customer that can be inserted into the database.
|
/// This model represents a new customer that can be inserted into the database.
|
||||||
|
@ -94,3 +80,22 @@ pub struct NewCustomer {
|
||||||
/// Flag whether the customer requires time specificaions
|
/// Flag whether the customer requires time specificaions
|
||||||
pub time_specification: bool,
|
pub time_specification: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod graphql {
|
||||||
|
use super::{Customer, DbConn, Invoice, Task};
|
||||||
|
|
||||||
|
use juniper::{object, FieldResult};
|
||||||
|
|
||||||
|
#[object(Context = DbConn)]
|
||||||
|
impl Customer {
|
||||||
|
/// Returns the invoices billed to the customer.
|
||||||
|
fn invoices(&self, context: &DbConn) -> FieldResult<Vec<Invoice>> {
|
||||||
|
self.invoices(context).map_err(Into::into)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the project/tasks associated with the customer.
|
||||||
|
fn tasks(&self, context: &DbConn) -> FieldResult<Vec<Task>> {
|
||||||
|
self.tasks(context).map_err(Into::into)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue