-
Notifications
You must be signed in to change notification settings - Fork 0
feat(customer): implement Customer repository #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
4e3bd44
52ca39c
c1c4434
c191ad3
37099e8
32e39ff
6a557aa
34a40ba
10482bb
902ad3e
f555457
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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, | ||
| 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 | ||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| } | ||
| } |
This file was deleted.
This file was deleted.
| 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, | ||
|
||
| public readonly address: CustomerAddress, | ||
| ) { } | ||
| } | ||
| 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 | ||
| ) { } | ||
| } |
| 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 | ||
| ) { } | ||
| } |
| 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 | ||
| ) { } | ||
| } |
| 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 { | ||
|
||
| 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); | ||
| }) | ||
| } | ||
| } | ||
| 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 { | ||
|
||
| 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); | ||
| }) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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