Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOPT 세미나 4차 과제 #8

Open
wants to merge 21 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
07836b0
4차 세미나 초기 파일 추가
LaonCoder Nov 2, 2024
c6c336d
[Feat] 네트워크 테스트용 ServerHomeController 구현, 앱스토어 탭바 구현
LaonCoder Nov 7, 2024
3a44c9f
[Feat] 서버 페이지 1차 구현
LaonCoder Nov 7, 2024
c23fdd0
[Feat] 4주차 과제 로그인, 내 취미 및 다른 사람 취미 조회 기능 구현
LaonCoder Nov 8, 2024
88e47be
[Refactor] 로그인 페이지 리팩토링
LaonCoder Nov 9, 2024
a2df36f
[Refactor] ServerHomeController 내부 코드 개선
LaonCoder Nov 9, 2024
c0f9640
[Refactor] ServerHomeController 내부 로그아웃 셀 위치 변경
LaonCoder Nov 9, 2024
f1aeecd
[Refactor] UserRegisterController 내부 코드 및 레이아웃 개선
LaonCoder Nov 9, 2024
f283d9b
[Refactor] MyHobbyViewController 제거 및 사용자 취미 plain 셀로 노출
LaonCoder Nov 9, 2024
54424b7
[Feat] 사용자 정보 변경 기능 구현 및 UserService 클래스 수정
LaonCoder Nov 9, 2024
c0e9b66
[Refactor] 폴더 구조 변경 및 UserService 리팩토링
LaonCoder Nov 9, 2024
1b20d2e
[Feat] 앱 시작 시 KeyChain에 기존에 존재하던 토큰 제거하는 로직 추가
LaonCoder Nov 9, 2024
c7062ac
[Rename] 잘못 들어간 파일 위치 수정
LaonCoder Nov 9, 2024
abbda33
[Refactor] alert 창 사용하는 부분 showAlert 사용하도록 수정
LaonCoder Nov 9, 2024
7c96469
[Refactor] UserHobbyLookUpController 내부 레이아웃 수정
LaonCoder Nov 9, 2024
50c76e5
[Chore] 디버깅용 print 문 제거
LaonCoder Nov 9, 2024
b6bf52e
[Feat] 취미 변경 시 ServerHomeController에 반영되도록 delegate 구현
LaonCoder Nov 9, 2024
a734ac9
[Feat] delegate 누락 추가 / 로그아웃 시 토큰 삭제하도록 추가
LaonCoder Nov 9, 2024
4589365
[Refactor] 서버 api 받아오는 곳에 DispatchQueue.main.async로 감싸주도록 변경
LaonCoder Nov 9, 2024
e5824aa
[Refactor] interceptor 사용 코드 리팩토링
LaonCoder Nov 9, 2024
d8a9d9f
[Refactor] Session을 활용하여 Request 공통 처리 / APIEventLogger 추가 및 적용
LaonCoder Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -104,4 +104,7 @@ xcuserdata
/*.gcno
**/xcshareddata/WorkspaceSettings.xcsettings

## XCConfig file ##
*.xcconfig

# End of https://www.toptal.com/developers/gitignore/api/swiftpackagemanager,swift,xcode
10 changes: 7 additions & 3 deletions 35-Seminar/App/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -10,10 +10,14 @@ import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {



func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.

// 앱 삭제 후 재설치하는 경우, 토큰 초기화 (KeyChain에 저장된 토큰 제거)
if TokenManager.shared.isNewUser {
TokenManager.shared.clearTokens()
TokenManager.shared.isNewUser = false
}

return true
}

3 changes: 1 addition & 2 deletions 35-Seminar/App/SceneDelegate.swift
Original file line number Diff line number Diff line change
@@ -14,8 +14,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
self.window = UIWindow(windowScene: windowScene)
let navigationController = UINavigationController(rootViewController: AppstoreEntryPointController())
self.window?.rootViewController = navigationController
self.window?.rootViewController = AppstoreTabBarController()
self.window?.makeKeyAndVisible()
}

7 changes: 7 additions & 0 deletions 35-Seminar/Info.plist
Original file line number Diff line number Diff line change
@@ -2,6 +2,13 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BASE_URL</key>
<string>$(BASE_URL)</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
2 changes: 0 additions & 2 deletions 35-Seminar/Week3/Test/Seminar3TableViewTestController.swift
Original file line number Diff line number Diff line change
@@ -189,8 +189,6 @@ extension Seminar3TableViewTestController: UITableViewDelegate, UITableViewDataS

final class TableViewCell: UITableViewCell {

static let identifier = "TableViewCell"

private let containerView = UIView()

private let appIconImageView = UIImageView().then {
2 changes: 0 additions & 2 deletions 35-Seminar/Week3/Views/Cells/PopularRankingCell.swift
Original file line number Diff line number Diff line change
@@ -11,8 +11,6 @@ import Then

final class PopularRankingCell: UITableViewCell {

static let identifier = "PopularRankingCell"

private let containerView = UIView()

private let appIconImageView = UIImageView().then {
42 changes: 42 additions & 0 deletions 35-Seminar/Week4/Feature/ArcadeHome/ArcadeHomeController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// ArcadeHomeController.swift
// 35-Seminar
//
// Created by 최지석 on 11/7/24.
//

import UIKit

final class ArcadeHomeController: UIViewController {

private let titleLabel = UILabel().then {
$0.attributedText = .makeAttributedString(text: "Arcade",
color: .black,
font: UIFont.systemFont(ofSize: 36, weight: .bold))
$0.addBottomBorder(color: UIColor.Week2ColorSet.borderGray)
}


override func viewDidLoad() {
super.viewDidLoad()

makeUI()
}


private func makeUI() {
view.backgroundColor = .white

view.addSubViews(
titleLabel
)

titleLabel.snp.makeConstraints {
$0.top.equalTo(view.safeAreaLayoutGuide.snp.top)
$0.height.equalTo(60)
$0.left.right.equalToSuperview().inset(20)
}
}
}


162 changes: 162 additions & 0 deletions 35-Seminar/Week4/Feature/Auth/UserLoginController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
//
// UserLoginController.swift
// 35-Seminar
//
// Created by 최지석 on 11/8/24.
//

import UIKit
import SnapKit
import Then

protocol UserLoginControllerDelegate: AnyObject {
func didLogin(username: String)
}

class UserLoginController: UIViewController {

weak var delegate: UserLoginControllerDelegate?

private let containerView = UIView()

private let cancelButton = UIButton().then {
var config = UIButton.Configuration.plain()
config.attributedTitle = AttributedString(.makeAttributedString(text: "취소",
color: .systemBlue,
font: UIFont.systemFont(ofSize: 16,
weight: .regular)))
config.contentInsets = .zero
$0.configuration = config
}

private let titleLabel = UILabel().then {
$0.attributedText = .makeAttributedString(text: "Apple 계정 암호",
color: .black,
font: .systemFont(ofSize: 30, weight: .bold))
}

private let usernameTextField = UITextField().then {
$0.placeholder = "이름"
$0.clipsToBounds = true
$0.layer.cornerRadius = 10
$0.backgroundColor = UIColor.secondarySystemBackground
$0.configureDefaultSettings()
$0.setLeftInset(10)
}

private let passwordTextField = UITextField().then {
$0.placeholder = "비밀번호"
$0.clipsToBounds = true
$0.layer.cornerRadius = 10
$0.backgroundColor = UIColor.secondarySystemBackground
$0.isSecureTextEntry = true
$0.configureDefaultSettings()
$0.setLeftInset(10)
}

private let loginButton = UIButton().then {
var config = UIButton.Configuration.plain()
config.attributedTitle = AttributedString(.makeAttributedString(text: "로그인",
color: .systemBlue,
font: UIFont.systemFont(ofSize: 16,
weight: .regular)))
$0.configuration = config
}


override func viewDidLoad() {
super.viewDidLoad()

makeUI()
bindAction()
}


private func makeUI() {
view.backgroundColor = .white

view.addSubViews(
containerView.addSubViews(
cancelButton,
titleLabel,
usernameTextField,
passwordTextField,
loginButton
)
)

containerView.snp.makeConstraints {
$0.edges.equalToSuperview()
}

cancelButton.snp.makeConstraints {
$0.top.left.equalToSuperview().inset(20)
}

titleLabel.snp.makeConstraints {
$0.top.equalToSuperview().offset(56)
$0.centerX.equalToSuperview()
}

usernameTextField.snp.makeConstraints {
$0.top.equalTo(titleLabel.snp.bottom).offset(32)
$0.leading.trailing.equalToSuperview().inset(20)
$0.height.equalTo(44)
}

passwordTextField.snp.makeConstraints {
$0.top.equalTo(usernameTextField.snp.bottom).offset(12)
$0.leading.trailing.equalToSuperview().inset(20)
$0.height.equalTo(44)
}

loginButton.snp.makeConstraints {
$0.top.equalTo(passwordTextField.snp.bottom).offset(20)
$0.centerX.equalToSuperview()
}
}


private func bindAction() {
loginButton.addAction(UIAction { [weak self] _ in
guard let self else { return }
loginButtonDidTap()
}, for: .touchUpInside)

cancelButton.addAction(UIAction { [weak self] _ in
guard let self else { return }
cancelButtonDidTap()
}, for: .touchUpInside)
}


private func loginButtonDidTap() {
guard let username = usernameTextField.text,
let password = passwordTextField.text else { return }

UserService.shared.login(username: username,
password: password) { [weak self] result in
DispatchQueue.main.async { [weak self] in
guard let self else { return }

switch result {
case .success(let token):

// 토큰 저장
TokenManager.shared.setAccessToken(token)

delegate?.didLogin(username: username)

dismiss(animated: true)
case .failure(let error):
showAlert(title: "로그인 실패", message: error.errorMessage)
}
}
}
}


private func cancelButtonDidTap() {
dismiss(animated: true)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// GameHomeController.swift
// 35-Seminar
//
// Created by 최지석 on 11/7/24.
//

import UIKit

final class GameHomeController: UIViewController {

private let titleLabel = UILabel().then {
$0.attributedText = .makeAttributedString(text: "게임",
color: .black,
font: UIFont.systemFont(ofSize: 36, weight: .bold))
$0.addBottomBorder(color: UIColor.Week2ColorSet.borderGray)
}


override func viewDidLoad() {
super.viewDidLoad()

makeUI()
}


private func makeUI() {
view.backgroundColor = .white

view.addSubViews(
titleLabel
)

titleLabel.snp.makeConstraints {
$0.top.equalTo(view.safeAreaLayoutGuide.snp.top)
$0.height.equalTo(60)
$0.left.right.equalToSuperview().inset(20)
}
}
}

Loading