Week 025 — The User Profile's Long Overdue Reckoning
The user profile page had been functional but unrefactored for months. That ended this week.
Week of May 5, 2025
Progress
The user profile page was updated to use the new class structure. A UserAddressDTO class was created and integrated into the UserService and UserRepository chain. Country code and state/province fields, previously just text inputs, became dynamic dropdowns backed by JSON files — loading states when a country is selected, preserving the saved values on load.
The save functionality, once the classes were wired in, required debugging in layers: the UserAddressDTO::fromPost() function needed the address ID to be carried as a hidden form field, PDO was throwing a parameter count mismatch because id had ended up in both the SET clause and the WHERE clause of an UPDATE statement, and the country code wasn't being pre-selected because the option list was being built client-side after the page loaded (with no selected value set). Rebuilt the country/state options server-side in PHP and let JavaScript handle changes only.
The item page got a save button that enables on detected changes. The user profile page got the same pattern. Found image display on the item page was started.
The Hard Part
The state/province dropdown was only triggering its change event once — on initial load — and then never again. The issue was that the event handler was being attached to the element before the options list was populated. Attaching it after the options loaded solved it.
Decision Made
Address info stayed as a separate DTO but combined with the existing UserService and UserRepository classes — no separate service or repository for addresses. The address is part of the user's data model, and separating it further wasn't worth the overhead.
Next Week
Vacation in LaPush. Back the following week.
