Week 022 — The Found API, One Field at a Time

Two days lost to life — a Rocket recall, taxes — and then three days of backend work that felt like archaeology.

Week of April 14, 2025

Progress

Image resizing landed on Wednesday: images are now resized client-side before upload, keeping file sizes reasonable. Getting the resized file to the server was briefly confusing — the upload needed to be accessed from the $_FILES global, not $_POST. Once clear, it worked.

The found item API backend took shape Thursday and Friday. The flow: finder submits information, API receives it, data gets mapped into the LostItemDTO and written to the database. The implementation required LostItemDTO->toJson() and updates to the repository class to handle the new fields.

By Friday, all data was posting correctly. Several fields that weren't saving turned out to have simple explanations: geolocation results returned as an indexed array, not a key-value pair; a case typo in the class property name for timestamp_found; an image path being mapped under the wrong property name.

Grok was used to figure out how to extract coordinates from MySQL's POINT type — storing coordinates as a point is cleaner, but reading them back requires knowing the format.

The Hard Part

A brief but real confusion about JavaScript destructuring: using newFile vs file in the pictureLoaded function returned undefined silently with no error. The shorthand destructuring const { file } = result creates a const named file — so naming the variable anything else just doesn't bind to anything. No error, just nothing there.

Also discovered that PHP's isset() check inside an echo statement doesn't behave as expected. An issue where $user was passing an isset test when no user was logged in took longer to trace than the fix warranted.

Learnings

JavaScript destructuring with shorthand assignment is name-sensitive. const { file } = result binds to result.file specifically — a different name in the destructuring won't throw an error, it just won't have a value.

Next Week

The API returns a success response. Now the found flow needs to be tested through the case where an item hasn't been reported lost yet — a finder picks up an item the owner doesn't know is missing.