-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ITDS-75] feat: #61 - "추천 공고 관리" + "공고 검색" 데이터 Stream 구현
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
Targets/PresentationLayer/Sources/PostRecommend/RecommendedPostStream.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// RecommendedPostStream.swift | ||
// PresentationLayer | ||
// | ||
// Created by 이원빈 on 2/12/25. | ||
// Copyright © 2025 MOZIP. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import DomainLayer | ||
|
||
import RxCocoa | ||
|
||
public protocol RecommendedPostStream { | ||
var data: BehaviorRelay<[RecommendCellData]> { get set } | ||
var targetIndex: Int { get set } | ||
} | ||
|
||
public protocol MutableRecommendedPostStream: RecommendedPostStream { | ||
func setTargetIndex(_ index: Int) | ||
func updatePostInfo(id: Int, subTitle: String) | ||
func updatePostImage(_ imageData: Data) | ||
func updateAllPost(posts: [RecommendCellData]) | ||
} | ||
|
||
final class MutableRecommendedPostStreamImpl: MutableRecommendedPostStream { | ||
|
||
var data: BehaviorRelay<[RecommendCellData]> = .init( | ||
value: RecommendCellData.initialData | ||
) | ||
var targetIndex: Int = 0 | ||
|
||
func setTargetIndex(_ index: Int) { | ||
targetIndex = index | ||
} | ||
|
||
func updatePostInfo(id: Int, subTitle: String) { | ||
var currentList = data.value | ||
var targetPost = currentList[targetIndex] | ||
targetPost.infoID = id | ||
targetPost.subTitle = subTitle | ||
currentList[targetIndex] = targetPost | ||
data.accept(currentList) | ||
} | ||
|
||
func updatePostImage(_ imageData: Data) { | ||
var currentList = data.value | ||
var targetPost = currentList[targetIndex] | ||
targetPost.imageData = imageData | ||
currentList[targetIndex] = targetPost | ||
data.accept(currentList) | ||
} | ||
|
||
func updateAllPost(posts: [RecommendCellData]) { | ||
var currentList = data.value | ||
currentList.enumerated().forEach { (i, item) in | ||
currentList[i].infoID = posts[i].infoID | ||
currentList[i].subTitle = posts[i].subTitle | ||
currentList[i].thumbnailURL = posts[i].thumbnailURL | ||
currentList[i].imageData = posts[i].imageData | ||
} | ||
data.accept(currentList) | ||
} | ||
} |