-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feat] #159 - 출석하기 UI 구현
- Loading branch information
Showing
27 changed files
with
886 additions
and
36 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
27 changes: 0 additions & 27 deletions
27
SOPT-iOS/Projects/Core/Sources/Extension/UIKit+/UIViewController+.swift
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
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
40 changes: 40 additions & 0 deletions
40
SOPT-iOS/Projects/Data/Sources/Repository/AttendanceRepository.swift
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,40 @@ | ||
// | ||
// AttendanceRepository.swift | ||
// Data | ||
// | ||
// Created by 김영인 on 2023/04/16. | ||
// Copyright © 2023 SOPT-iOS. All rights reserved. | ||
// | ||
|
||
import Combine | ||
|
||
import Core | ||
import Domain | ||
import Network | ||
|
||
public class AttendanceRepository { | ||
|
||
private let attendanceService: AttendanceService | ||
private let cancelBag = CancelBag() | ||
|
||
public init(service: AttendanceService) { | ||
self.attendanceService = service | ||
} | ||
} | ||
|
||
extension AttendanceRepository: AttendanceRepositoryInterface { | ||
|
||
public func fetchLectureRound(lectureId: Int) -> AnyPublisher<Int, Error> { | ||
return self.attendanceService | ||
.fetchAttendanceRound(lectureId: lectureId) | ||
.compactMap { $0.data?.round } | ||
.eraseToAnyPublisher() | ||
} | ||
|
||
public func postAttendance(lectureRoundId: Int, code: Int) -> AnyPublisher<Bool, Error> { | ||
return self.attendanceService | ||
.postAttendance(lectureRoundId: lectureRoundId, code: code) | ||
.map { $0.success } | ||
.eraseToAnyPublisher() | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/AttendanceRepositoryInterface.swift
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,16 @@ | ||
// | ||
// AttendanceRepositoryInterface.swift | ||
// Domain | ||
// | ||
// Created by 김영인 on 2023/04/16. | ||
// Copyright © 2023 SOPT-iOS. All rights reserved. | ||
// | ||
|
||
import Combine | ||
|
||
import Core | ||
|
||
public protocol AttendanceRepositoryInterface { | ||
func fetchLectureRound(lectureId: Int) -> AnyPublisher<Int, Error> | ||
func postAttendance(lectureRoundId: Int, code: Int) -> AnyPublisher<Bool, Error> | ||
} |
64 changes: 64 additions & 0 deletions
64
SOPT-iOS/Projects/Domain/Sources/UseCase/AttendanceUseCase.swift
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,64 @@ | ||
// | ||
// AttendanceUseCase.swift | ||
// Domain | ||
// | ||
// Created by 김영인 on 2023/04/16. | ||
// Copyright © 2023 SOPT-iOS. All rights reserved. | ||
// | ||
|
||
import Combine | ||
|
||
import Core | ||
|
||
public protocol AttendanceUseCase { | ||
func fetchLectureRound(lectureId: Int) | ||
func postAttendance(lectureRoundId: Int, code: Int) | ||
var lectureRound: PassthroughSubject<Int, Never> { get set } | ||
var attendSuccess: PassthroughSubject<Bool, Never> { get set } | ||
} | ||
|
||
public class DefaultAttendanceUseCase { | ||
|
||
private let repository: AttendanceRepositoryInterface | ||
private var cancelBag = CancelBag() | ||
|
||
public var lectureRound = PassthroughSubject<Int, Never>() | ||
public var attendSuccess = PassthroughSubject<Bool, Never>() | ||
|
||
public init(repository: AttendanceRepositoryInterface, cancelBag: CancelBag = CancelBag()) { | ||
self.repository = repository | ||
self.cancelBag = cancelBag | ||
} | ||
} | ||
|
||
extension DefaultAttendanceUseCase: AttendanceUseCase { | ||
public func fetchLectureRound(lectureId: Int) { | ||
repository.fetchLectureRound(lectureId: lectureId) | ||
.sink(receiveCompletion: { event in | ||
switch event { | ||
case .failure(let error): | ||
print("failure: fetchLectureRound \(error)") | ||
case .finished: | ||
print("completion: fetchLectureRound \(event)") | ||
} | ||
}, receiveValue: { result in | ||
self.lectureRound.send(result) | ||
}) | ||
.store(in: cancelBag) | ||
} | ||
|
||
public func postAttendance(lectureRoundId: Int, code: Int) { | ||
repository.postAttendance(lectureRoundId: lectureRoundId, code: code) | ||
.sink(receiveCompletion: { event in | ||
switch event { | ||
case .failure(let error): | ||
print("failure: postAttendance \(error)") | ||
case .finished: | ||
print("completion: postAttendance \(event)") | ||
} | ||
}, receiveValue: { result in | ||
self.attendSuccess.send(result) | ||
}) | ||
.store(in: cancelBag) | ||
} | ||
} |
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
107 changes: 107 additions & 0 deletions
107
...tures/AttendanceFeature/Sources/AttendanceScene/Component/OPAttendanceCodeTextField.swift
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,107 @@ | ||
// | ||
// OPCodeTextField.swift | ||
// AttendanceFeature | ||
// | ||
// Created by 김영인 on 2023/04/17. | ||
// Copyright © 2023 SOPT-iOS. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
import Core | ||
import DSKit | ||
|
||
@frozen | ||
public enum AttendanceCodeState { | ||
case empty | ||
case fill | ||
|
||
var backgroundColor: UIColor { | ||
switch self { | ||
case .empty: | ||
return DSKitAsset.Colors.black40.color | ||
case .fill: | ||
return DSKitAsset.Colors.black80.color | ||
} | ||
} | ||
|
||
var borderColor: CGColor { | ||
switch self { | ||
case .empty: | ||
return DSKitAsset.Colors.black40.color.cgColor | ||
case .fill: | ||
return DSKitAsset.Colors.purple40.color.cgColor | ||
} | ||
} | ||
} | ||
|
||
/// 숫자코드 입력 자리수, 숫자 | ||
public struct AttendanceCodeInfo { | ||
var idx: Int | ||
var text: String? | ||
} | ||
|
||
public class OPAttendanceCodeTextField: UITextField { | ||
|
||
// MARK: - Init | ||
|
||
public override init(frame: CGRect) { | ||
super.init(frame: .zero) | ||
|
||
self.setUI() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
} | ||
|
||
// MARK: - Methods | ||
|
||
extension OPAttendanceCodeTextField { | ||
|
||
public var textChanged: Driver<AttendanceCodeInfo> { | ||
self.publisher(for: .editingChanged) | ||
.map { _ in | ||
AttendanceCodeInfo( | ||
idx: self.tag, | ||
text: self.text | ||
) | ||
} | ||
.asDriver() | ||
} | ||
|
||
public func updateUI(text: String?) { | ||
let state: AttendanceCodeState = (text == "") ? .empty : .fill | ||
|
||
backgroundColor = state.backgroundColor | ||
layer.borderColor = state.borderColor | ||
self.text = text | ||
} | ||
|
||
/// 복사 붙여넣기 방지 | ||
override public func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool { | ||
return false | ||
} | ||
} | ||
|
||
|
||
// MARK: - UI | ||
|
||
extension OPAttendanceCodeTextField { | ||
private func setUI() { | ||
backgroundColor = AttendanceCodeState.empty.backgroundColor | ||
|
||
textColor = DSKitAsset.Colors.purple40.color | ||
font = .Main.headline2 | ||
textAlignment = .center | ||
tintColor = .clear | ||
|
||
layer.cornerRadius = 8 | ||
layer.borderWidth = 1 | ||
layer.borderColor = AttendanceCodeState.empty.borderColor | ||
|
||
keyboardType = .numberPad | ||
textContentType = .oneTimeCode | ||
} | ||
} |
Oops, something went wrong.