-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: manage date format in user preferences (monicahq/chandler#37)
- Loading branch information
Showing
24 changed files
with
513 additions
and
45 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
27 changes: 27 additions & 0 deletions
27
app/Http/Controllers/Settings/Preferences/PreferencesDateFormatController.php
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,27 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Settings\Preferences; | ||
|
||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Controller; | ||
use Illuminate\Support\Facades\Auth; | ||
use App\Services\User\StoreDateFormatPreference; | ||
use App\Http\Controllers\Settings\Preferences\ViewHelpers\PreferencesIndexViewHelper; | ||
|
||
class PreferencesDateFormatController extends Controller | ||
{ | ||
public function store(Request $request) | ||
{ | ||
$data = [ | ||
'account_id' => Auth::user()->account_id, | ||
'author_id' => Auth::user()->id, | ||
'date_format' => $request->input('dateFormat'), | ||
]; | ||
|
||
$user = (new StoreDateFormatPreference)->execute($data); | ||
|
||
return response()->json([ | ||
'data' => PreferencesIndexViewHelper::dtoDateFormat($user), | ||
], 200); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
app/Http/Controllers/Settings/Preferences/PreferencesNameOrderController.php
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,27 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Settings\Preferences; | ||
|
||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Controller; | ||
use Illuminate\Support\Facades\Auth; | ||
use App\Services\User\StoreNameOrderPreference; | ||
use App\Http\Controllers\Settings\Preferences\ViewHelpers\PreferencesIndexViewHelper; | ||
|
||
class PreferencesNameOrderController extends Controller | ||
{ | ||
public function store(Request $request) | ||
{ | ||
$data = [ | ||
'account_id' => Auth::user()->account_id, | ||
'author_id' => Auth::user()->id, | ||
'name_order' => $request->input('nameOrder'), | ||
]; | ||
|
||
$user = (new StoreNameOrderPreference)->execute($data); | ||
|
||
return response()->json([ | ||
'data' => PreferencesIndexViewHelper::dtoNameOrder($user), | ||
], 200); | ||
} | ||
} |
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
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,60 @@ | ||
<?php | ||
|
||
namespace App\Services\User; | ||
|
||
use App\Models\User; | ||
use App\Services\BaseService; | ||
use App\Interfaces\ServiceInterface; | ||
|
||
class StoreDateFormatPreference extends BaseService implements ServiceInterface | ||
{ | ||
private array $data; | ||
|
||
/** | ||
* Get the validation rules that apply to the service. | ||
* | ||
* @return array | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'account_id' => 'required|integer|exists:accounts,id', | ||
'author_id' => 'required|integer|exists:users,id', | ||
'date_format' => 'required|string|max:255', | ||
]; | ||
} | ||
|
||
/** | ||
* Get the permissions that apply to the user calling the service. | ||
* | ||
* @return array | ||
*/ | ||
public function permissions(): array | ||
{ | ||
return [ | ||
'author_must_belong_to_account', | ||
]; | ||
} | ||
|
||
/** | ||
* Store date format preferences for the given user. | ||
* | ||
* @param array $data | ||
* @return User | ||
*/ | ||
public function execute(array $data): User | ||
{ | ||
$this->data = $data; | ||
|
||
$this->validateRules($data); | ||
$this->updateUser(); | ||
|
||
return $this->author; | ||
} | ||
|
||
private function updateUser(): void | ||
{ | ||
$this->author->date_format = $this->data['date_format']; | ||
$this->author->save(); | ||
} | ||
} |
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
Oops, something went wrong.