Skip to content

Commit

Permalink
Merge pull request #122 from Sopt-Mongle/feature/#119
Browse files Browse the repository at this point in the history
Feature/#119
  • Loading branch information
seu11ee authored Nov 12, 2020
2 parents cd1586f + 04795d3 commit 706e66e
Show file tree
Hide file tree
Showing 21 changed files with 353 additions and 117 deletions.
7 changes: 5 additions & 2 deletions Mongle/Mongle.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
B83800F52525FF78009286AE /* PasswordChangeVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B83800F42525FF78009286AE /* PasswordChangeVC.swift */; };
B83800F82525FFA2009286AE /* PasswordChange.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B83800F72525FFA2009286AE /* PasswordChange.storyboard */; };
B842A4462557E3B100253275 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B842A4452557E3B100253275 /* String+Extensions.swift */; };
B842A455255BBD4B00253275 /* MyProfileUploadData.swift in Sources */ = {isa = PBXBuildFile; fileRef = B842A454255BBD4A00253275 /* MyProfileUploadData.swift */; };
B85400A025513C1D004700B4 /* VersionInfo.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B854009F25513C1D004700B4 /* VersionInfo.storyboard */; };
B85400A6255143D7004700B4 /* AccountEditVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B85400A5255143D7004700B4 /* AccountEditVC.swift */; };
B85400A9255143EC004700B4 /* AccountEdit.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B85400A8255143EC004700B4 /* AccountEdit.storyboard */; };
Expand Down Expand Up @@ -283,6 +284,7 @@
B83800F42525FF78009286AE /* PasswordChangeVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasswordChangeVC.swift; sourceTree = "<group>"; };
B83800F72525FFA2009286AE /* PasswordChange.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = PasswordChange.storyboard; sourceTree = "<group>"; };
B842A4452557E3B100253275 /* String+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extensions.swift"; sourceTree = "<group>"; };
B842A454255BBD4A00253275 /* MyProfileUploadData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyProfileUploadData.swift; sourceTree = "<group>"; };
B854009F25513C1D004700B4 /* VersionInfo.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = VersionInfo.storyboard; sourceTree = "<group>"; };
B85400A5255143D7004700B4 /* AccountEditVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountEditVC.swift; sourceTree = "<group>"; };
B85400A8255143EC004700B4 /* AccountEdit.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AccountEdit.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -606,6 +608,7 @@
B8E2E17824C29CD300595752 /* MyThemeData.swift */,
B8E2E17C24C2AE3C00595752 /* MySentenceData.swift */,
B8E2E18024C2B6F200595752 /* MyCuratorData.swift */,
B842A454255BBD4A00253275 /* MyProfileUploadData.swift */,
);
path = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -699,14 +702,13 @@
B8E2E14A24BEE0A000595752 /* MyTabThemeVC.swift */,
B8E2E14C24BEE0B000595752 /* MyTabSentenceVC.swift */,
B8E2E14E24BEE0E900595752 /* MyTabCuratorVC.swift */,
B83800F42525FF78009286AE /* PasswordChangeVC.swift */,
B85400A5255143D7004700B4 /* AccountEditVC.swift */,
EC6E99C92508C9D900B57284 /* SignUpAgreeVC.swift */,
EC523909250DF4ED0080BAF0 /* SignUpRuleVC.swift */,
EC76E10425109D56009DDEF1 /* SignUpMainVC.swift */,
EC771BB3254D4E210041603E /* SignUpServiceAgreeVC.swift */,
EC30462B254ED0AA00DB6E4A /* ServiceAgreeForSignUpVC.swift */,
B83800F42525FF78009286AE /* PasswodChangeVC.swift */,
B83800F42525FF78009286AE /* PasswordChangeVC.swift */,
ECF97E882556722000BF85AA /* SignUpEmailVC.swift */,
);
path = VCs;
Expand Down Expand Up @@ -1062,6 +1064,7 @@
B8E2E17724C29C9800595752 /* MyThemeService.swift in Sources */,
EC759C4624BF7219001D2F81 /* BookSearchForWritingService.swift in Sources */,
B8E2E15324C0586800595752 /* SearchMainService.swift in Sources */,
B842A455255BBD4B00253275 /* MyProfileUploadData.swift in Sources */,
B8F4DDF824B210000075FDC1 /* RecentSearchCVC.swift in Sources */,
7FBFAB76255850CA0079FAC5 /* LoginRequestPopupView.swift in Sources */,
7FFEA28724BF768D003D381A /* EditorPickData.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Mongle/Mongle/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>UnderTab</string>
<string>LogIn</string>
</dict>
</array>
</dict>
Expand Down
124 changes: 89 additions & 35 deletions Mongle/Mongle/Resource/APIService/MyProfileService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct MyProfileService {

func getMy(completion : @escaping (NetworkResult<Any>) -> Void) {
let header : HTTPHeaders = ["Content-Type" : "application/json","token":UserDefaults.standard.string(forKey:"token")!]
print(UserDefaults.standard.string(forKey:"token")!)
let dataRequest = Alamofire.request(APIConstants.myProfileURL,
method: .get,
parameters: nil,
Expand All @@ -23,62 +24,115 @@ struct MyProfileService {

dataRequest.responseData { dataResponse in
switch dataResponse.result {
case .success :
guard let statusCode = dataResponse.response?.statusCode else {return}
guard let data = dataResponse.result.value else {return}
let networkResult = self.judge(by: statusCode, data)
completion(networkResult)

case .failure :
completion(.networkFail)


case .success :
guard let statusCode = dataResponse.response?.statusCode else {return}
guard let data = dataResponse.result.value else {return}
let networkResult = self.judge(flag: 1, by: statusCode, data)
completion(networkResult)
case .failure :
completion(.networkFail)
}


}





}
func uploadMy(img: UIImage,name: String, introduce: String, keywordIdx: Int, completion : @escaping(NetworkResult<Any>) -> Void) {
let header: HTTPHeaders = [
"Content-Type": "multipart/form-data",
"token":UserDefaults.standard.string(forKey:"token")!]
let body: Parameters = [
"name": name,
"introduce": introduce,
"keywordIdx": keywordIdx
]
Alamofire.upload(multipartFormData: {multiPartFormData in
let imageData = img.jpegData(compressionQuality: 1.0)!
multiPartFormData.append(imageData,withName:"img",mimeType:"image/jpeg")
print("img")
for (key,value) in body{
if value is String{
let val = value as! String
multiPartFormData.append(val.data(using:String.Encoding.utf8)!,withName:key)
print(key)
}
else if value is Int{
let val = value as! Int
let convertedValueNumber: NSNumber = NSNumber(value: val)
let data = NSKeyedArchiver.archivedData(withRootObject: convertedValueNumber)
multiPartFormData.append("\(val)".data(using:String.Encoding.utf8)!, withName: key)
print(key)
}
// else if value is UIImage{
// let image = value as! UIImage
// let imageData = image.jpegData(compressionQuality: 1.0)!
// multiPartFormData.append(imageData,withName:key,mimeType:"image/jpeg")
// print(key)
// }
}

},usingThreshold:UInt64.init(), to: APIConstants.myProfileURL,method:.post, headers:header, encodingCompletion: { result in
switch result {
case .success(let upload,_,_):
upload.uploadProgress(closure: { (progress) in
print(progress.fractionCompleted) })
upload.responseData { response in
guard let statusCode = response.response?.statusCode, let data = response.result.value else { return }
let networkResult = self.judge(flag: 2, by: statusCode, data)
completion(networkResult)
}
case .failure(let error):
print(error.localizedDescription)
completion(.networkFail) }
})
}


private func judge(by statusCode : Int , _ data : Data) -> NetworkResult<Any> {
private func judge(flag: Int, by statusCode : Int , _ data : Data) -> NetworkResult<Any> {
switch statusCode{
case 200 :
return getMyProfile(by: data)
case 400:
return showErrorMessage(by : data)
case 600 :
return .serverErr
default :
return .networkFail

case 200 :
return getMyProfile(flag: flag, by: data)
case 400:
return showErrorMessage(by : data)
case 600 :
return .serverErr
default :
return .networkFail
}


}

private func getMyProfile(by data : Data) -> NetworkResult<Any> {

private func getMyProfile(flag: Int, by data : Data) -> NetworkResult<Any> {
let decoder = JSONDecoder()
guard let decodedData = try? decoder.decode(GenericResponse<[MyProfileData]>.self, from: data)
if flag == 1{
guard let decodedData = try? decoder.decode(GenericResponse<[MyProfileData]>.self, from: data)
else { return .pathErr }


guard let data = decodedData.data else{
return .requestErr(decodedData.message)

guard let data = decodedData.data else{
return .requestErr("디코딩실패")
}
return .success(data)
}
else{
guard let decodedData = try? decoder.decode(GenericResponse<[MyProfileUploadData]>.self, from: data)
else { return .pathErr }

guard let data = decodedData.data else{
return .requestErr("디코딩실패")
}
return .success(data)
}

return .success(data)

}

private func showErrorMessage(by data : Data) -> NetworkResult<Any> {
let decoder = JSONDecoder()
guard let decodedData = try? decoder.decode(GenericResponse<[MyProfileData]>.self, from: data)
else { return .pathErr }
else { return .pathErr }

print(decodedData.message)
return .requestErr(decodedData.message)
Expand Down
6 changes: 0 additions & 6 deletions Mongle/Mongle/Resource/APIService/SignInService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,10 @@ struct SignInService {
case .failure :
completion(.networkFail)


}


}





}

private func judge(by statusCode : Int , _ data : Data) -> NetworkResult<Any> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "mySettingsProfilePopupBg.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "[email protected]"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "mySettingsProfilePopupBox.png",
"scale" : "1x",
"idiom" : "universal"
},
{
"filename" : "[email protected]",
"scale" : "2x",
"idiom" : "universal"
},
{
"filename" : "[email protected]",
"scale" : "3x",
"idiom" : "universal"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@
</constraints>
</view>
<connections>
<outlet property="backButton" destination="aRX-DT-6sS" id="8YB-O7-It9"/>
<outlet property="bottomBlurImageBottomConstraint" destination="ZSk-zv-Lld" id="Rbk-rw-9mL"/>
<outlet property="cameraButton" destination="5SS-23-U9m" id="EH7-Zc-xGH"/>
<outlet property="completeButton" destination="41n-Er-Zfz" id="CJn-9w-9f0"/>
Expand All @@ -300,21 +301,6 @@
</objects>
<point key="canvasLocation" x="264.80000000000001" y="-241.62561576354682"/>
</scene>
<!--View Controller-->
<scene sceneID="dPG-3T-gPk">
<objects>
<viewController id="k1l-cV-MRv" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="wib-uN-ikY">
<rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<viewLayoutGuide key="safeArea" id="S6J-Ft-Vlb"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="oV0-Eh-b0p" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1015" y="-242"/>
</scene>
</scenes>
<resources>
<image name="mySettingsProfile4IcCamera" width="23" height="23"/>
Expand Down
7 changes: 6 additions & 1 deletion Mongle/Mongle/Source/Cell/ProfileEditIntroduceTVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ProfileEditIntroduceTVC: UITableViewCell {
lazy var warningStackView: UIStackView = UIStackView()
var selectedTextFieldDelegate: (() -> ()) = { }
var unSelectedTextfieldDelegate: (() -> ()) = { }
var introduceDelegate: ((String) -> ()) = { _ in }

override func awakeFromNib() {
super.awakeFromNib()
Expand All @@ -32,7 +33,9 @@ class ProfileEditIntroduceTVC: UITableViewCell {
warningStackView = makeWarningStackView(message: "소개를 입력해주세요!", isCorrect: false)

}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){
self.contentView.endEditing(true)
}
override func setSelected(_ selected: Bool, animated: Bool) {
}
@objc func textFieldChanged(sender: UITextField){
Expand Down Expand Up @@ -107,6 +110,8 @@ extension ProfileEditIntroduceTVC: UITextFieldDelegate {
func textFieldDidEndEditing(_ textField: UITextField) {
textField.setBorder(borderColor: .veryLightPink, borderWidth: 1.0)
unSelectedTextfieldDelegate()
introduceDelegate(textField.text!)

}


Expand Down
2 changes: 1 addition & 1 deletion Mongle/Mongle/Source/Model/MyProfileData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Foundation
struct MyProfileData: Codable {
var curatorIdx: Int
var name: String
var img: String
var img: String?
var introduce: String?
var keywordIdx: Int?
var subscribe: Int
Expand Down
17 changes: 17 additions & 0 deletions Mongle/Mongle/Source/Model/MyProfileUploadData.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// MyProfileUploadData.swift
// Mongle
//
// Created by 이예슬 on 11/11/20.
// Copyright © 2020 이주혁. All rights reserved.
//

import Foundation

struct MyProfileUploadData: Codable {
var name: String
var img: String?
var introduce: String?
var keyword: String?
var keywordIdx: Int?
}
Loading

0 comments on commit 706e66e

Please sign in to comment.