Skip to content

Refactor/#413 코드리뷰 반영#433

Merged
juri123123 merged 3 commits intodevelopfrom
refactor/#413-코드리뷰-반영
May 6, 2026

Hidden character warning

The head ref may contain hidden characters: "refactor/#413-\ucf54\ub4dc\ub9ac\ubdf0-\ubc18\uc601"
Merged

Refactor/#413 코드리뷰 반영#433
juri123123 merged 3 commits intodevelopfrom
refactor/#413-코드리뷰-반영

Conversation

@juri123123
Copy link
Copy Markdown
Collaborator

🔗 연결된 이슈

📄 작업 내용

  • Feat/#387 ai api 연동 #394 해당 PR의 코드리뷰를 반영했습니다.
  • task의 취소를 관리할 수 있도록 변수로 선언하고 view가 사라질 때 cancel 및 메모리 해제 시켜주었습니다.
  • AI 답장 존재 여부에 따라 분기하던 로직을 usecase로 변경했습니다.

💻 주요 코드 설명

AIAnswerViewModel

  • viewDidDisappear에서 cancelTask를 호출해줬습니디ㅓㅏ!
private var fetchAIAnswerTask: Task<Void, Never>?

private func fetchAIAnswer() {
        fetchAIAnswerTask?.cancel()
        
        fetchAIAnswerTask = Task {
            do {
                AILoadingSubject.send(true)
                
                let answer = try await fetchAIAnswerUseCase.execute(
                    questID: questID,
                    isAnswerExists: isAnswerExists
                ).AIAnswer
                AIResultSubject.send(.success(answer))
                
                AILoadingSubject.send(false)
            } catch {
                guard let error = error as? ByeBooError else {
                    return
                }
                AIResultSubject.send(.failure(error))
                AILoadingSubject.send(false)
            }
        }
    }
    
    private func cancelTask() {
        fetchAIAnswerTask?.cancel()
        fetchAIAnswerTask = nil
    }

@juri123123 juri123123 requested review from dev-domo and y-eonee May 5, 2026 09:14
@juri123123 juri123123 self-assigned this May 5, 2026
@juri123123 juri123123 added 주리🐿️ refactor 기존 코드 리팩토링 labels May 5, 2026
@juri123123 juri123123 linked an issue May 5, 2026 that may be closed by this pull request
1 task
Copy link
Copy Markdown
Member

@y-eonee y-eonee left a comment

Choose a reason for hiding this comment

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

고생하셨습니당


func fetchAIAnswer(questID: Int, isAnswerExists: Bool) async throws -> AIAnswerEntity {
func fetchAIAnswer(questID: Int) async throws -> AIAnswerEntity {
// throw ByeBooError.unknownError
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

요 주석은 무엇인가용??

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

요 주석은 error를 던지는 경우를 테스트하기 위함입니닷!!!!

Comment on lines +85 to +88
private func cancelTask() {
fetchAIAnswerTask?.cancel()
fetchAIAnswerTask = nil
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

우와..저도 이번 스프린트부터 적용해보겠습니다!!

Copy link
Copy Markdown
Collaborator

@dev-domo dev-domo left a comment

Choose a reason for hiding this comment

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

Task 취소 관리 좋네요!

decodingType: AIAnswerResponseDTO.self
)
}
func fetchAIAnswer(questID: Int) async throws -> AIAnswerEntity {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

답장 존재 유무와 상관없이 계속 create을 하게 되나요?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

답장 존재 유무를 판단하고 fetch 할지 create 할지 결정하는 역할을 usecase로 넘겼습니다 !

extension AIAnswerViewModel {
private func fetchAIAnswer() {
Task {
fetchAIAnswerTask?.cancel()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

fetchAIAnswerTask?.cancel() 대신 만들어놓은 cancelTask를 호출하는 방법도 괜찮을 것 같아요!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

좋은 의견 감사합니다 !!!
추후 fetch하는 task가 많아질 경우 cancelTask 내부에 task들을 취소하는 로직을 모두 넣을 예정이라 통일성을 위해 분리해서 사용할 수 있도록 이렇게 작성했습니닷 !

@juri123123 juri123123 merged commit 2ce2a42 into develop May 6, 2026
1 check passed
@juri123123 juri123123 deleted the refactor/#413-코드리뷰-반영 branch May 6, 2026 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor 기존 코드 리팩토링 주리🐿️

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactor] 코드리뷰 반영

3 participants