Skip to content

Commit

Permalink
not clean yet
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Jan 25, 2025
1 parent 8e7233a commit 3d0d803
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions app/Http/Controllers/Gallery/PhotoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,21 @@ public function update(EditPhotoRequest $request): PhotoResource
$photo->tags = $request->tags();
$photo->license = $request->license()->value;

if ($request->takenAt() !== null) {
// update if required
$photo->taken_at_mod = $request->takenAt();
} elseif ($photo->taken_at_mod !== null) {
// reset if set to null
// We only use taken_at_mod to store the original date when the user changes the date.
// If the user changes the date again, we do not update taken_at_mod.
if ($request->takenAt() !== null && $photo->taken_at_mod === null) {
// First time saving: we preserve the original date in taken_at_mod.
$photo->taken_at_mod = $photo->taken_at;
$photo->taken_at = $request->takenAt();
} elseif ($request->takenAt() !== null && $photo->taken_at_mod !== null) {
// We already have a taken_at_mod, we only update the taken_at.
$photo->taken_at = $request->takenAt();
} elseif ($request->takenAt() === null && $photo->taken_at_mod !== null) {
// we reset
$photo->taken_at = $photo->taken_at_mod;
$photo->taken_at_mod = null;
}

$photo->save();

return PhotoResource::fromModel($photo);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Resources/Models/PhotoResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function __construct(Photo $photo)
$this->shutter = $photo->shutter;
$this->size_variants = new SizeVariantsResouce($photo);
$this->tags = $photo->tags;
$this->taken_at = ($photo->taken_at_mod ?? $photo->taken_at)?->toIso8601String();
$this->taken_at = $photo->taken_at?->toIso8601String();
$this->taken_at_orig_tz = $photo->taken_at_orig_tz;
$this->title = $photo->title;
$this->type = $photo->type;
Expand Down

0 comments on commit 3d0d803

Please sign in to comment.