-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor/#413 코드리뷰 반영 #433
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
The head ref may contain hidden characters: "refactor/#413-\uCF54\uB4DC\uB9AC\uBDF0-\uBC18\uC601"
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,24 +122,23 @@ struct DefaultQuestRepository: QuestsInterface { | |
| .emptyAnswerStub() | ||
| } | ||
|
|
||
| func fetchAIAnswer(questID: Int, isAnswerExists: Bool) async throws -> AIAnswerEntity { | ||
| let result: AIAnswerResponseDTO | ||
|
|
||
| if isAnswerExists { | ||
| result = try await network.request( | ||
| QuestAPI.fetchAIAnswer(questID: questID), | ||
| decodingType: AIAnswerResponseDTO.self | ||
| ) | ||
| } else { | ||
| result = try await network.request( | ||
| QuestAPI.createAIAnswer(questID: questID), | ||
| decodingType: AIAnswerResponseDTO.self | ||
| ) | ||
| } | ||
| func fetchAIAnswer(questID: Int) async throws -> AIAnswerEntity { | ||
| let result: AIAnswerResponseDTO = try await network.request( | ||
| QuestAPI.createAIAnswer(questID: questID), | ||
| decodingType: AIAnswerResponseDTO.self | ||
| ) | ||
|
|
||
| return result.toEntity() | ||
| } | ||
|
|
||
| func createAIAnswer(questID: Int) async throws -> AIAnswerEntity { | ||
| let result = try await network.request( | ||
| QuestAPI.createAIAnswer(questID: questID), | ||
| decodingType: AIAnswerResponseDTO.self | ||
| ) | ||
| return result.toEntity() | ||
| } | ||
|
|
||
| // MARK: private function | ||
|
|
||
| private func makeSignedURL(imageKey: String) async throws -> String { | ||
|
|
@@ -188,14 +187,6 @@ struct DefaultQuestRepository: QuestsInterface { | |
| QuestAPI.editActive(questID: questID, request: editQuestActiveDTO) | ||
| ) | ||
| } | ||
|
|
||
| private func createAIAnswer(questID: Int) async throws -> AIAnswerEntity { | ||
| let result = try await network.request( | ||
| QuestAPI.createAIAnswer(questID: questID), | ||
| decodingType: AIAnswerResponseDTO.self | ||
| ) | ||
| return result.toEntity() | ||
| } | ||
| } | ||
|
|
||
| final class MockQuestsRepository: QuestsInterface { | ||
|
|
@@ -258,9 +249,13 @@ final class MockQuestsRepository: QuestsInterface { | |
| .emptyAnswerStub() | ||
| } | ||
|
|
||
| func fetchAIAnswer(questID: Int, isAnswerExists: Bool) async throws -> AIAnswerEntity { | ||
| func fetchAIAnswer(questID: Int) async throws -> AIAnswerEntity { | ||
| // throw ByeBooError.unknownError | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요 주석은 무엇인가용??
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요 주석은 error를 던지는 경우를 테스트하기 위함입니닷!!!! |
||
| .stub() | ||
| } | ||
|
|
||
| func createAIAnswer(questID: Int) async throws -> AIAnswerEntity { | ||
| try await Task.sleep(for: .seconds(2)) | ||
| throw ByeBooError.unknownError | ||
| // .stub() | ||
| return .stub() | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,8 @@ final class AIAnswerViewModel { | |
| private var questID: Int = 1 | ||
| private var isAnswerExists: Bool = false | ||
|
|
||
| private var fetchAIAnswerTask: Task<Void, Never>? | ||
|
|
||
| init(fetchAIAnswerUseCase: FetchAIAnswerUseCase) { | ||
| self.fetchAIAnswerUseCase = fetchAIAnswerUseCase | ||
|
|
||
|
|
@@ -34,6 +36,7 @@ final class AIAnswerViewModel { | |
| extension AIAnswerViewModel: ViewModelType { | ||
| enum Input { | ||
| case viewDidLoad(questID: Int, isAIAnswerExists: Bool) | ||
| case viewDidDisappear | ||
| } | ||
|
|
||
| struct Output { | ||
|
|
@@ -48,13 +51,17 @@ extension AIAnswerViewModel: ViewModelType { | |
| self.isAnswerExists = isExists | ||
|
|
||
| fetchAIAnswer() | ||
| case .viewDidDisappear: | ||
| cancelTask() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extension AIAnswerViewModel { | ||
| private func fetchAIAnswer() { | ||
| Task { | ||
| fetchAIAnswerTask?.cancel() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fetchAIAnswerTask?.cancel() 대신 만들어놓은 cancelTask를 호출하는 방법도 괜찮을 것 같아요!
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋은 의견 감사합니다 !!! |
||
|
|
||
| fetchAIAnswerTask = Task { | ||
| do { | ||
| AILoadingSubject.send(true) | ||
|
|
||
|
|
@@ -74,4 +81,9 @@ extension AIAnswerViewModel { | |
| } | ||
| } | ||
| } | ||
|
|
||
| private func cancelTask() { | ||
| fetchAIAnswerTask?.cancel() | ||
| fetchAIAnswerTask = nil | ||
| } | ||
|
Comment on lines
+85
to
+88
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 우와..저도 이번 스프린트부터 적용해보겠습니다!! |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
답장 존재 유무와 상관없이 계속 create을 하게 되나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
답장 존재 유무를 판단하고 fetch 할지 create 할지 결정하는 역할을 usecase로 넘겼습니다 !