Skip to content

Commit

Permalink
Merge pull request #35 from BE-SOPT-Collaboration-Seminar-Coinone/fea…
Browse files Browse the repository at this point in the history
…ture/#30

Feature/#30
  • Loading branch information
pcsoyeon authored Jun 10, 2021
2 parents c4ca970 + 28d9b77 commit 7341bc1
Show file tree
Hide file tree
Showing 5 changed files with 567 additions and 485 deletions.
4 changes: 4 additions & 0 deletions Coinone-iOS/Coinone-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
06A1A45591145692DA4F18C7 /* Pods_Coinone_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E0AB500236EDF60103A408AE /* Pods_Coinone_iOS.framework */; };
92AB2FB72671F80D00479451 /* CoinListService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92AB2FB62671F80D00479451 /* CoinListService.swift */; };
CC0A1A9726564240000B65B9 /* FilterCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC0A1A9626564240000B65B9 /* FilterCollectionViewCell.swift */; };
CC0A1A992656425A000B65B9 /* CoinListTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC0A1A982656425A000B65B9 /* CoinListTableViewCell.swift */; };
CC0A1A9C265642E9000B65B9 /* TitleCollectionReusableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC0A1A9B265642E9000B65B9 /* TitleCollectionReusableView.swift */; };
Expand Down Expand Up @@ -61,6 +62,7 @@
/* Begin PBXFileReference section */
3E2F6097EABAAACC664AB52A /* Pods-Coinone-iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Coinone-iOS.debug.xcconfig"; path = "Target Support Files/Pods-Coinone-iOS/Pods-Coinone-iOS.debug.xcconfig"; sourceTree = "<group>"; };
4BA5E0330054E48E147B52CA /* Pods-Coinone-iOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Coinone-iOS.release.xcconfig"; path = "Target Support Files/Pods-Coinone-iOS/Pods-Coinone-iOS.release.xcconfig"; sourceTree = "<group>"; };
92AB2FB62671F80D00479451 /* CoinListService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoinListService.swift; sourceTree = "<group>"; };
CC0A1A9626564240000B65B9 /* FilterCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterCollectionViewCell.swift; sourceTree = "<group>"; };
CC0A1A982656425A000B65B9 /* CoinListTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoinListTableViewCell.swift; sourceTree = "<group>"; };
CC0A1A9B265642E9000B65B9 /* TitleCollectionReusableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleCollectionReusableView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -177,6 +179,7 @@
isa = PBXGroup;
children = (
CC3370122667C5D4004F067E /* CoinFilterService.swift */,
92AB2FB62671F80D00479451 /* CoinListService.swift */,
);
path = NetworkServices;
sourceTree = "<group>";
Expand Down Expand Up @@ -443,6 +446,7 @@
CC0E232D2652241D00B982A0 /* StockModel.swift in Sources */,
CCAA9A2B264FACDD008E50BF /* UIColor+.swift in Sources */,
CC770CF8265396CF004095A6 /* UILabel+.swift in Sources */,
92AB2FB72671F80D00479451 /* CoinListService.swift in Sources */,
CC0E232B265223FE00B982A0 /* StockTVC.swift in Sources */,
CC33700F2667C549004F067E /* APIConstants.swift in Sources */,
CC0A1A992656425A000B65B9 /* CoinListTableViewCell.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// CoinListService.swift
// Coinone-iOS
//
// Created by soyeon on 2021/06/10.
//

import Foundation
import Alamofire

struct CoinListService {
static let shared = CoinListService()

func sortCoin(sort: String,
ascending: String,
completion: @escaping (NetworkResult<Any>) -> Void) {
let header: HTTPHeaders = ["Content-Type": "application/json"]
let url = APIConstants.coinListURL + APIIndex.init(index: .sort(sort, ascending)).index.getIndex()
let dataRequest = AF.request(url,
method: .get,
encoding: JSONEncoding.default,
headers: header)
dataRequest.responseData { dataResponse in
dump(dataResponse)
print(dataResponse.result)
switch dataResponse.result {
case .success:
guard let statusCode = dataResponse.response?.statusCode else {return}
guard let value = dataResponse.value else {return}
let networkResult = self.judgeStatus(by: statusCode, value)
completion(networkResult)
case .failure:
completion(.pathErr)
}
}
}

private func judgeStatus(by statusCode: Int, _ data: Data) -> NetworkResult<Any> {
switch statusCode {
case 200:
return isValidData(data: data)
case 400: return .requestErr
case 500: return .serverErr
default: return .networkFail
}
}

private func isValidData(data : Data) -> NetworkResult<Any> {
let decoder = JSONDecoder()

guard let decodedData = try? decoder.decode([SortedCoin].self, from: data)
else { return .pathErr}
// 우선 PersonDataModel 형태로 decode(해독)을 한번 거칩니다. 실패하면 pathErr

// 해독에 성공하면 Person data를 success에 넣어줍니다.
return .success(decodedData)

}
}


35 changes: 14 additions & 21 deletions Coinone-iOS/Coinone-iOS/Source/Cells/StockTVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,33 +141,26 @@ extension StockTVC {

transPriceLabel.snp.makeConstraints { make in
make.top.equalTo(backView.snp.top).inset(22)
make.leading.equalTo(backView.snp.leading).inset(279)
make.leading.equalTo(backView.snp.leading).inset(299)
make.height.equalTo(17)
}
}
}

extension StockTVC {
func setData(coinLogoImageName: String, coinEnglishTitle: String, coinKoreanTitle: String, coinCurrentPrice: Float, riseOrDescent: String, percentage: Double, coinTotalPrice: Float) {
let formatter = NumberFormatter().then {
$0.numberStyle = .decimal
}

self.logoImage.image = UIImage(named: coinLogoImageName)
self.titleLabel.text = coinEnglishTitle
self.subTitleLabel.text = coinKoreanTitle


if riseOrDescent == "+" {
self.curValueLabel.setLabel(text: "\(formatter.string(from: NSNumber(value: coinCurrentPrice))!)", textColor: .textRed, font: .boldSystemFont(ofSize: 14))
self.rateLabel.setLabel(text: "\(riseOrDescent)\(percentage)%", textColor: .textRed, font: .systemFont(ofSize: 14, weight: .regular))
} else {
self.curValueLabel.setLabel(text: "\(formatter.string(from: NSNumber(value: coinCurrentPrice))!)", textColor: .mainBlue, font: .boldSystemFont(ofSize: 14))
self.rateLabel.setLabel(text: "\(riseOrDescent)\(percentage)%", textColor: .mainBlue, font: .systemFont(ofSize: 14, weight: .regular))
}

self.transPriceLabel.setLabel(text: "\(formatter.string(from: NSNumber(value:coinTotalPrice))!)", textColor: .coinGray, font: .systemFont(ofSize: 14, weight: .regular))

func setData(coinLogoImageName: String, coinEnglishTitle: String, coinKoreanTitle: String, coinCurrentPrice: String, riseOrDescent: String, percentage: String, coinTotalPrice: String) {
self.logoImage.imageFromUrl(coinLogoImageName, defaultImgPath: "https://sopt-8-coinone.s3.ap-northeast-2.amazonaws.com/KLAY.png")
self.titleLabel.setLabel(text: coinEnglishTitle, textColor: .black, font: .notoSansKRBoldFont(fontSize: 14))
self.subTitleLabel.setLabel(text: coinKoreanTitle, textColor: .coinGray, font: .notoSansKRMediumFont(fontSize: 10))
if riseOrDescent == "+" {
self.curValueLabel.setLabel(text: coinCurrentPrice, textColor: .textRed, font: .boldSystemFont(ofSize: 14))
self.rateLabel.setLabel(text: "\(riseOrDescent)\(percentage)%", textColor: .textRed, font: .systemFont(ofSize: 14, weight: .regular))
}
else {
self.curValueLabel.setLabel(text: coinCurrentPrice, textColor: .mainBlue, font: .boldSystemFont(ofSize: 14))
self.rateLabel.setLabel(text: "\(riseOrDescent)\(percentage)%", textColor: .mainBlue, font: .systemFont(ofSize: 14, weight: .regular))
}
self.transPriceLabel.setLabel(text: "\(coinTotalPrice.dropLast(8))", textColor: .coinGray, font: .systemFont(ofSize: 14, weight: .regular))
}
}

12 changes: 6 additions & 6 deletions Coinone-iOS/Coinone-iOS/Source/Models/StockModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import Foundation

struct StockModel {
var logoImage: String!
var title: String!
var subTitle: String!
var curValue: Float!
var coinLogoImageName: String
var coinEnglishTitle: String
var coinKoreanTitle: String
var coinCurrentPrice: String
var riseOrDescent: String
var rate: Double!
var transPrice: Float!
var percentage: String
var coinTotalPrice: String
}
Loading

0 comments on commit 7341bc1

Please sign in to comment.