-
Notifications
You must be signed in to change notification settings - Fork 0
#7 - Activity history #30
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
Open
KacperWalenga
wants to merge
29
commits into
main
Choose a base branch
from
#7-Activity-history
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
29 commits
Select commit
Hold shift + click to select a range
6009c27
add api for profiles
KacperWalenga 152cc3b
Add avatars
KacperWalenga 960fc7b
code suggestions
KacperWalenga 9ec0bd8
update .env.ci
KacperWalenga 00251ac
tests
KacperWalenga b52fc36
tests
KacperWalenga e117983
tests
KacperWalenga 5b43c1c
tests
KacperWalenga 6f16baf
add activities
KacperWalenga 50e0f7b
Update app/Actions/Profile/UpdateProfileAction.php
KacperWalenga f4ffd46
Update app/Models/User.php
KacperWalenga aa24de1
Update database/migrations/0001_01_01_000000_create_users_table.php
KacperWalenga 5ee7dea
Update app/Actions/Avatars/ChangeAvatarAction.php
KacperWalenga 258dffd
fix birth_date
KacperWalenga 58e27a2
fix index profiles
KacperWalenga 1c14ed4
add activities
KacperWalenga 38f31bb
Merge remote-tracking branch 'origin/#7-Activity-history' into #7-Act…
KacperWalenga df0ec9a
Update app/Models/Activity.php
KacperWalenga ae5a997
fix route
KacperWalenga ae9068e
Update app/Actions/Activities/GetActivityPhotoAction.php
KacperWalenga a37765c
Merge remote-tracking branch 'origin/#7-Activity-history' into #7-Act…
KacperWalenga 8aed744
Update app/Models/Activity.php
KacperWalenga b96c517
Update app/Models/Activity.php
KacperWalenga 4d598b7
update Activity.php
KacperWalenga 222b54a
Merge remote-tracking branch 'origin/#7-Activity-history' into #7-Act…
KacperWalenga f5f4609
update ActivitiesController.php
KacperWalenga 07751c4
Update app/Http/Requests/StoreActivityRequest.php
KacperWalenga 60d3775
task fix
KacperWalenga c34a979
Merge remote-tracking branch 'origin/#7-Activity-history' into #7-Act…
KacperWalenga 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,26 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Strava\Actions\Activities; | ||
|
|
||
| use Strava\Models\Activity; | ||
|
|
||
| class CreateActivityAction | ||
| { | ||
| public function execute(int $userId, array $data): Activity | ||
| { | ||
| $activity = new Activity(); | ||
|
|
||
| $activity->user_id = $userId; | ||
| $activity->title = $data["title"]; | ||
| $activity->notes = $data["notes"] ?? ""; | ||
| $activity->duration_s = (int)$data["duration_s"]; | ||
| $activity->distance_m = (int)$data["distance_m"]; | ||
| $activity->activityType = $data["activityType"]; | ||
|
|
||
| $activity->save(); | ||
|
|
||
| return $activity; | ||
| } | ||
| } |
This file contains hidden or 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,21 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Strava\Actions\Activities; | ||
|
|
||
| use Illuminate\Support\Facades\Storage; | ||
|
|
||
| class GetActivityPhotoAction | ||
| { | ||
| public function execute(int $activityId): ?string | ||
| { | ||
| $filename = "activity_" . $activityId . ".png"; | ||
|
|
||
| if (Storage::disk("activityPhotos")->exists($filename)) { | ||
| return Storage::disk("activityPhotos")->get($filename); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } |
This file contains hidden or 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,19 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Strava\Actions\Activities; | ||
|
|
||
| use Illuminate\Pagination\LengthAwarePaginator; | ||
| use Strava\Models\Activity; | ||
|
|
||
| class ListActivitiesAction | ||
| { | ||
| public function execute(int $userId): LengthAwarePaginator | ||
| { | ||
| return Activity::query() | ||
| ->where("user_id", $userId) | ||
| ->latest() | ||
| ->paginate(10); | ||
| } | ||
| } |
This file contains hidden or 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,17 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Strava\Actions\Avatars; | ||
|
|
||
| use Illuminate\Http\UploadedFile; | ||
|
|
||
| class ChangeAvatarAction | ||
| { | ||
| public function execute(UploadedFile $uploadedFile, int $userId): bool | ||
| { | ||
| $stored = $uploadedFile->storeAs("", $userId . ".png", "avatars"); | ||
|
|
||
| return $stored !== false; | ||
| } | ||
| } |
This file contains hidden or 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,23 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Strava\Actions\Avatars; | ||
|
|
||
| use Illuminate\Support\Facades\Storage; | ||
|
|
||
| class DeleteAvatarAction | ||
| { | ||
| public function execute(int $userId): bool | ||
| { | ||
| $filename = $userId . ".png"; | ||
|
|
||
| if (Storage::disk("avatars")->exists($filename)) { | ||
| Storage::disk("avatars")->delete($filename); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } |
This file contains hidden or 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,21 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Strava\Actions\Avatars; | ||
|
|
||
| use Illuminate\Support\Facades\Storage; | ||
|
|
||
| class GetAvatarAction | ||
| { | ||
| public function execute(int $userId): ?string | ||
| { | ||
| $filename = $userId . ".png"; | ||
|
|
||
| if (Storage::disk("avatars")->exists($filename)) { | ||
| return Storage::disk("avatars")->get($filename); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } |
This file contains hidden or 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,18 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Strava\Actions\Avatars; | ||
|
|
||
| use Identicon\Generator\SvgGenerator; | ||
| use Identicon\Identicon; | ||
|
|
||
| class GetDefaultAvatarAction | ||
| { | ||
| public function execute(int $userId): ?string | ||
| { | ||
| $identicon = new Identicon(new SvgGenerator()); | ||
|
|
||
| return $identicon->getImageData((string)$userId, 300); | ||
| } | ||
| } |
This file contains hidden or 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,18 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Strava\Actions\Profile; | ||
|
|
||
| use Strava\Models\User; | ||
|
|
||
| class UpdateProfileAction | ||
| { | ||
| public function execute(User $user, array $data): User | ||
| { | ||
| $user->fill($data); | ||
| $user->save(); | ||
|
|
||
| return $user->fresh(); | ||
| } | ||
| } |
This file contains hidden or 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,13 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Strava\Enums; | ||
|
|
||
| enum ActivityType: string | ||
| { | ||
| case Run = "run"; | ||
| case Ride = "ride"; | ||
| case Walk = "walk"; | ||
| case Other = "other"; | ||
| } |
This file contains hidden or 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,11 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Strava\Enums; | ||
|
|
||
| enum Gender: string | ||
| { | ||
| case Male = "male"; | ||
| case Female = "female"; | ||
| } |
This file contains hidden or 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,39 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Strava\Helpers; | ||
|
|
||
| use Identicon\Identicon; | ||
| use Illuminate\Support\Facades\Storage; | ||
|
|
||
| class IdenticonHelper | ||
| { | ||
| private Identicon $identicon; | ||
|
|
||
| public function __construct() | ||
| { | ||
| $this->identicon = new Identicon(); | ||
| } | ||
|
|
||
| public static function url(string|int $name): string | ||
| { | ||
| return url("/api/profiles/{$name}/avatar"); | ||
| } | ||
|
|
||
| public function create(string|int $filename, string $data): string | ||
| { | ||
| $image = $this->identicon->getImageData($data, 300); | ||
|
|
||
| return $this->save($filename, $image); | ||
| } | ||
|
|
||
| private function save(string|int $name, string $imageData): string | ||
| { | ||
| $path = $name . ".png"; | ||
|
|
||
| Storage::disk("avatars")->put($path, $imageData); | ||
|
|
||
| return Storage::disk("avatars")->url($path); | ||
| } | ||
| } |
This file contains hidden or 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,51 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Strava\Http\Controllers; | ||
|
|
||
| use Illuminate\Http\Request; | ||
| use Illuminate\Http\Response; | ||
| use Strava\Actions\Activities\CreateActivityAction; | ||
| use Strava\Actions\Activities\GetActivityPhotoAction; | ||
| use Strava\Actions\Activities\ListActivitiesAction; | ||
| use Strava\Http\Requests\StoreActivityRequest; | ||
| use Strava\Http\Resources\ActivityResource; | ||
|
|
||
| class ActivitiesController extends Controller | ||
| { | ||
| public function index(Request $request, ListActivitiesAction $listActivitiesAction) | ||
| { | ||
| $user = $request->user(); | ||
|
|
||
| $activities = $listActivitiesAction->execute($user->id); | ||
|
|
||
| return ActivityResource::collection($activities); | ||
| } | ||
|
|
||
| public function store(StoreActivityRequest $request, CreateActivityAction $createActivityAction): ActivityResource | ||
| { | ||
| $validated = $request->validated(); | ||
| $user = $request->user(); | ||
| $photo = $request->file("photo"); | ||
|
|
||
| $activity = $createActivityAction->execute($user->id, $validated); | ||
|
|
||
| $photo?->storeAs("", "activity_" . $activity->id . ".png", "activityPhotos"); | ||
|
|
||
| return ActivityResource::make($activity); | ||
| } | ||
|
|
||
| public function getPhoto(int $id, GetActivityPhotoAction $getActivityPhotoAction): Response | ||
| { | ||
| $photo = $getActivityPhotoAction->execute($id); | ||
|
|
||
| if ($photo) { | ||
| return response($photo) | ||
| ->header("Content-Type", "image/png") | ||
| ->header("Cache-Control", "max-age=31536000, public"); | ||
| } | ||
|
|
||
| return response()->noContent(); | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.