Skip to content

Commit

Permalink
Merge pull request #421 from BinaryStudioAcademy/develop
Browse files Browse the repository at this point in the history
0.5.0
  • Loading branch information
lenchvolodymyr authored Sep 9, 2020
2 parents 2bd0f3a + b872c29 commit 3ef278a
Show file tree
Hide file tree
Showing 21 changed files with 187 additions and 127 deletions.
1 change: 1 addition & 0 deletions api/app/Actions/Event/AddEventAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function execute(AddEventRequest $request): UpdateEventResponse
$event->invitee_email = $request->getInviteeEmail();
$event->start_date = $request->getStartDate();
$event->timezone = $request->getTimezone();
$event->invitee_information = $request->getInviteeInformation();

$this->eventRepository->save($event);

Expand Down
10 changes: 9 additions & 1 deletion api/app/Actions/Event/AddEventRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,24 @@ final class AddEventRequest
private string $startDate;
private string $timezone;
private ?array $customFieldValues;
private ?string $inviteeInformation;

public function __construct(
int $eventTypeId,
string $inviteeName,
string $inviteeEmail,
string $startDate,
string $timezone,
?array $customFieldValues
?array $customFieldValues,
?string $inviteeInformation
) {
$this->eventTypeId = $eventTypeId;
$this->inviteeName = $inviteeName;
$this->inviteeEmail = $inviteeEmail;
$this->startDate = $startDate;
$this->timezone = $timezone;
$this->customFieldValues = $customFieldValues;
$this->inviteeInformation = $inviteeInformation;
}

public function getEventTypeId(): int
Expand Down Expand Up @@ -58,4 +61,9 @@ public function getCustomFieldValues(): ?array
{
return $this->customFieldValues;
}

public function getInviteeInformation(): ?string
{
return $this->inviteeInformation;
}
}
2 changes: 1 addition & 1 deletion api/app/Actions/SocialAccount/AuthResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class AuthResponse
{
private string $urt;
private string $url;
private ?array $data;

public function __construct(string $url, array $data = [])
Expand Down
3 changes: 2 additions & 1 deletion api/app/Entity/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class Event extends Model
'timezone',
'status',
'location',
'created_at'
'created_at',
'invitee_information'
];

protected $attributes = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

final class CoordinatesFieldIsRequiredException extends BaseException
{
protected $message = "For 'location_type = address' field 'coordinates' is required!";
protected $message = "Please, choose address for your meeting";
protected $code = ErrorCode::COORDINATES_FIELD_IS_REQUIRED;
}
3 changes: 2 additions & 1 deletion api/app/Http/Controllers/Api/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public function store(EventRequest $request): JsonResponse
$request->invitee_email,
$request->start_date,
$request->timezone,
$request->custom_field_values
$request->custom_field_values,
$request->invitee_information
)
);

Expand Down
36 changes: 36 additions & 0 deletions api/app/Jobs/SendNotificationToOwnerChatito.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Jobs;

use App\Entity\Event;
use App\Notifications\EventCreatedNotificationToOwnerChatito;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class SendNotificationToOwnerChatito implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;

private Event $event;

public function __construct(Event $event)
{
$this->event = $event;
}

/**
* Execute the job.
*
* @return void
*/
public function handle()
{
new EventCreatedNotificationToOwnerChatito($this->event);
}
}
14 changes: 11 additions & 3 deletions api/app/Listeners/SendEventCreatedNotificationToOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace App\Listeners;

use App\Events\EventCreated;
use App\Notifications\EventCreatedNotification;
use App\Jobs\SendNotificationToOwnerChatito;
use App\Notifications\EventCreatedNotificationToOwnerChatito;
use App\Notifications\EventCreatedNotificationToOwnerMail;
use App\Notifications\EventCreatedNotificationToOwnerSlack;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

class SendEventCreatedNotificationToOwner implements ShouldQueue
{
Expand All @@ -26,6 +28,12 @@ public function __construct()
*/
public function handle(EventCreated $eventCreated)
{
$eventCreated->event->eventType->owner->notify(new EventCreatedNotification($eventCreated->event));
$eventCreated->event->eventType->owner->notify(new EventCreatedNotificationToOwnerMail($eventCreated->event));
if ($eventCreated->event->eventType->owner->slack_active) {
$eventCreated->event->eventType->owner->notify(new EventCreatedNotificationToOwnerSlack($eventCreated->event));
}
if ($eventCreated->event->eventType->owner->chatito_active) {
SendNotificationToOwnerChatito::dispatch($eventCreated->event);
}
}
}
3 changes: 1 addition & 2 deletions api/app/Mail/EventCreatedMailToInvitee.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public function build()
'owner' => $this->owner,
'inviteeName' => $this->inviteeName,
'inviteeEmail' => $this->inviteeEmail,
'customFieldValues' => $this->event->customFieldValues,
'location' => $this->event->location
'customFieldValues' => $this->event->customFieldValues
]);
}
}
13 changes: 1 addition & 12 deletions api/app/Mail/EventCreatedMailToOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,13 @@ class EventCreatedMailToOwner extends Mailable
public EventType $eventType;
public User $owner;

/**
* Create a new message instance.
*
* @return void
*/
public function __construct(Event $event)
{
$this->event = $event;
$this->eventType = $event->eventType;
$this->owner = $event->eventType->owner;
}

/**
* Build the message.
*
* @return $this
*/
public function build()
{
$this->to($this->owner->getEmail());
Expand All @@ -47,8 +37,7 @@ public function build()
'event' => $this->event,
'eventType' => $this->eventType,
'user' => $this->owner,
'customFieldValues' => $this->event->customFieldValues,
'location' => $this->event->location
'customFieldValues' => $this->event->customFieldValues
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function generateMessage()
"{$this->user->name}<br><br>" .
"<b>Organizator Email:</b><br>" .
"{$this->user->email}<br><br>" .
"<b>Event Date/Time:</b><br>" .
"<b>Event Date/Time (UTC):</b><br>" .
"{$this->event->start_date}<br><br>";

if ($this->event->eventType->location_type == 'zoom') {
Expand Down
8 changes: 2 additions & 6 deletions api/app/Notifications/Chatito/EventCreatedChatitoMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ final class EventCreatedChatitoMessage extends ChatitoMessage
{
protected function generateMessage()
{
$message = "Hi, <b>{$this->event->invitee_name}</b> and <b>{$this->user->name}</b><br>" .
return "Hi, <b>{$this->event->invitee_name}</b> and <b>{$this->user->name}</b><br>" .
"A new event was scheduled!<br><br>" .
"<b>Event Type:</b><br>" .
"{$this->eventType->name}<br><br>" .
Expand All @@ -22,11 +22,7 @@ protected function generateMessage()
"{$this->user->name}<br><br>" .
"<b>Organizator Email:</b><br>" .
"{$this->user->email}<br><br>" .
"<b>Event Date/Time:</b><br>" .
"<b>Event Date/Time (UTC):</b><br>" .
"{$this->event->start_date}<br>";
if ($this->event->location) {
$message .= "<b>Location:</b><br>{$this->event->location}<br>";
}
return $message;
}
}
82 changes: 0 additions & 82 deletions api/app/Notifications/EventCreatedNotification.php

This file was deleted.

36 changes: 36 additions & 0 deletions api/app/Notifications/EventCreatedNotificationToOwnerChatito.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Notifications;

use App\Entity\Event;
use App\Entity\EventType;
use App\Entity\User;
use App\Notifications\Chatito\EventCreatedChatitoMessage;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;

class EventCreatedNotificationToOwnerChatito extends Notification implements ShouldQueue
{
use Queueable;

private Event $event;

public function __construct(Event $event)
{
$this->event = $event;
$this->toChatito();
}

private function toChatito()
{
return new EventCreatedChatitoMessage($this->event);
}

public function toArray($notifiable)
{
return [
//
];
}
}
38 changes: 38 additions & 0 deletions api/app/Notifications/EventCreatedNotificationToOwnerMail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Notifications;

use App\Entity\Event;
use App\Mail\EventCreatedMailToOwner;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;

class EventCreatedNotificationToOwnerMail extends Notification implements ShouldQueue
{
use Queueable;

private Event $event;

public function __construct(Event $event)
{
$this->event = $event;
}

public function via($notifiable)
{
return ['mail'];
}

public function toMail($notifiable)
{
return new EventCreatedMailToOwner($this->event);
}

public function toArray($notifiable)
{
return [
//
];
}
}
Loading

0 comments on commit 3ef278a

Please sign in to comment.