Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions ByeBoo-iOS/ByeBoo-iOS/Domain/DomainDependencyAssembler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ struct DomainDependencyAssembler: DependencyAssembler {
return DefaultCheckHasEnterMyPageUseCase(repository: userRepository)
}

DIContainer.shared.register(type: IsValidQuestAnswerUseCase.self) { _ in
return DefaultIsValidQuestAnswerUseCase()
}

DIContainer.shared.register(type: CheckAlarmEnabledUseCase.self) { _ in
return DefaultCheckAlarmEnabledUseCase(repository: userRepository)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// isValidQuestAnswerUseCase.swift
// ByeBoo-iOS
//
// Created by 이나연 on 12/4/25.
//

import Foundation

protocol IsValidQuestAnswerUseCase {
func execute(previousText: String, changingText: String) -> Bool
}

struct DefaultIsValidQuestAnswerUseCase: IsValidQuestAnswerUseCase {
func execute(previousText: String, changingText: String) -> Bool {
if previousText.isEmpty {
if isValidAnswerText(text: changingText) {
return true
} else {
return false
}
} else {
if previousText != changingText && isValidAnswerText(text: changingText) {
return true
} else {
return false
}
}
}

private func isValidAnswerText(text: String) -> Bool {
if (text.count >= 10) && !text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
return true
} else {
return false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ extension QuestTextField: UITextViewDelegate {
}
count = textView.text.count
textCount.text = "(\(count)/\(limitCount))"
delegate?.changeStyle(count: count)
delegate?.changeStyleWhenEditing(changedText: textView.text)
delegate?.updateButtonWhenWriting(text: textView.text)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,3 @@ extension WriteActiveTypeQuestView {
)
}
}

extension WriteActiveTypeQuestView: QuestCompleteProtocol {
func changeStyle(count: Int) {
if count == 1 {
confirmButton.updateType(.enabled)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ final class WriteQuestionTypeQuestView: BaseView {
errorIcon,
descriptionLabel
)
setDelegate()
}

override func setStyle() {
Expand All @@ -59,10 +58,6 @@ final class WriteQuestionTypeQuestView: BaseView {
}
}

private func setDelegate() {
questTextField.delegate = self
}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.endEditing(true)
}
Expand Down Expand Up @@ -108,14 +103,3 @@ extension WriteQuestionTypeQuestView {
)
}
}

extension WriteQuestionTypeQuestView: QuestCompleteProtocol {
func changeStyle(count: Int) {
if (count >= 10) &&
(!questTextField.textView.text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty) {
confirmButton.updateType(.enabled)
} else {
confirmButton.updateType(.disabled)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ extension WriteActiveTypeQuestViewController: UIImagePickerControllerDelegate, U
rootView.imageContainer.changeIconHidden()
rootView.imgCount = 1
rootView.updateImageCountLabel(count: rootView.imgCount)
rootView.changeStyle(count: rootView.imgCount)
changeCount(count: rootView.imgCount)
self.image = image
isImageChanged = questMode == .edit ? true : false
}
Expand Down Expand Up @@ -399,8 +399,14 @@ extension WriteActiveTypeQuestViewController: EditQuestProtocol {
}

extension WriteActiveTypeQuestViewController: QuestCompleteProtocol {
func changeStyleWhenEditing(changedText: String) {
if answerText != changedText {
func changeCount(count: Int) {
if count == 1 {
rootView.confirmButton.updateType(.enabled)
}
}

func updateButtonWhenWriting(text: String) {
if rootView.imgCount == 1 && answerText != text {
rootView.confirmButton.updateType(.enabled)
} else {
rootView.confirmButton.updateType(.disabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,18 @@ extension WriteQuestionTypeQuestViewController: ToastPresentable, ToastErrorHand
}
}
.store(in: &cancellables)

viewModel.output.isValidTextPublisher
.receive(on: DispatchQueue.main)
.sink { [weak self] result in
switch result {
case true:
self?.rootView.confirmButton.updateType(.enabled)
case false:
self?.rootView.confirmButton.updateType(.disabled)
}
}
.store(in: &cancellables)
}
}

Expand Down Expand Up @@ -285,11 +297,7 @@ extension WriteQuestionTypeQuestViewController: EditQuestProtocol {
}

extension WriteQuestionTypeQuestViewController: QuestCompleteProtocol {
func changeStyleWhenEditing(changedText: String) {
if answerText != changedText {
rootView.confirmButton.updateType(.enabled)
} else {
rootView.confirmButton.updateType(.disabled)
}
func updateButtonWhenWriting(text: String) {
viewModel.action(.textFieldEditing(answerText: self.answerText, text: text))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,32 @@ struct WriteQuestionTypeViewModel: ViewModelType {
private let saveQuestTypeUseCase: SaveQuestTypeUseCase
private let getQuestInfoUseCase: GetQuestInfoUseCase
private let editQuestTypeUseCase: EditQuestTypeUseCase
private let isValidQuestAnswerUseCase: IsValidQuestAnswerUseCase

private let questInfoResultSubject: PassthroughSubject<Result<QuestInfoEntity, ByeBooError>, Never> = .init()
private let questInfoWhenEditModeSubject: PassthroughSubject<Result<QuestInfoEntity, ByeBooError>, Never> = .init()
private let didSuccessPostSubject: PassthroughSubject<Result<Void, ByeBooError>, Never> = .init()
private let didSuccessEditSubject: PassthroughSubject<Result<Void, ByeBooError>, Never> = .init()
private let isValidTextSubject: PassthroughSubject<Bool, Never> = .init()

init(
saveQuestTypeUseCase: SaveQuestTypeUseCase,
getQuestInfoUseCase: GetQuestInfoUseCase,
editQuestTypeUseCase: EditQuestTypeUseCase
editQuestTypeUseCase: EditQuestTypeUseCase,
isValidQuestAnswerUseCase: IsValidQuestAnswerUseCase

){
self.saveQuestTypeUseCase = saveQuestTypeUseCase
self.getQuestInfoUseCase = getQuestInfoUseCase
self.editQuestTypeUseCase = editQuestTypeUseCase
self.isValidQuestAnswerUseCase = isValidQuestAnswerUseCase

output = Output(
questInfoResultPublisher: questInfoResultSubject.eraseToAnyPublisher(),
didSuccessPostPublisher: didSuccessPostSubject.eraseToAnyPublisher(),
questInfoWhenEditModeResultPublisher: questInfoWhenEditModeSubject.eraseToAnyPublisher(),
didSuccessEditPublisher: didSuccessEditSubject.eraseToAnyPublisher()
didSuccessEditPublisher: didSuccessEditSubject.eraseToAnyPublisher(),
isValidTextPublisher: isValidTextSubject.eraseToAnyPublisher()
)
}
}
Expand All @@ -47,13 +52,15 @@ extension WriteQuestionTypeViewModel {
case viewDidLoad(quesetID: Int)
case presentCompleteView(questID: Int, answer: String, emotionState: String?, isEdit: Bool)
case viewDidLoadWhenEditMode(questID: Int)
case textFieldEditing(answerText: String, text: String)
}

struct Output {
let questInfoResultPublisher: AnyPublisher<Result<QuestInfoEntity, ByeBooError>, Never>
let didSuccessPostPublisher: AnyPublisher<Result<Void, ByeBooError>, Never>
let questInfoWhenEditModeResultPublisher: AnyPublisher<Result<QuestInfoEntity, ByeBooError>, Never>
let didSuccessEditPublisher: AnyPublisher<Result<Void, ByeBooError>, Never>
let isValidTextPublisher: AnyPublisher<Bool, Never>
}

func action(_ trigger: Input) {
Expand All @@ -72,6 +79,8 @@ extension WriteQuestionTypeViewModel {
guard let emotionState = emotionState else { return }
postQuestType(questID: questID, answer: answer, emotionState: emotionState)
}
case .textFieldEditing(let answerText, let text):
isValidText(previousText: answerText, changingText: text)
}
}
}
Expand Down Expand Up @@ -120,4 +129,9 @@ extension WriteQuestionTypeViewModel {
}
}
}

private func isValidText(previousText: String, changingText: String) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 if-else문을 최대한 안 쓰는 편이라 아래처럼 해도 괜찮을 것 같아요. 참고만 해주세용!

let isValidText: Bool = isValidQuestAnswerUseCase.execute(previousText: previousText, changingText: changingText)
isValidSubject.send(isValidText)

let isValidText: Bool = isValidQuestAnswerUseCase.execute(previousText: previousText, changingText: changingText)
isValidTextSubject.send(isValidText)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ struct PresentationDependencyAssembler: DependencyAssembler {
DIContainer.shared.register(type: WriteQuestionTypeViewModel.self) { container in
guard let getQuestInfoUseCase = container.resolve(type: GetQuestInfoUseCase.self),
let saveQuestTypeUseCase = container.resolve(type: SaveQuestTypeUseCase.self),
let editQuestTypeUseCase = container.resolve(type: EditQuestTypeUseCase.self) else {
let editQuestTypeUseCase = container.resolve(type: EditQuestTypeUseCase.self),
let isValidQuestAnswerUseCase = container.resolve(type: IsValidQuestAnswerUseCase.self) else {
ByeBooLogger.error(ByeBooError.DIFailedError)
return
}
return WriteQuestionTypeViewModel(
saveQuestTypeUseCase: saveQuestTypeUseCase,
getQuestInfoUseCase: getQuestInfoUseCase,
editQuestTypeUseCase: editQuestTypeUseCase
editQuestTypeUseCase: editQuestTypeUseCase,
isValidQuestAnswerUseCase: isValidQuestAnswerUseCase
)
}

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

protocol QuestCompleteProtocol: AnyObject {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기존에 만들어두신 EditQuestProtocol에 메서드를 추가하는 대신 QuestCompleteProtocol을 따로 정의한 이유가 있는지 궁금합니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

원래 기존에는 QuestCompleteProtocol이 있고 수정기능을 추가하면서 edit protocol을 만들었는데요!
리팩토링을 하다보니 텍스트필드 유효성을 검증해서 완료버튼을 누르기까지의 과정은 수정과 기존 쓰기 버전이 둘이 비슷하다고 생각하여 관련로직은 Complete 프로토콜에 작성했습니다..!! edit protocol에는 처음 수정으로 들어갈 때 관련 정보를 불러오는 것을 수행합니다!

func changeStyle(count: Int)
func changeStyleWhenEditing(changedText: String)
func changeCount(count: Int)
func updateButtonWhenWriting(text: String)
}

extension QuestCompleteProtocol {
func changeStyle(count: Int) { return }
func changeStyleWhenEditing(changedText: String) { return }
func changeCount(count: Int) { return }
}