Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Dealer } from "../../../../domain/inventoryManagement/entities/Dealer";
import { DealerAddress } from "../../../../domain/inventoryManagement/value-object/DealerAddress";
import { DealerAddress } from "../../../../domain/maintenance/value-object/DealerAddress";
import { Siret } from '../../../../domain/shared/value-object/Siret';
import { IInputUseCase, IUseCase } from "../../../../shared/IUseCase";
import { Result } from "../../../../shared/Result";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Customer } from "../../../domain/maintenance/entities/Customer";
import { VehicleImmatriculation } from "../../../domain/shared/value-object/VehicleImmatriculation";
import { IRepository } from "../../../shared/IRepository";
import { Result, VoidResult } from "../../../shared/Result";

export interface CustomerRepository extends IRepository {
find(vehiculeImmatriculation: VehicleImmatriculation): Promise<Result<Customer>>;
store(customer: Customer): Promise<VoidResult>;
update(customer: Customer): Promise<VoidResult>;
delete(customer: Customer): Promise<VoidResult>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Garage } from '../../../domain/maintenance/entities/Garage';
import { Siret } from '../../../domain/shared/value-object/Siret';
import { IRepository } from '../../../shared/IRepository';
import { Result, VoidResult } from '../../../shared/Result';

export interface GarageRepository extends IRepository {
getBySiret(siret: Siret): Promise<Result<Garage>>
store(garage: Garage): Promise<VoidResult>;
delete(siret: Siret): Promise<VoidResult>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { IInputUseCase, IUseCase } from "../../../../shared/IUseCase";
import { Result } from "../../../../shared/Result";
import { CustomerRepository } from "../../repositories/CustomerRepository";

interface DeleteCustomerUseCaseInput extends IInputUseCase {
id: string
}

export type DeleteCustomerUseCase = IUseCase<DeleteCustomerUseCaseInput, Result>
export const deleteCustomerUseCase = (_customerRepository: CustomerRepository): DeleteCustomerUseCase => {
return async (input: DeleteCustomerUseCaseInput) => {
const deleteResponse = await _customerRepository.delete(input.id);
if (!deleteResponse.success) return Result.FailureStr("Cannot delete customer")
return Result.Success("Customer deleted")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Customer } from "../../../../domain/maintenance/entities/Customer";
import { CustomerAddress } from "../../../../domain/maintenance/value-object/CustomerAddress";
import { VehicleImmatriculation } from "../../../../domain/shared/value-object/VehicleImmatriculation";
import { IInputUseCase, IUseCase } from "../../../../shared/IUseCase";
import { Result } from "../../../../shared/Result";
import { CustomerRepository } from "../../repositories/CustomerRepository";

interface RegisterCustomerInput extends IInputUseCase {
id: string,
name: string,
phoneNumber: string,
email: string
vehiculeImmatrictulation: VehicleImmatriculation,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pareil ici tu dépends trop du véhicule pour le customer

address: CustomerAddress
}

export type RegisterCustomerUseCase = IUseCase<RegisterCustomerInput, Result>
export const registerCustomerUseCase = (_customerRepository: CustomerRepository): RegisterCustomerUseCase => {
return async (input: RegisterCustomerInput) => {
const customer = new Customer(
input.id,
input.name,
input.phoneNumber,
input.email,
input.vehiculeImmatrictulation,
input.address
);
const storeResponse = await _customerRepository.store(customer);
if (!storeResponse.success) return Result.FailureStr("Cannot register customer")
return Result.Success("Customer registered")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Customer } from '../../../../domain/maintenance/entities/Customer';
import { VehicleImmatriculation } from '../../../../domain/shared/value-object/VehicleImmatriculation';
import { IInputUseCase, IUseCase } from "../../../../shared/IUseCase";
import { Result } from '../../../../shared/Result';
import { CustomerRepository } from '../../repositories/CustomerRepository';

interface ShowCustomerInput extends IInputUseCase {
VehicleImmatriculation: VehicleImmatriculation
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmm c'est etrange ca il fautdrait un uuid sur le customer plutot ou le DriverLicense


type ShowCustomerResult = Result<Customer>
export type ShowCustomerUseCase = IUseCase<ShowCustomerInput, ShowCustomerResult>
export const showCustomerUseCase = (_customerRepository: CustomerRepository): ShowCustomerUseCase => {
return async (input: ShowCustomerInput) => {
const findResponse = await _customerRepository.find(input.VehicleImmatriculation);
if (!findResponse.success) return Result.FailureStr("Customer not found")
return findResponse
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Siret } from "../../../../domain/shared/value-object/Siret";
import { IInputUseCase, IUseCase } from "../../../../shared/IUseCase";
import { Result } from "../../../../shared/Result";
import { GarageRepository } from "../../repositories/GarageRepository";

interface DeleteGarageInput extends IInputUseCase {
siret: Siret,
}

export type DeleteGarageUseCase = IUseCase<DeleteGarageInput, Result>
export const deleteGarageUseCase = (_garageRepository: GarageRepository): DeleteGarageUseCase => {

// @TODO : Add logic to delete the link with a Dealer if exist

return async (input: DeleteGarageInput) => {
const deleteResponse = await _garageRepository.delete(input.siret)
if (!deleteResponse.success) return Result.FailureStr("Cannot delete garage")
return Result.Success("Garage deleted")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Garage } from '../../../../domain/maintenance/entities/Garage';
import { Siret } from '../../../../domain/shared/value-object/Siret';
import { IInputUseCase, IUseCase } from '../../../../shared/IUseCase';
import { Result } from '../../../../shared/Result';
import { GarageRepository } from '../../maintenance/GarageRepository';

interface RegisterGarageInput extends IInputUseCase {
siret: Siret,
name: string,
phoneNumber: string,
}

export type RegisterGarageUseCase = IUseCase<RegisterGarageInput, Result>
export const registerGarageUseCAse = (_garageRepository: GarageRepository): RegisterGarageUseCase => {
return async (input: RegisterGarageInput) => {
const garage = new Garage(
input.siret,
input.name,
input.phoneNumber,
);
const storeResponse = await _garageRepository.store(garage);
if (!storeResponse.success) return Result.FailureStr("Cannot register garage");
return Result.Success("Garage Registered");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Garage } from "../../../../domain/maintenance/entities/Garage";
import { Siret } from '../../../../domain/shared/value-object/Siret';
import { IInputUseCase, IUseCase } from "../../../../shared/IUseCase";
import { Result } from "../../../../shared/Result";
import { GarageRepository } from "../../maintenance/GarageRepository";

interface ShowGarageInput extends IInputUseCase {
siret: Siret
}

type ShowGarageResult = Result<Garage>
export type ShowGarageUseCase = IUseCase<ShowGarageInput, ShowGarageResult>
export const showGarageUseCase = (_garageRepository: GarageRepository): ShowGarageUseCase => {
return async (input: ShowGarageInput) => {
const findResponse = await _garageRepository.getBySiret(input.siret);
if (!findResponse.success) return Result.FailureStr("Garage not found")
return findResponse
}
}
2 changes: 1 addition & 1 deletion backend/src/domain/inventoryManagement/entities/Dealer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DealerAddress } from "../../maintenance/value-object/DealerAddress";
import { Siret } from "../../shared/value-object/Siret";
import { DealerAddress } from "../value-object/DealerAddress";

export class Dealer {
constructor(
Expand Down
3 changes: 0 additions & 3 deletions backend/src/domain/inventoryManagement/entities/Garage.ts

This file was deleted.

This file was deleted.

14 changes: 14 additions & 0 deletions backend/src/domain/maintenance/entities/Customer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { VehicleImmatriculation } from "../../shared/value-object/VehicleImmatriculation";
import { CustomerAddress } from "../value-object/CustomerAddress";


export class Customer {
constructor(
public readonly id: string,
public readonly name: string,
public readonly phoneNumber: string,
public readonly email: string,
public readonly vehiculeImmatrictulation: VehicleImmatriculation,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ne pas dépendre du véhicule

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le clients peut avior plusieurs véhicule

public readonly address: CustomerAddress,
) { }
}
11 changes: 11 additions & 0 deletions backend/src/domain/maintenance/entities/Garage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Siret } from "../../shared/value-object/Siret";
import { GarageAddress } from "../value-object/GarageAddress";

export class Garage {
constructor(
public readonly siret: Siret,
public readonly name: string,
public readonly phoneNumber: string,
public readonly address: GarageAddress,
) { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export class CustomerAddress {
constructor(
public readonly street: string,
public readonly city: string,
public readonly postalCode: string,
public readonly country: string
) { }
}
8 changes: 8 additions & 0 deletions backend/src/domain/maintenance/value-object/DealerAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export class DealerAddress {
constructor(
public readonly street: string,
public readonly city: string,
public readonly postalCode: string,
public readonly country: string
) { }
}
8 changes: 8 additions & 0 deletions backend/src/domain/maintenance/value-object/GarageAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export class GarageAddress {
constructor(
public readonly street: string,
public readonly city: string,
public readonly postalCode: string,
public readonly country: string
) { }
}
44 changes: 44 additions & 0 deletions backend/src/infrastructure/entityMappers/CustomerMapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Customer } from "../../domain/maintenance/entities/Customer";
import { CustomerAddress } from "../../domain/maintenance/value-object/CustomerAddress";
import { VehicleImmatriculation } from "../../domain/shared/value-object/VehicleImmatriculation";
import { MappedEntity } from "./MappedEntity";

export class CustomerMapper {
public static toPersistence(customer: Customer): MappedEntity {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementé les nouveau MappedEntity

return new MappedEntity({
id: customer.id,
name: customer.name,
email: customer.email,
phone_number: customer.phoneNumber,
address: customer.address,
})
}

public static toDomain(customer: any) {
return new Customer(
customer.id,
customer.name,
customer.phone_number,
customer.email,
new VehicleImmatriculation(customer.immatriculation),
new CustomerAddress(
customer.address.street,
customer.address.city,
customer.address.postalCode,
customer.address.country
)
)
}

public static toPersistenceList(customers: Customer[]): MappedEntity[] {
return customers.map(customer => {
return CustomerMapper.toPersistence(customer);
})
}

public static toDomainList(customers: any[]) {
return customers.map(customer => {
return CustomerMapper.toDomain(customer);
})
}
}
14 changes: 7 additions & 7 deletions backend/src/infrastructure/entityMappers/DriverMapper.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Driver} from "../../domain/testDrive/entities/Driver";
import {DriverLicenseId} from "../../domain/testDrive/value-object/DriverLicenseId";
import {MappedEntities, MappedEntity} from "./MappedEntity";
import { Driver } from "../../domain/testDrive/entities/Driver";
import { DriverLicenseId } from "../../domain/testDrive/value-object/DriverLicenseId";
import { MappedEntity } from "./MappedEntity";

export class DriverMapper{
public static toPersistence(driver: Driver) : MappedEntity {
export class DriverMapper {
public static toPersistence(driver: Driver): MappedEntity {
return new MappedEntity({
driver_licence_id: driver.driverLicenceId.getValue(),
first_name: driver.firstName,
Expand All @@ -12,7 +12,7 @@ export class DriverMapper{
driver_licensed_at: driver.driverLicensedAt,
})
}
public static toDomain(driver: any){
public static toDomain(driver: any) {
return new Driver(
new DriverLicenseId(driver.driver_licence_id),
driver.first_name,
Expand All @@ -28,7 +28,7 @@ export class DriverMapper{
return DriverMapper.toPersistence(driver);
}))
}
public static toDomainList(drivers: any[]){
public static toDomainList(drivers: any[]) {
return drivers.map(driver => {
return DriverMapper.toDomain(driver);
})
Expand Down
40 changes: 40 additions & 0 deletions backend/src/infrastructure/entityMappers/GarageMapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Garage } from "../../domain/maintenance/entities/Garage";
import { GarageAddress } from '../../domain/maintenance/value-object/GarageAddress';
import { MappedEntity } from "./MappedEntity";

export class GarageMapper {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pareil ici

public static toPersistence(garage: Garage): MappedEntity {
return new MappedEntity({
siret: garage.siret.getValue(),
name: garage.name,
phone_number: garage.phoneNumber,
address: garage.address,
})
}

public static toDomain(garage: any) {
return new Garage(
garage.siret,
garage.name,
garage.phone_number,
new GarageAddress(
garage.address.street,
garage.address.city,
garage.address.postalCode,
garage.address.country
)
)
}

public static toPersistenceList(garages: Garage[]): MappedEntity[] {
return garages.map(garage => {
return GarageMapper.toPersistence(garage);
})
}

public static toDomainList(garages: any[]) {
return garages.map(garage => {
return GarageMapper.toDomain(garage);
})
}
}
Loading