feat: 최근 들은 콘텐츠 로컬 DB 추가

This commit is contained in:
Yu Sung
2025-07-28 22:34:34 +09:00
parent a73cafa08c
commit 70af4cb3dd
10 changed files with 306 additions and 67 deletions

View File

@@ -0,0 +1,55 @@
//
// RecentContentViewModel.swift
// SodaLive
//
// Created by klaus on 7/28/25.
//
import SwiftUI
import Combine
class RecentContentViewModel: ObservableObject {
@Published var recentContents: [RecentContent] = []
@Published var contentCount: Int = 0
private let service: RecentContentService
private var cancellables = Set<AnyCancellable>()
init(service: RecentContentService = RecentContentService()) {
self.service = service
fetchRecentContents()
fetchContentCount()
}
func fetchRecentContents(limit: Int = 10) {
self.recentContents = service.getRecentContents(limit: limit)
self.contentCount = recentContents.count
}
func fetchContentCount() {
self.contentCount = service.getCount()
}
func insertRecentContent(contentId: Int64, coverImageUrl: String, title: String, creatorNickname: String) {
service.insertRecentContent(
contentId: contentId,
coverImageUrl: coverImageUrl,
title: title,
creatorNickname: creatorNickname
)
fetchRecentContents()
fetchContentCount()
}
func deleteByContentId(contentId: Int64) {
service.deleteByContentId(contentId: contentId)
fetchRecentContents()
fetchContentCount()
}
func truncate() {
service.truncate()
fetchRecentContents()
fetchContentCount()
}
}