-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marco Sabatini
committed
Sep 10, 2024
1 parent
273e001
commit 1176f01
Showing
11 changed files
with
105 additions
and
43 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from app.command_handler.commands import TurnOff | ||
from app.ddd.basics import CommandHandler | ||
from app.domain.events import MarsRoverTurnedOff | ||
from app.domain.mars_rover import MarsRover | ||
from app.infrastructure.mars_rover_repository import InMemoryMarsRoverRepository | ||
|
||
|
||
class TurnOffCommandHandler(CommandHandler): | ||
def __init__(self, repo: InMemoryMarsRoverRepository): | ||
self.repo = repo | ||
|
||
def handle(self, command: TurnOff) -> MarsRoverTurnedOff: | ||
mars_rover: MarsRover = self.repo.get_by_id(command.id) | ||
event = mars_rover.turn_off() | ||
self.repo.save(mars_rover) | ||
|
||
return event |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
from app.command_handler.commands import NotifyObstacleHit | ||
from app.command_handler.commands import NotifyObstacleHit, TurnOff | ||
from app.ddd.basics import Policy, Command | ||
from app.domain.events import ObstacleHit | ||
|
||
|
||
class TurnOffObstacleHitPolicy(Policy): | ||
def apply(self, event: ObstacleHit) -> Command: | ||
return TurnOff(id=event.id) | ||
|
||
|
||
class NotifyObstacleHitPolicy(Policy): | ||
def apply(self, event: ObstacleHit) -> Command: | ||
return NotifyObstacleHit(message=f"Rover {event.id.value} hit obstacle") |
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
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
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
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