Last active
October 10, 2023 12:37
-
-
Save dyrkow/47387f985272de910f3d011194d0ec20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CookingOrder extends ValueObject { | |
// TODO: тут только те данные, которые нужны для работы в этом контексте | |
} | |
// Основная сущность, задача на готовку | |
class CookingRequest extends Aggregate { | |
id: Identifier; | |
orderId: Identifier; | |
positions: CookingRequestPosition[]; | |
merge(request: CookingRequest); // Метод позволит проще вычислять состояние | |
} | |
class CookingRequestPosition extends ValueObject { | |
product: ...; | |
quantity: Quantity; | |
polarity: + || -; | |
} | |
class CookingRequestService { | |
// Собирает состояние из предыдущих задач | |
getState(requests: CookingRequest[]) CookingRequest { | |
return requests.reduce(); | |
} | |
// Вычисляет разницу между текущим заказом и состоянием на кухне | |
getDiff(order: CookingOrder, state: CookingRequest): CookingRequest { | |
} | |
} | |
class CookingRequestRepository { | |
getAll(orderId: Identifier) {} | |
add(CookingRequest) {} | |
} | |
// Юзкейс позволяет сформировать задачу на готовку для кухни | |
// Если задачи нету, вернется предыдущая задача | |
class getCookingRequestForOrderUseCase implements UseCase { | |
execute(order: CookingOrderDTO): CookingRequest { | |
const requests = this.repository.getAll(order.id); | |
const state = CookingRequestService.getState(requests); | |
const diff = CookingRequestService.getDiff(order, state); | |
this.repository.add(diff); | |
return diff; | |
} | |
} | |
onClick = () => { | |
const useCase = container.get<getCookingRequestForOrderUseCase>(); | |
const cookingRequest = await useCase.execute(Order); | |
const printCommand = getPrintCommandFromCookingRequest(cookingRequest) | |
print(printCommand); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment