Skip to content

Conversation

Genesis2010
Copy link
Contributor

✨ 해결한 이슈

🛠️ 작업내용

  • 하단 버튼의 title 을 다음 에서 완료로 변경
  • ShareViewController 의 비즈니스 로직을 ShareViewModel 로 변경
구현 내용 14 pro
�Img

🖥️ 주요 코드 설명

ShareViewModel

final class ShareViewModel: ViewModelType {

    private let appURL = "TOASTER://"
    private var urlString = ""
    
    struct Input {
        let selectedClip: AnyPublisher<RemindClipModel?, Never>
        let completeButtonTap: AnyPublisher<Void, Never>
        let closeButtonTap: AnyPublisher<Void, Never>
    }
    
    struct Output {
        let isSeleted: AnyPublisher<Bool, Never>
        let completeButtonAction: AnyPublisher<Bool, Never>
        let closeButtonAction: AnyPublisher<Void, Never>
    }
    
    func transform(_ input: Input) -> Output { // ... }

    func bindUrl(_ url: String) {
        self.urlString = url
    }
    
    func readAppURL() -> String {
        return appURL
    }
}

다음과 같이 MVVM input-output 구조로 변경하여 로직을 분리했습니다.

단순히 데이터를 갖고 있는 프로퍼티는 input-output 구조에 포함 시키지 않고 bindUrl, readAppURL 메서드를 통해 접근하거나 값을 바꾸도록 하였습니다.

private extension ShareViewModel {
    func postSaveLink(id: Int?) -> AnyPublisher<Bool, Error> {
        let request = PostSaveLinkRequestDTO(linkUrl: self.urlString, categoryId: id)
        
        return Future<Bool, Error> { promise in
            NetworkService.shared.toastService.postSaveLink(requestBody: request) { result in
                switch result {
                case .success:
                    print("저장 성공")
                    promise(.success(true))
                case .networkFail, .unAuthorized, .notFound, .badRequest, .serverErr, .decodeErr, .unProcessable:
                    print("저장 실패")
                    promise(.failure(NSError(domain: "PostSaveLinkError", code: 0, userInfo: [NSLocalizedDescriptionKey: "링크 저장에 실패했습니다."])))
                }
            }
        }
        .eraseToAnyPublisher()
    }
}

저번 회의때 나온 얘기 처럼 API 호출부분을 에서 바로 Publisher 를 반환할 수 있게 변경했고 Error 처리도 가능하게 추가해두었습니다.

✅ Checklist

  • 필요없는 주석, 프린트문 제거했는지 확인
  • 컨벤션 지켰는지 확인

@Genesis2010 Genesis2010 added ✨ Feat 새로운 기능 구현 ♻️ Refactor 전면 수정이 있을 때 사용합니다 🚗 준혁 준혁 선생님 작업 labels Oct 2, 2024
@Genesis2010 Genesis2010 self-assigned this Oct 2, 2024
Copy link
Member

@mini-min mini-min left a comment

Choose a reason for hiding this comment

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

고생했습니다!
저도 컴바인이 아직 익숙하지 않아서 서로 피드백해가면서 더 좋은 방식을 찾아가면 좋을 것 같아유~

@Genesis2010 Genesis2010 merged commit b06b719 into develop Oct 6, 2024
@mini-min mini-min deleted the feat/#205 branch November 7, 2024 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Feat 새로운 기능 구현 ♻️ Refactor 전면 수정이 있을 때 사용합니다 🚗 준혁 준혁 선생님 작업
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feat] 링크 글자 수 제한 삭제 및 Share Extension 버튼 UI 수정
2 participants