Added services
This commit moves most controller logic onto Services. Services are part of the Service-Repository pattern. The models act as repositories. Services are easily testable and are needed for the upcoming API, in order to avoid duplicated code and to maintain a single source of "truth". The User, Vacancy and Vote controllers still need their logic moved onto services.
This commit is contained in:
36
app/Services/MeetingNoteService.php
Normal file
36
app/Services/MeetingNoteService.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
|
||||
use App\Application;
|
||||
use App\Exceptions\InvalidAppointmentException;
|
||||
|
||||
class MeetingNoteService
|
||||
{
|
||||
/**
|
||||
* Adds meeting notes to an application.
|
||||
*
|
||||
* @param Application $application
|
||||
* @param $noteText
|
||||
* @return bool
|
||||
* @throws InvalidAppointmentException Thrown when an application doesn't have an appointment to save notes to
|
||||
*/
|
||||
public function addToApplication(Application $application, $noteText): bool {
|
||||
|
||||
if (! is_null($application)) {
|
||||
$application->load('appointment');
|
||||
|
||||
$application->appointment->meetingNotes = $noteText;
|
||||
$application->appointment->save();
|
||||
|
||||
return true;
|
||||
|
||||
} else {
|
||||
throw new InvalidAppointmentException('There\'s no appointment to save notes to!');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user