You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I love this SPM but having also lots of pain after I am using this :(
my model
public struct UserGetObject: Codable {
public var id: ObjectId
public var fullName: String
public var phoneNumber: String?
public var email: String?
public var role: UserRole
public var language: UserLanguage
public init(
id: ObjectId,
fullName: String,
phoneNumber: String? = nil,
email: String? = nil,
role: UserRole,
language: UserLanguage
) {
self.id = id
self.fullName = fullName
self.phoneNumber = phoneNumber
self.email = email
self.role = role
self.language = language
}
}
public let usersRouter = OneOf {
Route(.case(UsersRoute.user)) {
Path { Parse(.string) }
userRouter
}
Route(.case(UsersRoute.update)) {
Method.put
Body(.json(UserGetObject.self))
}
}
// reducer
case .nameForm:
withAnimation { state.selectedPage = .schaduleForm }
var currentUser = environment.currentUser
currentUser.fullName = state.name
return .task { [cuser = currentUser] in
return .userUpdate(
await TaskResult {
try await environment.userClient.update(cuser)
}
)
}
// Clinet
public struct UserClient {
static public let apiClient: URLRoutingClient<SiteRoute> = .live(
router: siteRouter.baseRequestData(
.init(
scheme: EnvironmentKeys.rootURL.scheme,
host: EnvironmentKeys.rootURL.host,
port: 7070,
headers: ["Authorization": ["Bearer \(accessTokenTemp)"]]
)
)
)
public typealias UserMeHandler = @Sendable (String) async throws -> UserGetObject
public typealias UserUpdateHandler = @Sendable (UserGetObject) async throws -> UserGetObject
public typealias UserDeleteHandler = @Sendable (String) async throws -> Bool
public let userMeHandler: UserMeHandler
public let update: UserUpdateHandler
public let delete: UserDeleteHandler
public init(
userMeHandler: @escaping UserMeHandler,
update: @escaping UserUpdateHandler,
delete: @escaping UserDeleteHandler
) {
self.userMeHandler = userMeHandler
self.update = update
self.delete = delete
}
}
extension UserClient {
public static var live: UserClient =
.init(
userMeHandler: { id in
return try await UserClient.apiClient.decodedResponse(
for: .authEngine(.users(.user(id: id, route: .find))),
as: UserGetObject.self,
decoder: .iso8601
).value
},
update: { userInput in
return try await UserClient.apiClient.decodedResponse(
for: .authEngine(.users(.update(input: userInput))),
as: UserGetObject.self,
decoder: .iso8601
).value
},
delete: { id in
return try await UserClient.apiClient.data(
for: .authEngine(.users(.user(id: id, route: .delete)))
).response.isResponseOK()
}
)
}
received action:
AppAction.welcome(
WelcomeAction.userUpdate(
TaskResult.failure(
URLRoutingDecodingError(
bytes: Data(77 bytes),
response: NSHTTPURLResponse(),
underlyingError: DecodingError.dataCorrupted(
DecodingError.Context(
codingPath: [],
debugDescription: "The given data was not valid JSON.",
underlyingError: NSError(
domain: "NSCocoaErrorDomain",
code: 3840,
userInfo: [
"NSDebugDescription": "Invalid value around line 1, column 0.",
"NSJSONSerializationErrorIndex": 0
]
)
)
)
)
)
)
)
(No state changes)
Hi @saroar, I'm converting this to a discussion because it's not clear it's an issue with the library.
Also, the project you attached doesn't seem to do anything. There are no tests and there is no UI. In order for anyone to be able to help it would be best for you to distill the essence of the problem into a standalone project with no dependencies other than the swift-url-routing library.
I love this SPM but having also lots of pain after I am using this :(
my model
https://vimeo.com/754632355
The text was updated successfully, but these errors were encountered: