Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

네트워크 모델 설계 및 테스트 완료 #143

Merged
merged 5 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
365 changes: 340 additions & 25 deletions iOS/IssueTracker/IssueTracker.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@
ReferencedContainer = "container:IssueTracker.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9521FCB7254FE7FE00FC0220"
BuildableName = "NetworkFrameworkTests.xctest"
BlueprintName = "NetworkFrameworkTests"
ReferencedContainer = "container:IssueTracker.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
15 changes: 0 additions & 15 deletions iOS/IssueTracker/IssueTracker/02.LabelScene/Model/Label.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Foundation
import NetworkFramework

protocol LabelListViewModelProtocol {
var didFetch: (() -> Void)? { get set }
Expand Down Expand Up @@ -36,19 +37,25 @@ class LabelListViewModel: LabelListViewModelProtocol {
}

func needFetchItems() {
labels = [Label(title: "feature", description: "기능에 대한 레이블입니다.", hexColor: "#FF5D5D"),
Label(title: "bug", description: "수정할 버그에 대한 레이블입니다.", hexColor: "#96F879"),
Label(title: "feature", description: "기능에 대한 레이블입니다.", hexColor: "#FF5D5D"),
Label(title: "bug", description: "수정할 버그에 대한 레이블입니다.", hexColor: "#96F879"),
Label(title: "feature", description: "기능에 대한 레이블입니다.", hexColor: "#FF5D5D"),
Label(title: "bug", description: "수정할 버그에 대한 레이블입니다.", hexColor: "#96F879"),
Label(title: "feature", description: "기능에 대한 레이블입니다.", hexColor: "#FF5D5D"),
Label(title: "bug", description: "수정할 버그에 대한 레이블입니다.", hexColor: "#96F879"),
Label(title: "feature", description: "기능에 대한 레이블입니다.", hexColor: "#FF5D5D"),
Label(title: "bug", description: "수정할 버그에 대한 레이블입니다.", hexColor: "#96F879"),
Label(title: "feature", description: "기능에 대한 레이블입니다.", hexColor: "#FF5D5D"),
Label(title: "bug", description: "수정할 버그에 대한 레이블입니다.", hexColor: "#96F879")]
didFetch?()
// 네트워크 통신으로 fetch
let labelFetchEndPoint = LabelEndPoint(requestType: .fetch)
let session = URLSession.init(configuration: .default, delegate: nil, delegateQueue: nil)
let dataLoader = DataLoader<[Label]>(session: session)
dataLoader.reqeust(endpoint: labelFetchEndPoint) { [weak self] (response) in
switch response {
case .success(let data):
guard let data = data else { return }
self?.labels = data
DispatchQueue.main.async {
self?.didFetch?()
}
case .failure(let error):
switch error {
case .decodingError(let message), .invalidURL(let message), .responseError(let message):
print(message)
}
}
}
}

func cellForItemAt(path: IndexPath) -> LabelItemViewModel {
Expand Down

This file was deleted.

51 changes: 51 additions & 0 deletions iOS/IssueTracker/IssueTracker/04.Models/Label.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// Label.swift
// IssueTracker
//
// Created by sihyung you on 2020/10/27.
// Copyright © 2020 IssueTracker-15. All rights reserved.
//

import Foundation

struct Label: Codable {
let id: Int
let title: String
let description: String
let hexColor: String

init(title: String, description: String, hexColor: String) {
self.id = -1
self.title = title
self.description = description
self.hexColor = hexColor
}

init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: DeCodingKeys.self)
id = try container.decode(Int.self, forKey: .id)
title = try container.decode(String.self, forKey: .title)
description = try container.decode(String.self, forKey: .description)
hexColor = try container.decode(String.self, forKey: .hexColor)
}

func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: EnCodingKeys.self)
try container.encode(title, forKey: .title)
try container.encode(description, forKey: .description)
try container.encode(hexColor, forKey: .hexColor)
}

enum EnCodingKeys: String, CodingKey {
case title
case description
case hexColor = "color"
}

enum DeCodingKeys: String, CodingKey {
case id
case title
case description
case hexColor = "color"
}
}
63 changes: 63 additions & 0 deletions iOS/IssueTracker/IssueTracker/04.Models/Milestone.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// Milestone.swift
// IssueTracker
//
// Created by 김신우 on 2020/10/29.
// Copyright © 2020 IssueTracker-15. All rights reserved.
//

import Foundation

struct Milestone: Codable {
let id: Int
let title: String
let description: String
let openIssuesLength: String
let closeIssueLength: String
let dueDate: String

init(id: Int, title: String, description: String, dueDate: String, openIssuesLength: String, closeIssueLength: String) {
self.id = id
self.title = title
self.description = description
self.dueDate = dueDate
self.openIssuesLength = openIssuesLength
self.closeIssueLength = closeIssueLength
}

init(id: Int, title: String, description: String, dueDate: String) {
self.init(id: id, title: title, description: description, dueDate: dueDate, openIssuesLength: "0", closeIssueLength: "0")
}

init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: DeCodingKeys.self)
id = try container.decode(Int.self, forKey: .id)
title = try container.decode(String.self, forKey: .title)
description = try container.decode(String.self, forKey: .description)
openIssuesLength = try container.decode(String.self, forKey: .openIssueLength)
closeIssueLength = try container.decode(String.self, forKey: .closeIssueLength)
dueDate = try container.decode(String.self, forKey: .dueDate)
}

func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: EnCodingKeys.self)
try container.encode(title, forKey: .title)
try container.encode(description, forKey: .description)
try container.encode(dueDate, forKey: .dueDate)
}

enum EnCodingKeys: CodingKey {
case title
case dueDate
case description
}

enum DeCodingKeys: String, CodingKey {
case id
case title
case description
case openIssueLength = "OpenIssuesLength"
case closeIssueLength = "CloseIssuesLength"
case dueDate
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// JSONDecoder+Decode.swift
// IssueTracker
//
// Created by 김신우 on 2020/11/02.
// Copyright © 2020 IssueTracker-15. All rights reserved.
//

import Foundation

extension JSONDecoder {

static func decode<T: Decodable>(_ type: T.Type, from data: Data) -> T? {
return try? JSONDecoder().decode(type, from: data)
}

}
5 changes: 5 additions & 0 deletions iOS/IssueTracker/IssueTracker/07.Supports/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
Expand Down
93 changes: 93 additions & 0 deletions iOS/IssueTracker/IssueTracker/08.Endpoints/LabelEndPoint.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//
// LabelEndPoint.swift
// IssueTracker
//
// Created by sihyung you on 2020/11/02.
// Copyright © 2020 IssueTracker-15. All rights reserved.
//

import Foundation
import NetworkFramework

struct LabelEndPoint: EndPoint {
var requestType: RequestType
var parameter: String = ""
var httpBody: Data?

init(requestType: RequestType, parameter: String, httpBody: Data? = nil) {
self.requestType = requestType
self.parameter = parameter
self.httpBody = httpBody
}

init(requestType: RequestType, httpBody: Data? = nil) {
self.requestType = requestType
self.httpBody = httpBody
}

enum RequestType {
case fetch
case create
case edit
case delete
}

var scheme: String {
switch self {
default:
return "http"
}
}

var baseURL: String {
switch self {
default:
return "118.67.134.194"
}
}

var port: Int {
switch self {
default:
return 3000
}
}

var path: String {
switch requestType {
case .fetch:
return "/api/label"
case .create:
return "/api/label"
case .edit:
return "/api/label/" + parameter
case .delete:
return "/api/label/" + parameter
}
}

var method: HTTPMethod {
switch requestType {
case .fetch:
return .get
case .create:
return .post
case .edit:
return .patch
case .delete:
return .delete
}
}

var statusCode: Int {
switch requestType {
case .fetch, .edit:
return 200
case .create:
return 201
case .delete:
return 204

}
}
}
Loading