| @@ 20-71 (lines=52) @@ | ||
| 17 | use Gitamin\Models\Issue; |
|
| 18 | use Gitamin\Models\Project; |
|
| 19 | ||
| 20 | class AddIssueCommandHandler |
|
| 21 | { |
|
| 22 | /** |
|
| 23 | * The date factory instance. |
|
| 24 | * |
|
| 25 | * @var \Gitamin\Dates\DateFactory |
|
| 26 | */ |
|
| 27 | protected $dates; |
|
| 28 | ||
| 29 | /** |
|
| 30 | * Create a new report issue command handler instance. |
|
| 31 | * |
|
| 32 | * @param \Gitamin\Dates\DateFactory $dates |
|
| 33 | * |
|
| 34 | * @return void |
|
| 35 | */ |
|
| 36 | public function __construct(DateFactory $dates) |
|
| 37 | { |
|
| 38 | $this->dates = $dates; |
|
| 39 | } |
|
| 40 | ||
| 41 | /** |
|
| 42 | * Handle the report issue command. |
|
| 43 | * |
|
| 44 | * @param \Gitamin\Commands\Issue\AddIssueCommand $command |
|
| 45 | * |
|
| 46 | * @return \Gitamin\Models\Issue |
|
| 47 | */ |
|
| 48 | public function handle(AddIssueCommand $command) |
|
| 49 | { |
|
| 50 | $data = [ |
|
| 51 | 'title' => $command->title, |
|
| 52 | 'description' => $command->description, |
|
| 53 | ]; |
|
| 54 | ||
| 55 | // Link with the user. |
|
| 56 | if ($command->author_id) { |
|
| 57 | $data['author_id'] = $command->author_id; |
|
| 58 | } |
|
| 59 | // Link with the project. |
|
| 60 | if ($command->project_id) { |
|
| 61 | $data['project_id'] = $command->project_id; |
|
| 62 | } |
|
| 63 | ||
| 64 | // Create the issue |
|
| 65 | $issue = Issue::create($data); |
|
| 66 | ||
| 67 | event(new IssueWasAddedEvent($issue)); |
|
| 68 | ||
| 69 | return $issue; |
|
| 70 | } |
|
| 71 | } |
|
| 72 | ||
| @@ 20-72 (lines=53) @@ | ||
| 17 | use Gitamin\Models\Note; |
|
| 18 | use Gitamin\Models\Project; |
|
| 19 | ||
| 20 | class AddNoteCommandHandler |
|
| 21 | { |
|
| 22 | /** |
|
| 23 | * The date factory instance. |
|
| 24 | * |
|
| 25 | * @var \Gitamin\Dates\DateFactory |
|
| 26 | */ |
|
| 27 | protected $dates; |
|
| 28 | ||
| 29 | /** |
|
| 30 | * Create a new report issue command handler instance. |
|
| 31 | * |
|
| 32 | * @param \Gitamin\Dates\DateFactory $dates |
|
| 33 | * |
|
| 34 | * @return void |
|
| 35 | */ |
|
| 36 | public function __construct(DateFactory $dates) |
|
| 37 | { |
|
| 38 | $this->dates = $dates; |
|
| 39 | } |
|
| 40 | ||
| 41 | /** |
|
| 42 | * Handle the report note command. |
|
| 43 | * |
|
| 44 | * @param \Gitamin\Commands\Issue\AddIssueCommand $command |
|
| 45 | * |
|
| 46 | * @return \Gitamin\Models\Issue |
|
| 47 | */ |
|
| 48 | public function handle(AddNoteCommand $command) |
|
| 49 | { |
|
| 50 | $data = [ |
|
| 51 | 'description' => $command->description, |
|
| 52 | 'noteable_type' => $command->noteable_type, |
|
| 53 | 'noteable_id' => $command->noteable_id, |
|
| 54 | ]; |
|
| 55 | ||
| 56 | // Link with the user. |
|
| 57 | if ($command->author_id) { |
|
| 58 | $data['author_id'] = $command->author_id; |
|
| 59 | } |
|
| 60 | // Link with the project. |
|
| 61 | if ($command->project_id) { |
|
| 62 | $data['project_id'] = $command->project_id; |
|
| 63 | } |
|
| 64 | ||
| 65 | // Create the note |
|
| 66 | $note = Note::create($data); |
|
| 67 | ||
| 68 | event(new NoteWasAddedEvent($note)); |
|
| 69 | ||
| 70 | return $note; |
|
| 71 | } |
|
| 72 | } |
|
| 73 | ||