Miguel N
8942623bde
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.
51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?php
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
use App\Exceptions\ProfileNotFoundException;
|
|
use App\User;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class ProfileService
|
|
{
|
|
|
|
/**
|
|
* @throws ProfileNotFoundException
|
|
*/
|
|
public function updateProfile($userID, Request $request) {
|
|
$profile = User::find($userID)->profile;
|
|
$social = [];
|
|
|
|
if (! is_null($profile)) {
|
|
switch ($request->avatarPref) {
|
|
case 'MOJANG':
|
|
$avatarPref = 'crafatar';
|
|
|
|
break;
|
|
case 'GRAVATAR':
|
|
$avatarPref = strtolower($request->avatarPref);
|
|
|
|
break;
|
|
}
|
|
|
|
$social['links']['github'] = $request->socialGithub;
|
|
$social['links']['twitter'] = $request->socialTwitter;
|
|
$social['links']['insta'] = $request->socialInsta;
|
|
$social['links']['discord'] = $request->socialDiscord;
|
|
|
|
$profile->profileShortBio = $request->shortBio;
|
|
$profile->profileAboutMe = $request->aboutMe;
|
|
$profile->avatarPreference = $avatarPref;
|
|
$profile->socialLinks = json_encode($social);
|
|
|
|
return $profile->save();
|
|
}
|
|
|
|
throw new ProfileNotFoundException("This profile does not exist.");
|
|
}
|
|
|
|
}
|