Skip to content

Commit

Permalink
[add/#12] add UserDefaults data
Browse files Browse the repository at this point in the history
  • Loading branch information
i-colours-u committed Nov 14, 2021
1 parent 8515daf commit 43e688a
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 19 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "59048036-EBB8-4320-97CE-8A9CF1DC3508"
type = "0"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "9AA3061A-6CBA-49E2-9A1E-56F6375A45A0"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "sopt_29th_Assignment/Global/Network/BaseAPI.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "84"
endingLineNumber = "84"
landmarkName = "bodyParameters"
landmarkType = "24">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct I18N{

struct Alert{
static let alarm = "알림"
static let error = "에러"
static let error = "오류"
static let networkError = "네트워크 상태를 확인해주세요"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct AccountDataGettable: Codable {
let status: Int
let success: Bool
let message: String
let data: UserData?
let userData: UserData?
}

// MARK: - DataClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ extension BaseAPI: TargetType {
case .postSignIn:
return "/login"
case .postSignUp:
return "/signin"
return "/signup"
default :
return ""
}
Expand Down Expand Up @@ -123,8 +123,7 @@ extension BaseAPI: TargetType {

var task: Task {
switch self{
case .sampleAPI
:
case .sampleAPI:
return .uploadMultipart(multiparts)

case .postSignIn,.postSignUp:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extension BaseService : AccountServiceType{
}

func postUserSignUp(email: String, password: String, name: String, completion: @escaping (Result<AccountDataGettable?, Error>) -> Void) {
print(email,password,name)
requestObject(.postSignUp(email: email, pw: password, name: name), completion: completion)
}

Expand Down
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>UIUserInterfaceStyle</key>
<string>Light</string>
<key>UIApplicationSceneManifest</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,27 @@ class SignInVC: UIViewController,SignInViewControllerable {
}

loginButton.press { [weak self] in
if let name = self?.nameTextField.text,
let email = self?.emailTextField.text,
if let email = self?.emailTextField.text,
let password = self?.passwordTextField.text{
print(email,password)
BaseService.default.postUserSignIn(email: email, password: password) { [weak self] result in
result.success { data in
self?.onSigninComplete?(name)

if let userName = data?.userData?.name{
UserDefaults.standard.setValue(userName, forKey: "userName")
self?.onSigninComplete?(userName)
}
}.catch { error in
if let error = error as? MoyaError,
let statusCode = error.response?.statusCode,
statusCode == 400 {
self?.makeAlert(title: I18N.Alert.error, message: JSON(error.response?.data)["message"] as! String)
self?.makeAlert(title: I18N.Alert.error, message: JSON(error.response?.data)["message"].stringValue)
}else{
self?.showNetworkErrorAlert()
}
}

}
}


}
}

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

import UIKit
import Moya
import SwiftyJSON

protocol SignUpViewControllerable: BaseControllable {
var onBack: (() -> Void)? { get set }
Expand Down Expand Up @@ -86,13 +88,33 @@ class SignUpVC: UIViewController,SignUpViewControllerable {
nameTextField.textDelegate = self
emailTextField.textDelegate = self
passwordTextField.textDelegate = self

}

private func setButtonActions(){
signupButton.press { [weak self] in
if let name = self?.nameTextField.text{
self?.onSignupComplete?(name)

if let email = self?.emailTextField.text,
let password = self?.passwordTextField.text,
let name = self?.nameTextField.text{
print(email,password)
BaseService.default.postUserSignUp(email: email, password: password, name: name) { [weak self] result in
result.success { data in
if let userName = data?.userData?.name{
self?.onSignupComplete?(userName)
}
}.catch { error in
dump(error)
if let error = error as? MoyaError,
let statusCode = error.response?.statusCode,
statusCode == 400 {
self?.makeAlert(title: I18N.Alert.error, message: JSON(error.response?.data)["message"].stringValue)
}else{
self?.showNetworkErrorAlert()
}
}

}
}
}
}
Expand All @@ -103,7 +125,7 @@ class SignUpVC: UIViewController,SignUpViewControllerable {
ImageLiterals.Components.checkBox_unactivated
}





Expand Down Expand Up @@ -155,7 +177,7 @@ extension SignUpVC : CustomInputTextFieldDelegate{

// 키보드 액션 부분
extension SignUpVC{


private func registerForKeyboardNotifications() {
NotificationCenter.default.addObserver(self, selector:#selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
Expand All @@ -174,15 +196,15 @@ extension SignUpVC{
self.headerViewTopConstraint.constant = -100
UIView.animate(withDuration: duration, delay: 0, options: .init(rawValue: curve)) {
self.headerView.alpha = 0

self.view.layoutIfNeeded()
}
}

@objc private func keyboardWillHide(_ notification: Notification) {
let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as! Double
let curve = notification.userInfo?[UIResponder.keyboardAnimationCurveUserInfoKey] as! UInt

self.headerViewTopConstraint.constant = 30
UIView.animate(withDuration: duration, delay: 0, options: .init(rawValue: curve)) {
self.headerView.alpha = 1
Expand Down

0 comments on commit 43e688a

Please sign in to comment.