Skip to content

Commit

Permalink
[#2] 4차 세미나 코드 업로드
Browse files Browse the repository at this point in the history
  • Loading branch information
Taehyeon-Kim committed May 7, 2022
1 parent a2c5f08 commit 536b807
Show file tree
Hide file tree
Showing 17 changed files with 442 additions and 53 deletions.
91 changes: 81 additions & 10 deletions Seminar/Seminar4/Seminar4.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
BD895C7B2824F279000AB87A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BD895C792824F279000AB87A /* Main.storyboard */; };
BD895C7D2824F27A000AB87A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BD895C7C2824F27A000AB87A /* Assets.xcassets */; };
BD895C802824F27A000AB87A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BD895C7E2824F27A000AB87A /* LaunchScreen.storyboard */; };
BD895C882825A494000AB87A /* APIConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD895C872825A494000AB87A /* APIConstants.swift */; };
BD895C8A2825A7EB000AB87A /* NetworkResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD895C892825A7EB000AB87A /* NetworkResult.swift */; };
BD895C8C2825B671000AB87A /* LoginModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD895C8B2825B671000AB87A /* LoginModel.swift */; };
BD895C8E2825BC7C000AB87A /* UserService.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD895C8D2825BC7C000AB87A /* UserService.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -27,6 +31,10 @@
BD895C7C2824F27A000AB87A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
BD895C7F2824F27A000AB87A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
BD895C812824F27A000AB87A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
BD895C872825A494000AB87A /* APIConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIConstants.swift; sourceTree = "<group>"; };
BD895C892825A7EB000AB87A /* NetworkResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkResult.swift; sourceTree = "<group>"; };
BD895C8B2825B671000AB87A /* LoginModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginModel.swift; sourceTree = "<group>"; };
BD895C8D2825BC7C000AB87A /* UserService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserService.swift; sourceTree = "<group>"; };
E974C8935CA0780106025F86 /* Pods-Seminar4.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Seminar4.debug.xcconfig"; path = "Target Support Files/Pods-Seminar4/Pods-Seminar4.debug.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -56,10 +64,69 @@
E974C8935CA0780106025F86 /* Pods-Seminar4.debug.xcconfig */,
6BB15202D71D244401400BC2 /* Pods-Seminar4.release.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
BD506E83282629D600AB96ED /* Network */ = {
isa = PBXGroup;
children = (
BD895C872825A494000AB87A /* APIConstants.swift */,
BD895C892825A7EB000AB87A /* NetworkResult.swift */,
);
path = Network;
sourceTree = "<group>";
};
BD506E84282629DD00AB96ED /* Model */ = {
isa = PBXGroup;
children = (
BD895C8B2825B671000AB87A /* LoginModel.swift */,
);
path = Model;
sourceTree = "<group>";
};
BD506E85282629E000AB96ED /* Application */ = {
isa = PBXGroup;
children = (
BD895C732824F279000AB87A /* AppDelegate.swift */,
BD895C752824F279000AB87A /* SceneDelegate.swift */,
);
path = Application;
sourceTree = "<group>";
};
BD506E86282629EE00AB96ED /* Service */ = {
isa = PBXGroup;
children = (
BD895C8D2825BC7C000AB87A /* UserService.swift */,
);
path = Service;
sourceTree = "<group>";
};
BD506E87282629FB00AB96ED /* Controller */ = {
isa = PBXGroup;
children = (
BD895C772824F279000AB87A /* ViewController.swift */,
);
path = Controller;
sourceTree = "<group>";
};
BD506E8828262A0B00AB96ED /* Support */ = {
isa = PBXGroup;
children = (
BD895C812824F27A000AB87A /* Info.plist */,
);
path = Support;
sourceTree = "<group>";
};
BD506E8928262A2700AB96ED /* Resource */ = {
isa = PBXGroup;
children = (
BD895C7C2824F27A000AB87A /* Assets.xcassets */,
BD895C792824F279000AB87A /* Main.storyboard */,
BD895C7E2824F27A000AB87A /* LaunchScreen.storyboard */,
);
path = Resource;
sourceTree = "<group>";
};
BD895C672824F279000AB87A = {
isa = PBXGroup;
children = (
Expand All @@ -81,13 +148,13 @@
BD895C722824F279000AB87A /* Seminar4 */ = {
isa = PBXGroup;
children = (
BD895C732824F279000AB87A /* AppDelegate.swift */,
BD895C752824F279000AB87A /* SceneDelegate.swift */,
BD895C772824F279000AB87A /* ViewController.swift */,
BD895C792824F279000AB87A /* Main.storyboard */,
BD895C7C2824F27A000AB87A /* Assets.xcassets */,
BD895C7E2824F27A000AB87A /* LaunchScreen.storyboard */,
BD895C812824F27A000AB87A /* Info.plist */,
BD506E85282629E000AB96ED /* Application */,
BD506E84282629DD00AB96ED /* Model */,
BD506E86282629EE00AB96ED /* Service */,
BD506E83282629D600AB96ED /* Network */,
BD506E87282629FB00AB96ED /* Controller */,
BD506E8928262A2700AB96ED /* Resource */,
BD506E8828262A0B00AB96ED /* Support */,
);
path = Seminar4;
sourceTree = "<group>";
Expand Down Expand Up @@ -207,6 +274,10 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
BD895C8E2825BC7C000AB87A /* UserService.swift in Sources */,
BD895C882825A494000AB87A /* APIConstants.swift in Sources */,
BD895C8C2825B671000AB87A /* LoginModel.swift in Sources */,
BD895C8A2825A7EB000AB87A /* NetworkResult.swift in Sources */,
BD895C782824F279000AB87A /* ViewController.swift in Sources */,
BD895C742824F279000AB87A /* AppDelegate.swift in Sources */,
BD895C762824F279000AB87A /* SceneDelegate.swift in Sources */,
Expand Down Expand Up @@ -361,7 +432,7 @@
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = W7P3R7ZL78;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Seminar4/Info.plist;
INFOPLIST_FILE = Seminar4/Support/Info.plist;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UIMainStoryboardFile = Main;
Expand Down Expand Up @@ -390,7 +461,7 @@
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = W7P3R7ZL78;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Seminar4/Info.plist;
INFOPLIST_FILE = Seminar4/Support/Info.plist;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UIMainStoryboardFile = Main;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
File renamed without changes.
24 changes: 0 additions & 24 deletions Seminar/Seminar4/Seminar4/Base.lproj/Main.storyboard

This file was deleted.

68 changes: 68 additions & 0 deletions Seminar/Seminar4/Seminar4/Controller/ViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// ViewController.swift
// Seminar4
//
// Created by taehy.k on 2022/05/06.
//

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var nameTextField: UITextField!
@IBOutlet weak var emailTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!

override func viewDidLoad() {
super.viewDidLoad()

}

// 로그인 버튼을 눌렀을 때 로그인 서버 통신 함수를 호출합니다.
@IBAction func loginButtonTapped(_ sender: Any) {
print("로그인")
login()
}
}

extension ViewController {

// 서버 통신 코드를 실제로 뷰 컨트롤러에서 호출해서 사용하는 부분입니다.
func login() {

// 각각의 텍스트 필드의 있는 값을 받아옵니다.
guard let name = nameTextField.text else { return }
guard let email = emailTextField.text else { return }
guard let password = passwordTextField.text else { return }

// 서버 통신 서비스 코드를 싱글톤 변수를 통해서 접근하고 있네요.
// 호출 후에 받은 응답을 가지고, 적절한 처리를 해주고 있습니다.
UserService.shared.login(
name: name,
email: email,
password: password) { response in
switch response {
case .success(let data):
guard let data = data as? LoginResponse else { return }
print(data)
self.alert(message: data.message)
case .requestErr(let err):
print(err)
case .pathErr:
print("pathErr")
case .serverErr:
print("serverErr")
case .networkFail:
print("networkFail")
}
}
}

// 알림창을 띄우는 함수입니다.
func alert(message: String) {
let alertVC = UIAlertController(title: message, message: nil, preferredStyle: .alert)
let okAction = UIAlertAction(title: "확인", style: .default, handler: nil)
alertVC.addAction(okAction)
present(alertVC, animated: true)
}
}
20 changes: 20 additions & 0 deletions Seminar/Seminar4/Seminar4/Model/LoginModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// LoginModel.swift
// Seminar4
//
// Created by taehy.k on 2022/05/07.
//

import Foundation

struct LoginResponse: Codable {
let status: Int
let success: Bool?
let message: String
let data: LoginData?
}

struct LoginData: Codable {
let name: String
let email: String
}
27 changes: 27 additions & 0 deletions Seminar/Seminar4/Seminar4/Network/APIConstants.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// APIConstants.swift
// Seminar4
//
// Created by taehy.k on 2022/05/07.
//

import Foundation

/*
API Constants

- 주소를 모아놓은 구조체
- 이름은 형식상 API를 모아 놓았다는 느낌으로 APIConstants라고 지음
*/

struct APIConstants {
// MARK: - Base URL
static let baseURL = "http://13.124.62.236"

// MARK: - Feature URL
// loginURL = "http://13.124.62.236/auth/signin"
static let loginURL = baseURL + "/auth/signin"

// signUpURL = "http://13.124.62.236/auth/signin"
static let signUpURL = baseURL + "/auth/signup"
}
23 changes: 23 additions & 0 deletions Seminar/Seminar4/Seminar4/Network/NetworkResult.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// NetworkResult.swift
// Seminar4
//
// Created by taehy.k on 2022/05/07.
//

/*
서버 통신의 결과를 핸들링하기 위한 열거형

- 서버 통신의 응답으로는 정말 다양한 결과들이 넘어옵니다.
- 단순히 성공 또는 실패로만 구분되지 않고,
- 요청은 성공했으나 서버 내부적인 문제로 값이 넘어오지 않거나,
- 요청을 잘못된 경로나 방식으로 해서 응답을 못 받을수도 있죠.
*/

enum NetworkResult<T> {
case success(T) // 서버 통신 성공
case requestErr(T) // 요청 에러가 발생
case pathErr // 경로 에러
case serverErr // 서버의 내부 에러
case networkFail // 네트워크 연결 실패
}
Loading

0 comments on commit 536b807

Please sign in to comment.