Skip to content

Commit

Permalink
Merge pull request #12 from SOPT28th-SOPKATHON-Kick/feat/#7
Browse files Browse the repository at this point in the history
Feat/#7
  • Loading branch information
Hansangjin98 authored May 22, 2021
2 parents 4e3a647 + 130a12e commit 57e680d
Show file tree
Hide file tree
Showing 10 changed files with 326 additions and 34 deletions.
81 changes: 57 additions & 24 deletions SOPKATHON_Kick.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@
4039177E265944D500BF2C6F /* KingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4039177D265944D500BF2C6F /* KingViewController.swift */; };
403917812659450A00BF2C6F /* MyPageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 403917802659450A00BF2C6F /* MyPageViewController.swift */; };
403917842659451100BF2C6F /* MyPage.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 403917832659451100BF2C6F /* MyPage.storyboard */; };
4040303226598F5600709B7F /* APIConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4040303126598F5600709B7F /* APIConstants.swift */; };
4040303526598FC500709B7F /* DataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4040303426598FC500709B7F /* DataModel.swift */; };
404030382659900D00709B7F /* NetworkResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 404030372659900D00709B7F /* NetworkResult.swift */; };
4040303B2659903000709B7F /* RecentWritingService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4040303A2659903000709B7F /* RecentWritingService.swift */; };
404030402659928100709B7F /* dateDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4040303F2659928100709B7F /* dateDataModel.swift */; };
40403045265999DE00709B7F /* countDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40403044265999DE00709B7F /* countDataModel.swift */; };
4040304826599C9B00709B7F /* PopularWritingService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4040304726599C9B00709B7F /* PopularWritingService.swift */; };
4058242726593B5B00845A48 /* Login.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4058242626593B5B00845A48 /* Login.storyboard */; };
4058242B26593BAB00845A48 /* LoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4058242A26593BAB00845A48 /* LoginViewController.swift */; };
40D8815A2659A508009D920D /* MainTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E84EBA2826599B3B00F0A2C1 /* MainTabBarController.swift */; };
40F598E22659568F005DD065 /* HomeCollectionViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40F598E12659568F005DD065 /* HomeCollectionViewModel.swift */; };
40F598E926595E86005DD065 /* UIColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40F598E826595E86005DD065 /* UIColor.swift */; };
40F598EF26596594005DD065 /* HomeTableViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40F598EE26596594005DD065 /* HomeTableViewModel.swift */; };
Expand All @@ -32,11 +40,7 @@
BB35780B265973CC0031961F /* NavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB35780A265973CC0031961F /* NavigationBar.swift */; };
BB35781126597B400031961F /* DetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB35781026597B400031961F /* DetailViewController.swift */; };
BB35781526598D340031961F /* ContentTableCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB35781426598D340031961F /* ContentTableCell.swift */; };
BB357828265994D10031961F /* Roboto-Bold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = BB357825265994D10031961F /* Roboto-Bold.ttf */; };
BB357829265994D10031961F /* Roboto-Medium.ttf in Resources */ = {isa = PBXBuildFile; fileRef = BB357826265994D10031961F /* Roboto-Medium.ttf */; };
BB35782A265994D10031961F /* Roboto-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = BB357827265994D10031961F /* Roboto-Regular.ttf */; };
BB357830265998530031961F /* UIFont + Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB35782F265998530031961F /* UIFont + Extension.swift */; };
E84EBA2926599B3B00F0A2C1 /* MainTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E84EBA2826599B3B00F0A2C1 /* MainTabBarController.swift */; };
E84EBA2C26599B4500F0A2C1 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E84EBA2B26599B4500F0A2C1 /* Main.storyboard */; };
E84EBA3026599B7300F0A2C1 /* Home.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E84EBA2F26599B7300F0A2C1 /* Home.storyboard */; };
/* End PBXBuildFile section */
Expand All @@ -55,6 +59,14 @@
4039177D265944D500BF2C6F /* KingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KingViewController.swift; sourceTree = "<group>"; };
403917802659450A00BF2C6F /* MyPageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageViewController.swift; sourceTree = "<group>"; };
403917832659451100BF2C6F /* MyPage.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = MyPage.storyboard; sourceTree = "<group>"; };
403917862659462100BF2C6F /* MainTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabBarController.swift; sourceTree = "<group>"; };
4040303126598F5600709B7F /* APIConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIConstants.swift; sourceTree = "<group>"; };
4040303426598FC500709B7F /* DataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataModel.swift; sourceTree = "<group>"; };
404030372659900D00709B7F /* NetworkResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkResult.swift; sourceTree = "<group>"; };
4040303A2659903000709B7F /* RecentWritingService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecentWritingService.swift; sourceTree = "<group>"; };
4040303F2659928100709B7F /* dateDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dateDataModel.swift; sourceTree = "<group>"; };
40403044265999DE00709B7F /* countDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = countDataModel.swift; sourceTree = "<group>"; };
4040304726599C9B00709B7F /* PopularWritingService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopularWritingService.swift; sourceTree = "<group>"; };
4058242626593B5B00845A48 /* Login.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Login.storyboard; sourceTree = "<group>"; };
4058242A26593BAB00845A48 /* LoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewController.swift; sourceTree = "<group>"; };
40F598E12659568F005DD065 /* HomeCollectionViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeCollectionViewModel.swift; sourceTree = "<group>"; };
Expand All @@ -69,9 +81,6 @@
BB35780A265973CC0031961F /* NavigationBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationBar.swift; sourceTree = "<group>"; };
BB35781026597B400031961F /* DetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = DetailViewController.swift; path = SOPKATHON_Kick/Sources/Detail/VC/DetailViewController.swift; sourceTree = SOURCE_ROOT; };
BB35781426598D340031961F /* ContentTableCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ContentTableCell.swift; path = SOPKATHON_Kick/Sources/Detail/Cell/ContentTableCell.swift; sourceTree = SOURCE_ROOT; };
BB357825265994D10031961F /* Roboto-Bold.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = "Roboto-Bold.ttf"; path = "../../../../../../Downloads/Roboto-Bold.ttf"; sourceTree = "<group>"; };
BB357826265994D10031961F /* Roboto-Medium.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = "Roboto-Medium.ttf"; path = "../../../../../../Downloads/Roboto-Medium.ttf"; sourceTree = "<group>"; };
BB357827265994D10031961F /* Roboto-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = "Roboto-Regular.ttf"; path = "../../../../../../Downloads/Roboto-Regular.ttf"; sourceTree = "<group>"; };
BB35782F265998530031961F /* UIFont + Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIFont + Extension.swift"; sourceTree = "<group>"; };
E84EBA2826599B3B00F0A2C1 /* MainTabBarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MainTabBarController.swift; path = MainTabBar/MainTabBarController.swift; sourceTree = "<group>"; };
E84EBA2B26599B4500F0A2C1 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = Main.storyboard; path = MainTabBar/Main.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -99,6 +108,7 @@
400CFA07265932CF0080CB1B /* Products */,
7476745A01D2EAECE836D67A /* Pods */,
7B0181038D825517EDFD4354 /* Frameworks */,
40D8814D2659A4A7009D920D /* Recovered References */,
);
sourceTree = "<group>";
};
Expand All @@ -122,6 +132,27 @@
path = SOPKATHON_Kick;
sourceTree = "<group>";
};
4040303026598F4500709B7F /* API */ = {
isa = PBXGroup;
children = (
4040303126598F5600709B7F /* APIConstants.swift */,
4040303426598FC500709B7F /* DataModel.swift */,
404030372659900D00709B7F /* NetworkResult.swift */,
4040303A2659903000709B7F /* RecentWritingService.swift */,
4040304726599C9B00709B7F /* PopularWritingService.swift */,
);
path = API;
sourceTree = "<group>";
};
4040303E2659924500709B7F /* Struct */ = {
isa = PBXGroup;
children = (
4040303F2659928100709B7F /* dateDataModel.swift */,
40403044265999DE00709B7F /* countDataModel.swift */,
);
path = Struct;
sourceTree = "<group>";
};
4058241D265939C700845A48 /* Application */ = {
isa = PBXGroup;
children = (
Expand All @@ -136,7 +167,6 @@
isa = PBXGroup;
children = (
BB35782D2659950C0031961F /* Extensions */,
BB357824265994C70031961F /* Fonts */,
400CFA12265932D10080CB1B /* Assets.xcassets */,
);
path = Resources;
Expand Down Expand Up @@ -217,6 +247,14 @@
path = Detail;
sourceTree = "<group>";
};
40D8814D2659A4A7009D920D /* Recovered References */ = {
isa = PBXGroup;
children = (
403917862659462100BF2C6F /* MainTabBarController.swift */,
);
name = "Recovered References";
sourceTree = "<group>";
};
40F598DF265954D7005DD065 /* MainTabBar */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -245,6 +283,8 @@
40F598E626595E65005DD065 /* Common */ = {
isa = PBXGroup;
children = (
4040303E2659924500709B7F /* Struct */,
4040303026598F4500709B7F /* API */,
40F598E726595E6C005DD065 /* Extension */,
);
path = Common;
Expand Down Expand Up @@ -323,16 +363,6 @@
path = Cell;
sourceTree = "<group>";
};
BB357824265994C70031961F /* Fonts */ = {
isa = PBXGroup;
children = (
BB357825265994D10031961F /* Roboto-Bold.ttf */,
BB357826265994D10031961F /* Roboto-Medium.ttf */,
BB357827265994D10031961F /* Roboto-Regular.ttf */,
);
path = Fonts;
sourceTree = "<group>";
};
BB35782D2659950C0031961F /* Extensions */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -403,13 +433,9 @@
files = (
4058242726593B5B00845A48 /* Login.storyboard in Resources */,
4039177B265944CC00BF2C6F /* King.storyboard in Resources */,
BB357828265994D10031961F /* Roboto-Bold.ttf in Resources */,
403917782659448000BF2C6F /* Writing.storyboard in Resources */,
E84EBA3026599B7300F0A2C1 /* Home.storyboard in Resources */,
403917842659451100BF2C6F /* MyPage.storyboard in Resources */,
BB35782A265994D10031961F /* Roboto-Regular.ttf in Resources */,
4039176E265941B000BF2C6F /* Home.storyboard in Resources */,
BB357829265994D10031961F /* Roboto-Medium.ttf in Resources */,
E84EBA2C26599B4500F0A2C1 /* Main.storyboard in Resources */,
400CFA16265932D10080CB1B /* LaunchScreen.storyboard in Resources */,
400CFA13265932D10080CB1B /* Assets.xcassets in Resources */,
Expand Down Expand Up @@ -465,25 +491,32 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
40D8815A2659A508009D920D /* MainTabBarController.swift in Sources */,
BB357830265998530031961F /* UIFont + Extension.swift in Sources */,
BB35781126597B400031961F /* DetailViewController.swift in Sources */,
403917752659447300BF2C6F /* WritingViewController.swift in Sources */,
4058242B26593BAB00845A48 /* LoginViewController.swift in Sources */,
403917872659462100BF2C6F /* MainTabBarController.swift in Sources */,
40F598F626596D7B005DD065 /* HomeTableViewCell.swift in Sources */,
404030402659928100709B7F /* dateDataModel.swift in Sources */,
BB35781526598D340031961F /* ContentTableCell.swift in Sources */,
40F598F626596D7B005DD065 /* HomeTableViewCell.swift in Sources */,
40F598EF26596594005DD065 /* HomeTableViewModel.swift in Sources */,
4040303B2659903000709B7F /* RecentWritingService.swift in Sources */,
4040303526598FC500709B7F /* DataModel.swift in Sources */,
403917812659450A00BF2C6F /* MyPageViewController.swift in Sources */,
404030382659900D00709B7F /* NetworkResult.swift in Sources */,
400CFA0A265932CF0080CB1B /* AppDelegate.swift in Sources */,
40F598E22659568F005DD065 /* HomeCollectionViewModel.swift in Sources */,
4040303226598F5600709B7F /* APIConstants.swift in Sources */,
400CFA0C265932CF0080CB1B /* SceneDelegate.swift in Sources */,
4040304826599C9B00709B7F /* PopularWritingService.swift in Sources */,
4039176A2659416F00BF2C6F /* HomeViewController.swift in Sources */,
40403045265999DE00709B7F /* countDataModel.swift in Sources */,
BB357807265969230031961F /* KingHeaderView.swift in Sources */,
4039177E265944D500BF2C6F /* KingViewController.swift in Sources */,
BB3577FF265961460031961F /* KingDataModel.swift in Sources */,
BB3577F826595FD10031961F /* KingTableCell.swift in Sources */,
BB35780B265973CC0031961F /* NavigationBar.swift in Sources */,
E84EBA2926599B3B00F0A2C1 /* MainTabBarController.swift in Sources */,
4039177E265944D500BF2C6F /* KingViewController.swift in Sources */,
40F598E926595E86005DD065 /* UIColor.swift in Sources */,
40F598F326596C59005DD065 /* HomeCollectionViewCell.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>SOPKATHON_Kick.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>3</integer>
<integer>4</integer>
</dict>
</dict>
</dict>
Expand Down
14 changes: 14 additions & 0 deletions SOPKATHON_Kick/Common/API/APIConstants.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// APIConstants.swift
// SOPKATHON_Kick
//
// Created by 한상진 on 2021/05/23.
//

import Foundation
struct APIConstants{

// MARK:- Base URL
static let dateURL = "http://13.209.70.37:5000/api/post/date"
static let countURL = "http://13.209.70.37:5000/api/post/count"
}
41 changes: 41 additions & 0 deletions SOPKATHON_Kick/Common/API/DataModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// DataModel.swift
// SOPKATHON_Kick
//
// Created by 한상진 on 2021/05/23.
//

import Foundation

// MARK: - LoginDataModel
struct DataModel: Codable {
let success: Bool
let message: String
let data: UserData?

enum CodingKeys: String, CodingKey {
case success
case message
case data
}

init(from decoder : Decoder) throws
{
let values = try decoder.container(keyedBy: CodingKeys.self)
success = (try? values.decode(Bool.self, forKey: .success)) ?? false
message = (try? values.decode(String.self, forKey: .message)) ?? ""
data = (try? values.decode(UserData.self, forKey: .data)) ?? nil
}
}

// MARK: - UserData
struct UserData: Codable {
let userID: Int
let userNickname, token: String

enum CodingKeys: String, CodingKey {
case userID = "UserId"
case userNickname = "user_nickname"
case token
}
}
16 changes: 16 additions & 0 deletions SOPKATHON_Kick/Common/API/NetworkResult.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// NetworkResult.swift
// SOPKATHON_Kick
//
// Created by 한상진 on 2021/05/23.
//

import Foundation

enum NetworkResult<T> {
case success(T)
case requestErr(T)
case pathErr
case serverErr
case networkFail
}
57 changes: 57 additions & 0 deletions SOPKATHON_Kick/Common/API/PopularWritingService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// PopularWritingService.swift
// SOPKATHON_Kick
//
// Created by 한상진 on 2021/05/23.
//

import Foundation
import Alamofire

struct PopularWriting{
static let shared = PopularWriting()



func getData(
completion : @escaping (NetworkResult<Any>) -> Void)
{

let url = "http://13.209.70.37:5000/api/post/count"
let header : HTTPHeaders = ["Content-Type": "application/json"]
let dataRequest = AF.request(url, method: .get, encoding: JSONEncoding.default)

dataRequest.responseData { dataResponse in

dump(dataResponse)

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> {

let decoder = JSONDecoder()

guard let decodedData = try? decoder.decode(Date.self, from: data)
else { return .pathErr}

switch statusCode {

case 200: return .success(decodedData)
case 400: return .requestErr(decodedData)
case 500: return .serverErr
default: return .networkFail
}
}
}
57 changes: 57 additions & 0 deletions SOPKATHON_Kick/Common/API/RecentWritingService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// NetworkService.swift
// SOPKATHON_Kick
//
// Created by 한상진 on 2021/05/23.
//

import Foundation
import Alamofire

struct RecentWriting{
static let shared = RecentWriting()



func getData(
completion : @escaping (NetworkResult<Any>) -> Void)
{

let url = "http://13.209.70.37:5000/api/post/date"
let header : HTTPHeaders = ["Content-Type": "application/json"]
let dataRequest = AF.request(url, method: .get, encoding: JSONEncoding.default)

dataRequest.responseData { dataResponse in

dump(dataResponse)

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> {

let decoder = JSONDecoder()

guard let decodedData = try? decoder.decode(Date.self, from: data)
else { return .pathErr}

switch statusCode {

case 200: return .success(decodedData)
case 400: return .requestErr(decodedData)
case 500: return .serverErr
default: return .networkFail
}
}
}
Loading

0 comments on commit 57e680d

Please sign in to comment.