-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2c5f08
commit 536b807
Showing
17 changed files
with
442 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
Seminar/Seminar4/Seminar4.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 // 네트워크 연결 실패 | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.