Skip to content

Commit

Permalink
feat: (#16) get메서드 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
torch-ray committed Jun 9, 2021
1 parent a3591b1 commit fb7adb4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
6 changes: 3 additions & 3 deletions IssueTracker/IssueTracker/Data/IssueDTO.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import Foundation

struct IssueDTO {
struct IssueDTO: Decodable {
let count: Count
let issue: [Issue]
}

struct Count {
struct Count: Decodable {
let label:Int
let milestone:Int
let openedIssue:Int
let closedIssue:Int
}

struct Issue {
struct Issue: Decodable {
let id:Int
let title:String
let author:String
Expand Down
22 changes: 21 additions & 1 deletion IssueTracker/IssueTracker/Data/Network/APIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@ import Foundation
import RxSwift
import Alamofire

class APIService {
protocol NetworkPort {
func get(_ url:URL) -> Observable<IssueDTO>
}

class APIService:NetworkPort {

func get(_ url: URL) -> Observable<IssueDTO> {
return Observable.create { observer in
AF.request(url, method: .get)
.responseDecodable(of: IssueDTO.self) { response in
switch response.result {
case .failure(let error):
observer.onError(error)
case .success(let data):
observer.onNext(data)
observer.onCompleted()
}
}
return Disposables.create()
}

}
}

0 comments on commit fb7adb4

Please sign in to comment.