Turn all models into GraphQL(Input)Objects

This commit is contained in:
Paul van Tilburg 2019-07-09 12:23:58 +02:00
parent f8bff689e6
commit 5e24738bba
5 changed files with 16 additions and 15 deletions

View File

@ -1,6 +1,6 @@
use chrono::NaiveDateTime;
use serde_derive::{Deserialize, Serialize};
use diesel::prelude::*;
use juniper_codegen::{GraphQLInputObject, GraphQLObject};
use crate::schema::company_infos;
use crate::DbConn;
@ -9,7 +9,7 @@ use crate::DbConn;
///
/// This model represents information about the company or sole proprietorship of the user of
/// StopTime.
#[derive(Associations, Debug, Identifiable, Deserialize, Queryable, Serialize)]
#[derive(Associations, Debug, GraphQLObject, Identifiable, Queryable)]
#[belongs_to(CompanyInfo, foreign_key = "original_id")]
#[table_name = "company_infos"]
pub struct CompanyInfo {
@ -77,7 +77,7 @@ impl CompanyInfo {
/// The new company (information) model.
///
/// This model represents new company information that can be inserted into the database.
#[derive(Debug, Deserialize, Insertable, Serialize)]
#[derive(Debug, GraphQLInputObject, Insertable)]
#[table_name = "company_infos"]
pub struct NewCompanyInfo {
/// The international bank account number

View File

@ -1,6 +1,7 @@
use chrono::NaiveDateTime;
use serde_derive::{Deserialize, Serialize};
use diesel::prelude::*;
use juniper::FieldResult;
use juniper_codegen::{object, GraphQLInputObject};
use crate::models::{Invoice, Task};
use crate::schema::customers;
@ -10,7 +11,7 @@ use crate::DbConn;
///
/// This model represents a customer that has projects/tasks for which invoices need to be
/// generated.
#[derive(AsChangeset, Debug, Deserialize, Identifiable, Queryable, Serialize)]
#[derive(AsChangeset, Associations, Debug, Identifiable, Queryable)]
#[table_name = "customers"]
pub struct Customer {
/// The unique identification number
@ -69,7 +70,7 @@ impl Customer {
/// The new customer model
///
/// This model represents a new customer that can be inserted into the database.
#[derive(Default, Deserialize, Insertable, Serialize)]
#[derive(Default, GraphQLInputObject, Insertable)]
#[table_name = "customers"]
pub struct NewCustomer {
/// The city part of the address

View File

@ -1,6 +1,6 @@
use chrono::NaiveDateTime;
use serde_derive::{Deserialize, Serialize};
use diesel::prelude::*;
use juniper_codegen::{GraphQLInputObject, GraphQLObject};
use crate::models::{CompanyInfo, Customer, Task};
use crate::schema::invoices;
@ -10,7 +10,7 @@ use crate::DbConn;
///
/// This model represents an invoice for a customer that contains billed tasks and through the
/// tasks the registered time.
#[derive(AsChangeset, Associations, Debug, Deserialize, Identifiable, Queryable, Serialize)]
#[derive(AsChangeset, Associations, Debug, GraphQLObject, Identifiable, Queryable)]
#[belongs_to(CompanyInfo)]
#[belongs_to(Customer)]
#[table_name = "invoices"]
@ -59,7 +59,7 @@ impl Invoice {
/// The new invoice model.
///
/// This model represents an new invoice for a customer that can be inserted into the database.
#[derive(Debug, Deserialize, Insertable, Serialize)]
#[derive(Debug, GraphQLInputObject, Insertable)]
#[table_name = "invoices"]
pub struct NewInvoice {
/// The ID of the company info at the time of billing

View File

@ -1,6 +1,6 @@
use chrono::NaiveDateTime;
use serde_derive::{Deserialize, Serialize};
use diesel::prelude::*;
use juniper_codegen::{GraphQLInputObject, GraphQLObject};
use crate::models::{Customer, Invoice, TimeEntry};
use crate::schema::tasks;
@ -10,7 +10,7 @@ use crate::DbConn;
///
/// This model represents a task (or project) of a customer on which time can be registered.
/// generated.
#[derive(AsChangeset, Associations, Debug, Deserialize, Identifiable, Queryable, Serialize)]
#[derive(AsChangeset, Associations, Debug, GraphQLObject, Identifiable, Queryable)]
#[belongs_to(Customer)]
#[belongs_to(Invoice)]
#[table_name = "tasks"]
@ -65,7 +65,7 @@ impl Task {
///
/// This model represents a new task (or project) of a customer that can be inserted into the
/// database.
#[derive(Debug, Deserialize, Insertable, Serialize)]
#[derive(Debug, GraphQLInputObject, Insertable)]
#[table_name = "tasks"]
pub struct NewTask {
/// The ID of the associated customer

View File

@ -1,6 +1,6 @@
use chrono::NaiveDateTime;
use serde_derive::{Deserialize, Serialize};
use diesel::prelude::*;
use juniper_codegen::{GraphQLInputObject, GraphQLObject};
use crate::models::Task;
use crate::schema::time_entries;
@ -9,7 +9,7 @@ use crate::DbConn;
/// The time entry model.
///
/// This model represents an amount of time that is registered for a certain task.
#[derive(AsChangeset, Associations, Debug, Deserialize, Identifiable, Queryable, Serialize)]
#[derive(AsChangeset, Associations, Debug, GraphQLObject, Identifiable, Queryable)]
#[belongs_to(Task)]
#[table_name = "time_entries"]
pub struct TimeEntry {
@ -43,7 +43,7 @@ impl TimeEntry {
/// The new time entry model.
///
/// This model represents a new registered amount of time that can be inserted into the database.
#[derive(Debug, Deserialize, Insertable, Serialize)]
#[derive(Debug, GraphQLInputObject, Insertable)]
#[table_name = "time_entries"]
pub struct NewTimeEntry {
/// Flag whether to bill or not