Skip to content

Commit

Permalink
refactor(TodoData): Refactor todo data payload (request & response)
Browse files Browse the repository at this point in the history
  • Loading branch information
dodo849 committed Aug 23, 2024
1 parent c5c8081 commit 956cfbd
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,83 @@
// Created by DOYEON LEE on 8/15/24.
//

import Foundation

import CommonData
import TodoDataInterface
import Foundation
import OpenapiGenerated

import OpenAPIURLSession
import RxSwift
import TodoDataInterface

/// A repository that handles network communication with the server related to the organization domain.
public struct TodoRepository: TodoRepositoryInterface {
private let client: APIProtocol

public init() {
self.client = Client(
serverURL: UrlConfig.baseUrl.url,
transport: URLSessionTransport(),
middlewares: [AuthenticationMiddleware()]
)
serverURL: UrlConfig.baseUrl.url,
configuration: .init(
dateTranscoder: .custom
),
transport: URLSessionTransport(),
middlewares: [AuthenticationMiddleware()]
)
}


public func getAssignedTodos(
_ request: GetAssignedTodosRequest
) async throws -> Observable<GetAssignedTodosResponse> {
return Observable.create { observer in
Task {
do {
let response = try await client.getAssigned(
.init(
query: .init(
pageable: request
)
)
)

if let data = try response.ok.body.json.data {
observer.onNext(data)
observer.onCompleted()
} else {
observer.onError(TodoError.invalidResponse)
}
} catch {
observer.onError(TodoError.underlying(error))
}
}

return Disposables.create()
}
}


public func updateTodo(_ request: UpdateTodoRequest) async throws -> Observable<UpdateTodoResponse>{
return Observable.create { observer in
Task {
do {
let response = try await client.modify(
.init(
query: .init(
taskModifyRequest: request
)
)
)

if let data = try response.ok.body.json.data {
observer.onNext(data)
observer.onCompleted()
} else {
observer.onError(TodoError.invalidResponse)
}
} catch {
observer.onError(TodoError.underlying(error))
}
}

return Disposables.create()
}
}
//
// public func createTodo(
// _ param: GetOrganizationParam
// ) -> Observable<GetOrganizationResult> {
// return Observable.create { observer in
// Task {
// do {
// let response = try await client.createTask(.init(path: param))
//
// if let data = try response.ok.body.json.data {
// observer.onNext(data)
// observer.onCompleted()
// } else {
// observer.onError(OrganizationError.invalidResponse)
// }
// } catch {
// observer.onError(OrganizationError.underlying(error))
// }
// }
//
// return Disposables.create()
// }
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// GetAssignedTodosPayload.swift
// TodoDataInterface
//
// Created by DOYEON LEE on 8/24/24.
//

import OpenapiGenerated

// MARK: Request
public typealias GetAssignedTodosRequest = Components.Schemas.Pageable

// MARK: Response
public typealias GetAssignedTodosResponse = Components.Schemas.SliceAssignedTaskResponse
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// UpdateTodoPayload.swift
// TodoDataInterface
//
// Created by DOYEON LEE on 8/24/24.
//

import OpenapiGenerated

// MARK: Request
public typealias UpdateTodoRequest = Components.Schemas.TaskModifyRequest

// MARK: Response
public typealias UpdateTodoResponse = Components.Schemas.TaskModifyResponse

0 comments on commit 956cfbd

Please sign in to comment.