Cargo clippy and cargo fmt
This commit is contained in:
parent
b0000c0117
commit
ed609cf06c
22 changed files with 286 additions and 94 deletions
|
|
@ -1,8 +1,8 @@
|
|||
use async_trait::async_trait;
|
||||
use service::{
|
||||
booking::{Booking, BookingService},
|
||||
ServiceError, ValidationFailureItem,
|
||||
permission::Authentication,
|
||||
ServiceError, ValidationFailureItem,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
use uuid::Uuid;
|
||||
|
|
@ -90,7 +90,10 @@ where
|
|||
{
|
||||
type Context = PermissionService::Context;
|
||||
|
||||
async fn get_all(&self, context: Authentication<Self::Context>) -> Result<Arc<[Booking]>, ServiceError> {
|
||||
async fn get_all(
|
||||
&self,
|
||||
context: Authentication<Self::Context>,
|
||||
) -> Result<Arc<[Booking]>, ServiceError> {
|
||||
self.permission_service
|
||||
.check_permission("hr", context)
|
||||
.await?;
|
||||
|
|
@ -103,7 +106,11 @@ where
|
|||
.collect())
|
||||
}
|
||||
|
||||
async fn get(&self, id: Uuid, context: Authentication<Self::Context>) -> Result<Booking, ServiceError> {
|
||||
async fn get(
|
||||
&self,
|
||||
id: Uuid,
|
||||
context: Authentication<Self::Context>,
|
||||
) -> Result<Booking, ServiceError> {
|
||||
self.permission_service
|
||||
.check_permission("hr", context)
|
||||
.await?;
|
||||
|
|
@ -149,22 +156,20 @@ where
|
|||
if booking.calendar_week > 53 {
|
||||
validation.push(ValidationFailureItem::InvalidValue("calendar_week".into()));
|
||||
}
|
||||
if self
|
||||
if !self
|
||||
.sales_person_service
|
||||
.exists(booking.sales_person_id, context.clone())
|
||||
.await?
|
||||
== false
|
||||
{
|
||||
validation.push(ValidationFailureItem::IdDoesNotExist(
|
||||
"sales_person_id".into(),
|
||||
booking.sales_person_id,
|
||||
));
|
||||
}
|
||||
if self
|
||||
if !self
|
||||
.slot_service
|
||||
.exists(booking.slot_id, context.clone())
|
||||
.await?
|
||||
== false
|
||||
{
|
||||
validation.push(ValidationFailureItem::IdDoesNotExist(
|
||||
"slot_id".into(),
|
||||
|
|
@ -178,7 +183,10 @@ where
|
|||
booking.slot_id,
|
||||
booking.calendar_week,
|
||||
booking.year,
|
||||
).await?.is_some() {
|
||||
)
|
||||
.await?
|
||||
.is_some()
|
||||
{
|
||||
validation.push(ValidationFailureItem::Duplicate);
|
||||
}
|
||||
|
||||
|
|
@ -202,7 +210,11 @@ where
|
|||
Ok(new_booking)
|
||||
}
|
||||
|
||||
async fn delete(&self, id: Uuid, context: Authentication<Self::Context>) -> Result<(), ServiceError> {
|
||||
async fn delete(
|
||||
&self,
|
||||
id: Uuid,
|
||||
context: Authentication<Self::Context>,
|
||||
) -> Result<(), ServiceError> {
|
||||
self.permission_service
|
||||
.check_permission("hr", context)
|
||||
.await?;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use service::ServiceError;
|
||||
use service::permission::Authentication;
|
||||
use service::ServiceError;
|
||||
|
||||
pub struct PermissionServiceImpl<PermissionDao, UserService>
|
||||
where
|
||||
|
|
@ -82,9 +82,17 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn user_exists(&self, user: &str, context: Authentication<Self::Context>) -> Result<bool, ServiceError> {
|
||||
async fn user_exists(
|
||||
&self,
|
||||
user: &str,
|
||||
context: Authentication<Self::Context>,
|
||||
) -> Result<bool, ServiceError> {
|
||||
self.check_permission("hr", context).await?;
|
||||
Ok(self.permission_dao.find_user(user).await.map(|x| x.is_some())?)
|
||||
Ok(self
|
||||
.permission_dao
|
||||
.find_user(user)
|
||||
.await
|
||||
.map(|x| x.is_some())?)
|
||||
}
|
||||
|
||||
async fn get_all_users(
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ use std::sync::Arc;
|
|||
|
||||
use async_trait::async_trait;
|
||||
use dao::sales_person::SalesPersonEntity;
|
||||
use service::{permission::Authentication, sales_person::SalesPerson, ServiceError, ValidationFailureItem};
|
||||
use service::{
|
||||
permission::Authentication, sales_person::SalesPerson, ServiceError, ValidationFailureItem,
|
||||
};
|
||||
use uuid::Uuid;
|
||||
|
||||
pub struct SalesPersonServiceImpl<SalesPersonDao, PermissionService, ClockService, UuidService>
|
||||
|
|
@ -86,7 +88,11 @@ where
|
|||
.ok_or(ServiceError::EntityNotFound(id))
|
||||
}
|
||||
|
||||
async fn exists(&self, id: Uuid, _context: Authentication<Self::Context>) -> Result<bool, ServiceError> {
|
||||
async fn exists(
|
||||
&self,
|
||||
id: Uuid,
|
||||
_context: Authentication<Self::Context>,
|
||||
) -> Result<bool, ServiceError> {
|
||||
Ok(self
|
||||
.sales_person_dao
|
||||
.find_by_id(id)
|
||||
|
|
@ -172,7 +178,11 @@ where
|
|||
Ok(sales_person)
|
||||
}
|
||||
|
||||
async fn delete(&self, id: Uuid, context: Authentication<Self::Context>) -> Result<(), ServiceError> {
|
||||
async fn delete(
|
||||
&self,
|
||||
id: Uuid,
|
||||
context: Authentication<Self::Context>,
|
||||
) -> Result<(), ServiceError> {
|
||||
self.permission_service
|
||||
.check_permission("hr", context)
|
||||
.await?;
|
||||
|
|
@ -197,7 +207,10 @@ where
|
|||
self.permission_service
|
||||
.check_permission("hr", context)
|
||||
.await?;
|
||||
Ok(self.sales_person_dao.get_assigned_user(sales_person_id).await?)
|
||||
Ok(self
|
||||
.sales_person_dao
|
||||
.get_assigned_user(sales_person_id)
|
||||
.await?)
|
||||
}
|
||||
|
||||
async fn set_user(
|
||||
|
|
@ -216,7 +229,6 @@ where
|
|||
self.sales_person_dao
|
||||
.assign_to_user(sales_person_id, user.as_ref(), SALES_PERSON_SERVICE_PROCESS)
|
||||
.await?;
|
||||
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,10 @@ where
|
|||
{
|
||||
type Context = PermissionService::Context;
|
||||
|
||||
async fn get_slots(&self, context: Authentication<Self::Context>) -> Result<Arc<[Slot]>, ServiceError> {
|
||||
async fn get_slots(
|
||||
&self,
|
||||
context: Authentication<Self::Context>,
|
||||
) -> Result<Arc<[Slot]>, ServiceError> {
|
||||
let (hr_permission, sales_permission) = join!(
|
||||
self.permission_service
|
||||
.check_permission("hr", context.clone()),
|
||||
|
|
@ -76,7 +79,11 @@ where
|
|||
.map(Slot::from)
|
||||
.collect())
|
||||
}
|
||||
async fn get_slot(&self, id: &Uuid, context: Authentication<Self::Context>) -> Result<Slot, ServiceError> {
|
||||
async fn get_slot(
|
||||
&self,
|
||||
id: &Uuid,
|
||||
context: Authentication<Self::Context>,
|
||||
) -> Result<Slot, ServiceError> {
|
||||
let (hr_permission, sales_permission) = join!(
|
||||
self.permission_service
|
||||
.check_permission("hr", context.clone()),
|
||||
|
|
@ -92,11 +99,19 @@ where
|
|||
Ok(slot)
|
||||
}
|
||||
|
||||
async fn exists(&self, id: Uuid, _context: Authentication<Self::Context>) -> Result<bool, ServiceError> {
|
||||
async fn exists(
|
||||
&self,
|
||||
id: Uuid,
|
||||
_context: Authentication<Self::Context>,
|
||||
) -> Result<bool, ServiceError> {
|
||||
Ok(self.slot_dao.get_slot(&id).await.map(|s| s.is_some())?)
|
||||
}
|
||||
|
||||
async fn create_slot(&self, slot: &Slot, context: Authentication<Self::Context>) -> Result<Slot, ServiceError> {
|
||||
async fn create_slot(
|
||||
&self,
|
||||
slot: &Slot,
|
||||
context: Authentication<Self::Context>,
|
||||
) -> Result<Slot, ServiceError> {
|
||||
self.permission_service
|
||||
.check_permission("hr", context.clone())
|
||||
.await?;
|
||||
|
|
@ -137,7 +152,11 @@ where
|
|||
Ok(slot)
|
||||
}
|
||||
|
||||
async fn delete_slot(&self, id: &Uuid, context: Authentication<Self::Context>) -> Result<(), ServiceError> {
|
||||
async fn delete_slot(
|
||||
&self,
|
||||
id: &Uuid,
|
||||
context: Authentication<Self::Context>,
|
||||
) -> Result<(), ServiceError> {
|
||||
self.permission_service
|
||||
.check_permission("hr", context)
|
||||
.await?;
|
||||
|
|
@ -152,7 +171,11 @@ where
|
|||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
async fn update_slot(&self, slot: &Slot, context: Authentication<Self::Context>) -> Result<(), ServiceError> {
|
||||
async fn update_slot(
|
||||
&self,
|
||||
slot: &Slot,
|
||||
context: Authentication<Self::Context>,
|
||||
) -> Result<(), ServiceError> {
|
||||
self.permission_service
|
||||
.check_permission("hr", context)
|
||||
.await?;
|
||||
|
|
|
|||
|
|
@ -2,14 +2,16 @@ use crate::test::error_test::*;
|
|||
use dao::booking::{BookingEntity, MockBookingDao};
|
||||
use mockall::predicate::eq;
|
||||
use service::{
|
||||
booking::Booking, clock::MockClockService, sales_person::MockSalesPersonService, slot::MockSlotService, uuid_service::MockUuidService, MockPermissionService, ValidationFailureItem
|
||||
booking::Booking, clock::MockClockService, sales_person::MockSalesPersonService,
|
||||
slot::MockSlotService, uuid_service::MockUuidService, MockPermissionService,
|
||||
ValidationFailureItem,
|
||||
};
|
||||
use time::{Date, Month, PrimitiveDateTime, Time};
|
||||
use uuid::{uuid, Uuid};
|
||||
|
||||
use super::error_test::NoneTypeExt;
|
||||
use crate::booking::BookingServiceImpl;
|
||||
use service::booking::BookingService;
|
||||
use super::error_test::NoneTypeExt;
|
||||
|
||||
pub fn default_id() -> Uuid {
|
||||
uuid!("CEA260A0-112B-4970-936C-F7E529955BD0")
|
||||
|
|
@ -94,7 +96,9 @@ impl BookingServiceDependencies {
|
|||
|
||||
pub fn build_dependencies(permission: bool, role: &'static str) -> BookingServiceDependencies {
|
||||
let mut booking_dao = MockBookingDao::new();
|
||||
booking_dao.expect_find_by_booking_data().returning(|_, _, _, _| Ok(None));
|
||||
booking_dao
|
||||
.expect_find_by_booking_data()
|
||||
.returning(|_, _, _, _| Ok(None));
|
||||
let mut permission_service = MockPermissionService::new();
|
||||
permission_service
|
||||
.expect_check_permission()
|
||||
|
|
@ -357,7 +361,12 @@ async fn test_create_booking_data_already_exists() {
|
|||
deps.booking_dao.checkpoint();
|
||||
deps.booking_dao
|
||||
.expect_find_by_booking_data()
|
||||
.with(eq(default_sales_person_id()), eq(default_slot_id()), eq(3), eq(2024))
|
||||
.with(
|
||||
eq(default_sales_person_id()),
|
||||
eq(default_slot_id()),
|
||||
eq(3),
|
||||
eq(2024),
|
||||
)
|
||||
.returning(|_, _, _, _| Ok(Some(default_booking_entity())));
|
||||
let service = deps.build_service();
|
||||
let result = service
|
||||
|
|
@ -371,12 +380,7 @@ async fn test_create_booking_data_already_exists() {
|
|||
().auth(),
|
||||
)
|
||||
.await;
|
||||
test_validation_error(
|
||||
&result,
|
||||
&ValidationFailureItem::Duplicate,
|
||||
1,
|
||||
);
|
||||
|
||||
test_validation_error(&result, &ValidationFailureItem::Duplicate, 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
|
|
|||
|
|
@ -122,5 +122,4 @@ impl NoneTypeExt for () {
|
|||
fn auth(&self) -> Authentication<()> {
|
||||
Authentication::Context(())
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,9 @@ async fn test_check_permission() {
|
|||
|
||||
let permission_service =
|
||||
PermissionServiceImpl::new(Arc::new(permission_dao), Arc::new(user_service));
|
||||
let result = permission_service.check_permission("hello", ().auth()).await;
|
||||
let result = permission_service
|
||||
.check_permission("hello", ().auth())
|
||||
.await;
|
||||
result.expect("Expected successful authorization");
|
||||
}
|
||||
|
||||
|
|
@ -40,7 +42,9 @@ async fn test_check_permission_denied() {
|
|||
|
||||
let permission_service =
|
||||
PermissionServiceImpl::new(Arc::new(permission_dao), Arc::new(user_service));
|
||||
let result = permission_service.check_permission("hello", ().auth()).await;
|
||||
let result = permission_service
|
||||
.check_permission("hello", ().auth())
|
||||
.await;
|
||||
test_forbidden(&result);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -527,7 +527,10 @@ async fn test_exists() {
|
|||
.with(eq(default_id()))
|
||||
.returning(|_| Ok(Some(default_sales_person_entity())));
|
||||
let sales_person_service = dependencies.build_service();
|
||||
let result = sales_person_service.exists(default_id(), ().auth()).await.unwrap();
|
||||
let result = sales_person_service
|
||||
.exists(default_id(), ().auth())
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(result);
|
||||
|
||||
let mut dependencies = build_dependencies(true, "hr");
|
||||
|
|
@ -537,6 +540,9 @@ async fn test_exists() {
|
|||
.expect_find_by_id()
|
||||
.with(eq(default_id()))
|
||||
.returning(|_| Ok(None));
|
||||
let result = sales_person_service.exists(default_id(), ().auth()).await.unwrap();
|
||||
let result = sales_person_service
|
||||
.exists(default_id(), ().auth())
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(false, !result);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -257,7 +257,9 @@ async fn test_create_slot() {
|
|||
async fn test_create_slot_no_permission() {
|
||||
let dependencies = build_dependencies(false, "hr");
|
||||
let slot_service = dependencies.build_service();
|
||||
let result = slot_service.create_slot(&generate_default_slot(), ().auth()).await;
|
||||
let result = slot_service
|
||||
.create_slot(&generate_default_slot(), ().auth())
|
||||
.await;
|
||||
test_forbidden(&result);
|
||||
}
|
||||
|
||||
|
|
@ -568,7 +570,9 @@ async fn test_delete_slot_not_found() {
|
|||
async fn test_update_slot_no_permission() {
|
||||
let dependencies = build_dependencies(false, "hr");
|
||||
let slot_service = dependencies.build_service();
|
||||
let result = slot_service.update_slot(&generate_default_slot(), ().auth()).await;
|
||||
let result = slot_service
|
||||
.update_slot(&generate_default_slot(), ().auth())
|
||||
.await;
|
||||
test_forbidden(&result);
|
||||
}
|
||||
|
||||
|
|
@ -582,7 +586,9 @@ async fn test_update_slot_not_found() {
|
|||
.times(1)
|
||||
.returning(|_| Ok(None));
|
||||
let slot_service = dependencies.build_service();
|
||||
let result = slot_service.update_slot(&generate_default_slot(), ().auth()).await;
|
||||
let result = slot_service
|
||||
.update_slot(&generate_default_slot(), ().auth())
|
||||
.await;
|
||||
test_not_found(&result, &default_id());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue