Skip to content

Conversation

@J0onYEong
Copy link
Collaborator

@J0onYEong J0onYEong commented Apr 21, 2025

변경된 점

  • 오더북 데이터 저장소 리팩토링

오더북 데이터 저장소 리팩토링

기존 데이터 관리

레이어 책임
Presentation 텍스트 가공, 오더북 테이블 데이터 관리, UI업데이트 주기 관리, 테이블 크기 결정, 테이블 정렬방식 결정
Domain -
Data DTO를 엔티티화

기존 구현의 경우 2가지 문제점이 있다고 판단했습니다.

첫 번째로, 현재 구조는 외부 의존성(Binance API)에 대한 책임이 Presentation 레이어까지 노출된 형태라고 판단됩니다. 이는 클린 아키텍처 원칙에 위배됩니다.

현재 사용 중인 바이낸스 API는 오더북 테이블을 다음과 같은 방식으로 관리합니다:

  1. HTTP 요청을 통해 오더북의 전체 스냅샷을 가져옵니다.
  2. 응답으로 받은 lastUpdateId를 기준으로, 이후 WebSocket으로 수신되는 실시간 데이터의 유효성을 검증합니다.
  3. 유효한 실시간 데이터를 기존 오더북 테이블에 반영해 지속적으로 상태를 업데이트합니다.

이 과정은 명확히 외부 API의 프로토콜에 종속적인 처리 로직이며, Presentation 레이어가 알 필요 없는 세부 구현입니다.
해당 절차가 Presentation에 그대로 들어나 있기에 외부환경에 의존하게 됩니다.

두 번째로, 클린 아키텍처 관점에서 이는 적절하지 않습니다.

오더북 테이블 데이터는 단순히 화면에 보여주기 위한 데이터일 뿐이며, 도메인 로직이 개입되지 않는 단순 데이터입니다.
따라서 해당 데이터는 도메인 또는 프레젠테이션 레이어에서 관리하기보다는, 데이터 계층에서 직접 처리하고 전달하는 것이 더 적절한 역할 분리입니다.

변경된 책임

외부 의존적인 관리법과 테이블 데이터 자체를 데이터 레이어로 이동시켰습니다.

정렬 및 슬라이싱과 같은 데이터 가공의 경우 비즈니스 로직이라고 판단되어 도메인 레이어에 위치시켰습니다.

레이어 책임
Presentation 텍스트 가공, UI업데이트 주기 관리, 테이블 크기 결정
Domain 테이블 정렬방식 결정, 요청된 테이블 크기로 테이블을 가공
Data DTO를 엔티티화, 전체 테이블 저장 및 관리

@J0onYEong J0onYEong requested a review from Copilot April 21, 2025 03:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the order book data storage by moving its management into the Data layer and updating related use cases and repositories to utilize Combine-based publishers instead of async streams.

  • Migrates data storage responsibilities from the Presentation layer to the Data layer
  • Introduces new entities (OrderbookTableVO, OrderbookTable) and updates use case protocols accordingly
  • Updates networking and repository implementations to use Combine for asynchronous operations

Reviewed Changes

Copilot reviewed 19 out of 20 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Tuist/Package.swift Added AdvancedSwift dependency
Projects/Utils/CoreUtil/Sources/Export/Export_AdvancedSwift.swift Added export file for AdvancedSwift module
Projects/Utils/CoreUtil/Sources/DataStructure/CVNumber.swift Added Copyable conformance and a copy() method to CVNumber
Projects/Utils/CoreUtil/Sources/Combine+Extension/Publisher+Ex.swift Introduced mapToVoid() publisher extension
Projects/Utils/CoreUtil/Project.swift Added dependency on AdvancedSwift in the project configuration
Projects/Features/CoinDetail/Feature/Sources/CoinDetailPageViewModel.swift Refactored order book stream processing to use a new use case function
Projects/Domain/Interface/UseCase/CoinDetailPageUseCase.swift Removed outdated methods and introduced getOrderbookTable with Combine
Projects/Domain/Interface/Repository/OrderbookRepository.swift Updated protocol to remove old methods and include a new publisher-based method
Projects/Domain/Interface/Entity/Orderbook/* Removed OrderbookUpdateVO; added OrderbookTableVO and Orderbook
Projects/Domain/Concrete/UseCase/DefaultCoinDetailPageUseCase.swift Updated use case implementation to retrieve and transform order book data
Projects/Data/Repository/Sources/* Updated repository to incorporate Combine and a thread-safe order book store, aligning with new DTO-to-entity adaptations
Projects/Data/DataSource/Sources/Service/Network/HTTP/HTTPService.swift Extended HTTPService with a Combine-based request method
Plugins/DependencyPlugin/ProjectDescriptionHelpers/Dependency.swift Added AdvancedSwift dependency
Files not reviewed (1)
  • Tuist/Package.resolved: Language not supported

@J0onYEong J0onYEong merged commit 968cc64 into main Apr 21, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants