fix: goals save API (void response), user greeting, goal field labels
All checks were successful
Security Checks / dependency-audit (push) Successful in 13s
Security Checks / secret-scanning (push) Successful in 4s
Security Checks / dockerfile-lint (push) Successful in 3s

- Goals PUT returns partial JSON, use putVoid + reload
- Home shows 'Hi, Yusuf' instead of 'Home'
- EmptyResponse type for void-like endpoints

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Yusuf Suleman
2026-04-03 12:12:52 -05:00
parent 401af3cb6d
commit 48bfdd96a2
4 changed files with 29 additions and 8 deletions

View File

@@ -1,5 +1,13 @@
import Foundation
// Accepts any JSON response (for void-like endpoints that return partial data)
private struct EmptyResponse: Decodable {
init(from decoder: Decoder) throws {
// Accept anything
_ = try? decoder.singleValueContainer()
}
}
enum APIError: Error, LocalizedError {
case invalidURL
case httpError(Int, String)
@@ -138,6 +146,10 @@ final class APIClient {
try await request("PUT", path: path, body: body)
}
func putVoid(_ path: String, body: any Encodable) async throws {
let _: EmptyResponse = try await request("PUT", path: path, body: body)
}
func delete<T: Decodable>(_ path: String) async throws -> T {
try await request("DELETE", path: path)
}

View File

@@ -30,8 +30,8 @@ struct FitnessAPI {
)
}
func updateGoals(_ request: UpdateGoalsRequest) async throws -> DailyGoal {
try await api.put("\(basePath)/goals", body: request)
func updateGoals(_ request: UpdateGoalsRequest) async throws {
try await api.putVoid("\(basePath)/goals", body: request)
}
func updateEntry(id: String, body: UpdateEntryRequest) async throws -> FoodEntry {

View File

@@ -43,9 +43,10 @@ final class GoalsViewModel {
sugar: Double(editSugar) ?? 0,
fiber: Double(editFiber) ?? 0
)
let updated = try await api.updateGoals(request)
goal = updated
populateFields(from: updated)
try await api.updateGoals(request)
// Reload goals to get the full updated object
goal = try await api.getGoals(date: Date().apiDateString)
populateFields(from: goal)
saveSuccess = true
} catch {
self.error = error.localizedDescription

View File

@@ -23,9 +23,17 @@ struct HomeView: View {
VStack(spacing: 16) {
// Top bar
HStack {
Text("Home")
.font(.title.weight(.bold))
.foregroundStyle(vm.hasBackground ? .white : Color.textPrimary)
VStack(alignment: .leading, spacing: 2) {
if let name = auth.currentUser?.displayName {
Text("Hi, \(name)")
.font(.title.weight(.bold))
.foregroundStyle(vm.hasBackground ? .white : Color.textPrimary)
} else {
Text("Home")
.font(.title.weight(.bold))
.foregroundStyle(vm.hasBackground ? .white : Color.textPrimary)
}
}
Spacer()
Menu {
PhotosPicker(