Skip to content

Commit

Permalink
[2.0.0] Cache > Dependency > 구독 (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgvv authored Mar 25, 2024
1 parent 41a78aa commit 6e05c48
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 107 deletions.
66 changes: 66 additions & 0 deletions package-kuring/Sources/Caches/Dependency/Subscriptions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// Copyright (c) 2024 쿠링
// See the 'License.txt' file for licensing information.
//

import Models
import Foundation
import Dependencies

public struct KuringSubscriptions {
/// 구독한 공지 추가
public var add: (_ noticeProvider: NoticeProvider) -> Void
/// 구독한 공지 제거
public var remove: (_ noticeProvider: NoticeProvider) -> Void
/// 구독한 모든 공지 카테고리
public var getAll: () -> [NoticeProvider]
/// 커스텀 공지 구독 여부
public var isCustomNotification: () -> Bool
/// 커스텀 공지 구독 여부 변경
public var changeCustomNotification: (_ isSubscribe: Bool) -> Void

/// 구독한 공지 (대학 및 학괴)
@UserDefault(key: StringSet.subscribedCategories, defaultValue: [])
static var subscriptions: [NoticeProvider]

/// 커스텀 공지 구독 여부 (기본값 true)
@UserDefault(key: StringSet.customNotification, defaultValue: true)
static var isCustomNotification: Bool
}

extension KuringSubscriptions {
public static let `default` = Self(
add: { noticeProvider in
var subscriptions = Self.subscriptions
subscriptions.append(noticeProvider)
Self.subscriptions = subscriptions

}, remove: { noticeProvider in
var subscriptions = Self.subscriptions
subscriptions.removeAll { $0.id == noticeProvider.id }
Self.subscriptions = subscriptions

}, getAll: {
Self.subscriptions

}, isCustomNotification: {
Self.isCustomNotification

}, changeCustomNotification: { isSubscribe in
Self.isCustomNotification = isSubscribe

}
)

}

extension KuringSubscriptions: DependencyKey {
public static var liveValue: KuringSubscriptions = .default
}

extension DependencyValues {
public var subscriptions: KuringSubscriptions {
get { self[KuringSubscriptions.self] }
set { self[KuringSubscriptions.self] = newValue }
}
}
1 change: 1 addition & 0 deletions package-kuring/Sources/Caches/Dummy.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

107 changes: 0 additions & 107 deletions package-kuring/Sources/Caches/UserDefault.swift

This file was deleted.

2 changes: 2 additions & 0 deletions package-kuring/Sources/Caches/Utils/StringSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ class StringSet {

static let selectedDepartments = "\(baseString).selected.departments"
static let currentDepartment = "\(baseString).current.department"

static let recentSearch = "com.kuring.lite.recent.search"
}

0 comments on commit 6e05c48

Please sign in to comment.