Move GraphQL-related model code to a separate module

This commit is contained in:
Paul van Tilburg 2019-07-10 20:56:48 +02:00
parent 63fc7a0721
commit fe13723323
1 changed files with 20 additions and 15 deletions

View File

@ -1,7 +1,6 @@
use chrono::NaiveDateTime;
use diesel::prelude::*;
use juniper::FieldResult;
use juniper_codegen::{object, GraphQLInputObject};
use juniper_codegen::GraphQLInputObject;
use crate::models::{Invoice, Task};
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
///
/// 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
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)
}
}
}