editing all fields works and app is actually functional with profile edits

This commit is contained in:
2026-04-10 22:20:12 -05:00
parent b8880af200
commit b79d591395
8 changed files with 69 additions and 52 deletions

View File

@@ -44,6 +44,7 @@ public final class APIClient: Sendable {
var req = URLRequest(url: url)
req.httpMethod = method
req.setValue(contentType, forHTTPHeaderField: "Content-Type")
req.setValue(baseURL.absoluteString, forHTTPHeaderField: "Origin")
if let body {
do {

View File

@@ -335,13 +335,13 @@ public final class AuthClient: Sendable {
// MARK: - Update Name
private struct UpdateNameBody: Encodable, Sendable {
let name: String
let name: String?
}
/// Update the authenticated user's display name.
/// Update the authenticated user's display name. Pass an empty string to clear it.
public func updateName(_ name: String) async throws -> AuthUser {
let body = UpdateNameBody(name: name)
_ = try await api.postRaw("/api/auth/update-user", body: body)
let body = UpdateNameBody(name: name.isEmpty ? nil : name)
_ = try await api.postRaw("/api/account/name", body: body)
return try await fetchCurrentUser()
}

View File

@@ -3,9 +3,9 @@ import Foundation
/// Profile data returned by the server uses snake_case keys.
public struct UserProfile: Codable, Sendable {
public var userId: String
public var piFirstName: String
public var bldgCode: String
public var lab: String
public var piFirstName: String?
public var bldgCode: String?
public var lab: String?
public var contact: String?
enum CodingKeys: String, CodingKey {
@@ -18,9 +18,9 @@ public struct UserProfile: Codable, Sendable {
public init(
userId: String = "",
piFirstName: String = "",
bldgCode: String = "",
lab: String = "",
piFirstName: String? = nil,
bldgCode: String? = nil,
lab: String? = nil,
contact: String? = nil
) {
self.userId = userId
@@ -33,9 +33,9 @@ public struct UserProfile: Codable, Sendable {
/// Request body for POST /api/profile server expects snake_case keys.
public struct UserProfileUpsertBody: Codable, Sendable {
public var piFirstName: String
public var bldgCode: String
public var lab: String
public var piFirstName: String?
public var bldgCode: String?
public var lab: String?
public var contact: String?
enum CodingKeys: String, CodingKey {
@@ -45,7 +45,7 @@ public struct UserProfileUpsertBody: Codable, Sendable {
case contact
}
public init(piFirstName: String, bldgCode: String, lab: String, contact: String? = nil) {
public init(piFirstName: String? = nil, bldgCode: String? = nil, lab: String? = nil, contact: String? = nil) {
self.piFirstName = piFirstName
self.bldgCode = bldgCode
self.lab = lab