Disable dependency to service in rest-types by default

This commit is contained in:
Simon Goller 2024-06-25 13:28:51 +02:00
parent 12e61d6bc2
commit ef2bbd22cf
3 changed files with 29 additions and 0 deletions

View file

@ -4,9 +4,14 @@ version = "0.1.0"
edition = "2021" edition = "2021"
resolver = "2" resolver = "2"
[features]
#default = ["service-impl"]
default = []
service-impl = ["dep:service"]
[dependencies.service] [dependencies.service]
path = "../service" path = "../service"
optional = true
[dependencies.serde] [dependencies.serde]
version = "1.0.198" version = "1.0.198"

View file

@ -1,6 +1,7 @@
use std::sync::Arc; use std::sync::Arc;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[cfg(feature = "service-impl")]
use service::{booking::Booking, sales_person::SalesPerson}; use service::{booking::Booking, sales_person::SalesPerson};
use time::PrimitiveDateTime; use time::PrimitiveDateTime;
use uuid::Uuid; use uuid::Uuid;
@ -9,6 +10,7 @@ use uuid::Uuid;
pub struct UserTO { pub struct UserTO {
pub name: String, pub name: String,
} }
#[cfg(feature = "service-impl")]
impl From<&service::User> for UserTO { impl From<&service::User> for UserTO {
fn from(user: &service::User) -> Self { fn from(user: &service::User) -> Self {
Self { Self {
@ -21,6 +23,7 @@ impl From<&service::User> for UserTO {
pub struct RoleTO { pub struct RoleTO {
pub name: String, pub name: String,
} }
#[cfg(feature = "service-impl")]
impl From<&service::Role> for RoleTO { impl From<&service::Role> for RoleTO {
fn from(role: &service::Role) -> Self { fn from(role: &service::Role) -> Self {
Self { Self {
@ -33,6 +36,7 @@ impl From<&service::Role> for RoleTO {
pub struct PrivilegeTO { pub struct PrivilegeTO {
pub name: String, pub name: String,
} }
#[cfg(feature = "service-impl")]
impl From<&service::Privilege> for PrivilegeTO { impl From<&service::Privilege> for PrivilegeTO {
fn from(privilege: &service::Privilege) -> Self { fn from(privilege: &service::Privilege) -> Self {
Self { Self {
@ -69,6 +73,7 @@ pub struct BookingTO {
#[serde(default)] #[serde(default)]
pub version: Uuid, pub version: Uuid,
} }
#[cfg(feature = "service-impl")]
impl From<&Booking> for BookingTO { impl From<&Booking> for BookingTO {
fn from(booking: &Booking) -> Self { fn from(booking: &Booking) -> Self {
Self { Self {
@ -83,6 +88,7 @@ impl From<&Booking> for BookingTO {
} }
} }
} }
#[cfg(feature = "service-impl")]
impl From<&BookingTO> for Booking { impl From<&BookingTO> for Booking {
fn from(booking: &BookingTO) -> Self { fn from(booking: &BookingTO) -> Self {
Self { Self {
@ -114,6 +120,7 @@ pub struct SalesPersonTO {
#[serde(default)] #[serde(default)]
pub version: Uuid, pub version: Uuid,
} }
#[cfg(feature = "service-impl")]
impl From<&SalesPerson> for SalesPersonTO { impl From<&SalesPerson> for SalesPersonTO {
fn from(sales_person: &SalesPerson) -> Self { fn from(sales_person: &SalesPerson) -> Self {
Self { Self {
@ -127,6 +134,7 @@ impl From<&SalesPerson> for SalesPersonTO {
} }
} }
} }
#[cfg(feature = "service-impl")]
impl From<&SalesPersonTO> for SalesPerson { impl From<&SalesPersonTO> for SalesPerson {
fn from(sales_person: &SalesPersonTO) -> Self { fn from(sales_person: &SalesPersonTO) -> Self {
Self { Self {
@ -151,6 +159,7 @@ pub enum DayOfWeekTO {
Saturday, Saturday,
Sunday, Sunday,
} }
#[cfg(feature = "service-impl")]
impl From<service::slot::DayOfWeek> for DayOfWeekTO { impl From<service::slot::DayOfWeek> for DayOfWeekTO {
fn from(day_of_week: service::slot::DayOfWeek) -> Self { fn from(day_of_week: service::slot::DayOfWeek) -> Self {
match day_of_week { match day_of_week {
@ -164,6 +173,7 @@ impl From<service::slot::DayOfWeek> for DayOfWeekTO {
} }
} }
} }
#[cfg(feature = "service-impl")]
impl From<DayOfWeekTO> for service::slot::DayOfWeek { impl From<DayOfWeekTO> for service::slot::DayOfWeek {
fn from(day_of_week: DayOfWeekTO) -> Self { fn from(day_of_week: DayOfWeekTO) -> Self {
match day_of_week { match day_of_week {
@ -193,6 +203,7 @@ pub struct SlotTO {
#[serde(default)] #[serde(default)]
pub version: Uuid, pub version: Uuid,
} }
#[cfg(feature = "service-impl")]
impl From<&service::slot::Slot> for SlotTO { impl From<&service::slot::Slot> for SlotTO {
fn from(slot: &service::slot::Slot) -> Self { fn from(slot: &service::slot::Slot) -> Self {
Self { Self {
@ -207,6 +218,7 @@ impl From<&service::slot::Slot> for SlotTO {
} }
} }
} }
#[cfg(feature = "service-impl")]
impl From<&SlotTO> for service::slot::Slot { impl From<&SlotTO> for service::slot::Slot {
fn from(slot: &SlotTO) -> Self { fn from(slot: &SlotTO) -> Self {
Self { Self {
@ -228,6 +240,7 @@ pub struct ShortEmployeeReportTO {
pub balance_hours: f32, pub balance_hours: f32,
} }
#[cfg(feature = "service-impl")]
impl From<&service::reporting::ShortEmployeeReport> for ShortEmployeeReportTO { impl From<&service::reporting::ShortEmployeeReport> for ShortEmployeeReportTO {
fn from(report: &service::reporting::ShortEmployeeReport) -> Self { fn from(report: &service::reporting::ShortEmployeeReport) -> Self {
Self { Self {
@ -244,6 +257,7 @@ pub enum ExtraHoursReportCategoryTO {
SickLeave, SickLeave,
Holiday, Holiday,
} }
#[cfg(feature = "service-impl")]
impl From<&service::reporting::ExtraHoursCategory> for ExtraHoursReportCategoryTO { impl From<&service::reporting::ExtraHoursCategory> for ExtraHoursReportCategoryTO {
fn from(category: &service::reporting::ExtraHoursCategory) -> Self { fn from(category: &service::reporting::ExtraHoursCategory) -> Self {
match category { match category {
@ -262,6 +276,7 @@ pub struct WorkingHoursDayTO {
pub hours: f32, pub hours: f32,
pub category: ExtraHoursReportCategoryTO, pub category: ExtraHoursReportCategoryTO,
} }
#[cfg(feature = "service-impl")]
impl From<&service::reporting::WorkingHoursDay> for WorkingHoursDayTO { impl From<&service::reporting::WorkingHoursDay> for WorkingHoursDayTO {
fn from(day: &service::reporting::WorkingHoursDay) -> Self { fn from(day: &service::reporting::WorkingHoursDay) -> Self {
Self { Self {
@ -289,6 +304,7 @@ pub struct WorkingHoursReportTO {
pub days: Arc<[WorkingHoursDayTO]>, pub days: Arc<[WorkingHoursDayTO]>,
} }
#[cfg(feature = "service-impl")]
impl From<&service::reporting::WorkingHours> for WorkingHoursReportTO { impl From<&service::reporting::WorkingHours> for WorkingHoursReportTO {
fn from(hours: &service::reporting::WorkingHours) -> Self { fn from(hours: &service::reporting::WorkingHours) -> Self {
Self { Self {
@ -329,6 +345,7 @@ pub struct EmployeeReportTO {
pub by_week: Arc<[WorkingHoursReportTO]>, pub by_week: Arc<[WorkingHoursReportTO]>,
pub by_month: Arc<[WorkingHoursReportTO]>, pub by_month: Arc<[WorkingHoursReportTO]>,
} }
#[cfg(feature = "service-impl")]
impl From<&service::reporting::EmployeeReport> for EmployeeReportTO { impl From<&service::reporting::EmployeeReport> for EmployeeReportTO {
fn from(report: &service::reporting::EmployeeReport) -> Self { fn from(report: &service::reporting::EmployeeReport) -> Self {
@ -376,6 +393,7 @@ pub struct WorkingHoursTO {
#[serde(default)] #[serde(default)]
pub version: Uuid, pub version: Uuid,
} }
#[cfg(feature = "service-impl")]
impl From<&service::working_hours::WorkingHours> for WorkingHoursTO { impl From<&service::working_hours::WorkingHours> for WorkingHoursTO {
fn from(working_hours: &service::working_hours::WorkingHours) -> Self { fn from(working_hours: &service::working_hours::WorkingHours) -> Self {
Self { Self {
@ -393,6 +411,7 @@ impl From<&service::working_hours::WorkingHours> for WorkingHoursTO {
} }
} }
#[cfg(feature = "service-impl")]
impl From<&WorkingHoursTO> for service::working_hours::WorkingHours { impl From<&WorkingHoursTO> for service::working_hours::WorkingHours {
fn from(working_hours: &WorkingHoursTO) -> Self { fn from(working_hours: &WorkingHoursTO) -> Self {
Self { Self {
@ -417,6 +436,7 @@ pub enum ExtraHoursCategoryTO {
SickLeave, SickLeave,
Holiday, Holiday,
} }
#[cfg(feature = "service-impl")]
impl From<&service::extra_hours::ExtraHoursCategory> for ExtraHoursCategoryTO { impl From<&service::extra_hours::ExtraHoursCategory> for ExtraHoursCategoryTO {
fn from(category: &service::extra_hours::ExtraHoursCategory) -> Self { fn from(category: &service::extra_hours::ExtraHoursCategory) -> Self {
match category { match category {
@ -427,6 +447,7 @@ impl From<&service::extra_hours::ExtraHoursCategory> for ExtraHoursCategoryTO {
} }
} }
} }
#[cfg(feature = "service-impl")]
impl From<&ExtraHoursCategoryTO> for service::extra_hours::ExtraHoursCategory { impl From<&ExtraHoursCategoryTO> for service::extra_hours::ExtraHoursCategory {
fn from(category: &ExtraHoursCategoryTO) -> Self { fn from(category: &ExtraHoursCategoryTO) -> Self {
match category { match category {
@ -455,6 +476,7 @@ pub struct ExtraHoursTO {
#[serde(default)] #[serde(default)]
pub version: Uuid, pub version: Uuid,
} }
#[cfg(feature = "service-impl")]
impl From<&service::extra_hours::ExtraHours> for ExtraHoursTO { impl From<&service::extra_hours::ExtraHours> for ExtraHoursTO {
fn from(extra_hours: &service::extra_hours::ExtraHours) -> Self { fn from(extra_hours: &service::extra_hours::ExtraHours) -> Self {
Self { Self {
@ -470,6 +492,7 @@ impl From<&service::extra_hours::ExtraHours> for ExtraHoursTO {
} }
} }
} }
#[cfg(feature = "service-impl")]
impl From<&ExtraHoursTO> for service::extra_hours::ExtraHours { impl From<&ExtraHoursTO> for service::extra_hours::ExtraHours {
fn from(extra_hours: &ExtraHoursTO) -> Self { fn from(extra_hours: &ExtraHoursTO) -> Self {
Self { Self {

View file

@ -29,6 +29,7 @@ path = "../service"
[dependencies.rest-types] [dependencies.rest-types]
path = "../rest-types" path = "../rest-types"
features = ["service-impl"]
[dependencies.uuid] [dependencies.uuid]
version = "1.8.0" version = "1.8.0"