-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add dicebear avatars to app #7457
Open
Laurell876
wants to merge
11
commits into
monicahq:main
Choose a base branch
from
Laurell876:feat/add-dicebear-avatars
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
485ebcc
feat, show preview of avatar style
Laurell876 a9d1df9
feat, implement dicebear avatar logic
Laurell876 3f8f77f
feat, add all current art styles
Laurell876 b247b0b
fix, remove todos
Laurell876 a032094
fix: remove else
Laurell876 435bae7
feat: add service test
Laurell876 aa0b5ff
fix: remove new avatar type
Laurell876 9da17d2
test: update helper test
Laurell876 fc9d613
Merge branch 'main' into feat/add-dicebear-avatars
Laurell876 8967a0f
Merge branch 'main' into feat/add-dicebear-avatars
asbiin 48b99bd
Merge branch 'main' into feat/add-dicebear-avatars
asbiin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
app/Domains/Settings/ManageUserPreferences/Services/StoreAvatarStylePreference.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,53 @@ | ||
<?php | ||
|
||
namespace App\Domains\Settings\ManageUserPreferences\Services; | ||
|
||
use App\Models\User; | ||
use App\Services\BaseService; | ||
|
||
class StoreAvatarStylePreference extends BaseService | ||
{ | ||
private array $data; | ||
|
||
/** | ||
* Get the validation rules that apply to the service. | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'account_id' => 'required|uuid|exists:accounts,id', | ||
'author_id' => 'required|uuid|exists:users,id', | ||
'avatar_style' => 'nullable|string', | ||
]; | ||
} | ||
|
||
/** | ||
* Get the permissions that apply to the user calling the service. | ||
*/ | ||
public function permissions(): array | ||
{ | ||
return [ | ||
'author_must_belong_to_account', | ||
]; | ||
} | ||
|
||
/** | ||
* Saves the avatar style preferences. | ||
* Determines which dicebear style is used to generate avatar's across the app for this user. | ||
*/ | ||
public function execute(array $data): User | ||
{ | ||
$this->data = $data; | ||
|
||
$this->validateRules($data); | ||
$this->updateUser(); | ||
|
||
return $this->author; | ||
} | ||
|
||
private function updateUser(): void | ||
{ | ||
$this->author->avatar_style = $this->data['avatar_style']; | ||
$this->author->save(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...mains/Settings/ManageUserPreferences/Web/Controllers/PreferencesAvatarStyleController.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\Domains\Settings\ManageUserPreferences\Web\Controllers; | ||
|
||
use App\Domains\Settings\ManageUserPreferences\Services\StoreAvatarStylePreference; | ||
use App\Domains\Settings\ManageUserPreferences\Web\ViewHelpers\UserPreferencesIndexViewHelper; | ||
use App\Http\Controllers\Controller; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class PreferencesAvatarStyleController extends Controller | ||
{ | ||
public function store(Request $request) | ||
{ | ||
$request = [ | ||
'account_id' => Auth::user()->account_id, | ||
'author_id' => Auth::id(), | ||
'avatar_style' => $request->input('avatarStyle'), | ||
]; | ||
|
||
(new StoreAvatarStylePreference)->execute($request); | ||
|
||
return response()->json([ | ||
'data' => UserPreferencesIndexViewHelper::dtoAvatarStyle(Auth::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
28 changes: 28 additions & 0 deletions
28
database/migrations/2024_11_14_225521_add_avatar_style_to_users.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,28 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::table('users', function (Blueprint $table) { | ||
$table->string('avatar_style')->nullable()->after('help_shown'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::table('users', function (Blueprint $table) { | ||
$table->dropColumn('avatar_style'); | ||
}); | ||
} | ||
}; |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we use the id (uuid) so it's always the same for one contact?