Skip to content

[IDLE-446] 알림 기능을 모킹한다. #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions project/Projects/App/Sources/DIAssembly/DataAssembly.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public struct DataAssembly: Assembly {

public func assemble(container: Container) {

// MARK: Key-value store for datasource
container.register(KeyValueStore.self) { _ in
return KeyChainList()
}
.inObjectScope(.container)

// MARK: Service
container.register(LocalStorageService.self) { _ in
return DefaultLocalStorageService()
Expand Down Expand Up @@ -68,5 +74,10 @@ public struct DataAssembly: Assembly {
container.register(NotificationTokenRepository.self) { _ in
return RootFeature.FCMTokenRepository()
}

// MARK: 알림 데이터 레포지토리
container.register(NotificationsRepository.self) { _ in
DefaultNotificationsRepository()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import Swinject
public struct PresentationAssembly: Assembly {
public func assemble(container: Container) {

container.register(RemoteConfigService.self) { _ in
DefaultRemoteConfigService()
}
.inObjectScope(.container)

container.register(RouterProtocol.self) { _ in
Router()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

import Foundation


import RxSwift

public extension Result {
var value: Success? {
guard case let .success(value) = self else {
Expand All @@ -22,3 +25,7 @@ public extension Result {
return error
}
}


/// Single + Result Short cut
public typealias Sult<T, F: Error> = Single<Result<T, F>>
3 changes: 3 additions & 0 deletions project/Projects/Data/DataSource/API/BaseAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum APIType {
case external(url: String)
case applys
case notificationToken
case notifications
}

// MARK: BaseAPI
Expand Down Expand Up @@ -46,6 +47,8 @@ public extension BaseAPI {
baseStr = url
case .notificationToken:
baseStr += "/fcm"
case .notifications:
baseStr += "/notifications"
}

return URL(string: baseStr)!
Expand Down
54 changes: 54 additions & 0 deletions project/Projects/Data/DataSource/API/NotificationsAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// NotificationsAPI.swift
// DataSource
//
// Created by choijunios on 10/15/24.
//

import Foundation


import Moya

public enum NotificationsAPI {

case readNotification(id: String)
case notReadNotificationsCount
case allNotifications
}

extension NotificationsAPI: BaseAPI {

public var apiType: APIType {
.notifications
}

public var path: String {
switch self {
case .readNotification(let id):
"\(id)"
case .notReadNotificationsCount:
"count"
case .allNotifications:
"my"
}
}

public var method: Moya.Method {
switch self {
case .readNotification(let id):
.patch
case .notReadNotificationsCount:
.get
case .allNotifications:
.get
}
}

public var task: Moya.Task {
switch self {
default:
.requestPlain
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// NotificationItemDTO.swift
// DataSource
//
// Created by choijunios on 10/15/24.
//

import Foundation

public enum NotificationTypeDTO: String, Decodable {
case APPLICANT
}

public struct NotificationItemDTO: Decodable {

public let id: String
public let isRead: Bool
public let title: String
public let body: String
// ISO8601
public let createdAt: String
public let imageUrlString: String?
public let notificationType: NotificationTypeDTO
public let notificationDetails: Decodable

enum CodingKeys: CodingKey {
case id
case isRead
case title
case body
case createdAt
case imageUrl
case notificationType
case notificationDetails
}

public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decode(String.self, forKey: .id)
self.isRead = try container.decode(Bool.self, forKey: .isRead)
self.title = try container.decode(String.self, forKey: .title)
self.body = try container.decode(String.self, forKey: .body)
self.createdAt = try container.decode(String.self, forKey: .createdAt)
self.imageUrlString = try container.decodeIfPresent(String.self, forKey: .imageUrl)

self.notificationType = try container.decode(NotificationTypeDTO.self, forKey: .notificationType)

switch notificationType {
case .APPLICANT:
self.notificationDetails = try container.decode(ApplicantInfluxDTO.self, forKey: .notificationDetails)
}
}
}

// MARK: DTO for NotificationTypes
public struct ApplicantInfluxDTO: Decodable {

public let jobPostingId: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
import Domain

public protocol EntityRepresentable: Codable {
public protocol EntityRepresentable: Decodable {
associatedtype Entity
func toEntity() -> Entity
}
Expand Down
6 changes: 1 addition & 5 deletions project/Projects/Data/DataSource/Service/ApplyService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,5 @@ import Foundation

public class ApplyService: BaseNetworkService<ApplyAPI> {

public init() { }

public override init(keyValueStore: KeyValueStore) {
super.init(keyValueStore: keyValueStore)
}
public override init() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Foundation
import Domain
import Core


import RxSwift
Expand All @@ -16,11 +17,9 @@ import RxMoya

public class BaseNetworkService<TagetAPI: BaseAPI> {

public let keyValueStore: KeyValueStore
@Injected var keyValueStore: KeyValueStore

init(keyValueStore: KeyValueStore = KeyChainList.shared) {
self.keyValueStore = keyValueStore
}
init() { }

private lazy var providerWithToken: MoyaProvider<TagetAPI> = {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,5 @@ import Foundation

public class AuthService: BaseNetworkService<AuthAPI> {

public init() { }

public override init(keyValueStore: KeyValueStore) {
super.init(keyValueStore: keyValueStore)
}
public override init() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,5 @@ import Foundation

public class CrawlingPostService: BaseNetworkService<CrawlingPostAPI> {

public init() { }

public override init(keyValueStore: KeyValueStore) {
super.init(keyValueStore: keyValueStore)
}
public override init() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,5 @@ import Foundation

public class ExternalRequestService: BaseNetworkService<ExtenalUrlAPI> {

public init() { }

public override init(keyValueStore: KeyValueStore) {
super.init(keyValueStore: keyValueStore)
}
public override init() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,5 @@ import Foundation

public class NotificationTokenTransferService: BaseNetworkService<NotificationTokenAPI> {

public init() { }

public override init(keyValueStore: KeyValueStore) {
super.init(keyValueStore: keyValueStore)
}
public override init() { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// NotificationsService.swift
// DataSource
//
// Created by choijunios on 10/15/24.
//

import Foundation

public class NotificationsService: BaseNetworkService<NotificationsAPI> {

public override init() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,5 @@ import Foundation

public class RecruitmentPostService: BaseNetworkService<RcruitmentPostAPI> {

public init() { }

public override init(keyValueStore: KeyValueStore) {
super.init(keyValueStore: keyValueStore)
}
public override init() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,5 @@ import Foundation

public class UserInformationService: BaseNetworkService<UserInformationAPI> {

public init() { }

public override init(keyValueStore: KeyValueStore) {
super.init(keyValueStore: keyValueStore)
}
public override init() { }
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
//
// KeyChainList.swift
// ConcreteRepository
// DataSource
//
// Created by choijunios on 6/28/24.
//

import Foundation
import KeychainAccess

class KeyChainList {
public class KeyChainList: KeyValueStore {

private init() { }

static let shared = KeyChainList()
public init() { }

private let keyChain = Keychain(service: "com.service.idle")
}

extension KeyChainList: KeyValueStore {

func save(key: String, value: String) throws {
public func save(key: String, value: String) throws {
do {
try keyChain.set(value, key: key)
#if DEBUG
Expand All @@ -33,20 +28,20 @@ extension KeyChainList: KeyValueStore {
}
}

func delete(key: String) throws {
public func delete(key: String) throws {
try keyChain.remove(key)
UserDefaults.standard.removeObject(forKey: key)
}

func removeAll() throws {
public func removeAll() throws {
try keyChain.removeAll()

// UserDefaults의 경우 수동으로 정보를 삭제합니다.
UserDefaults.standard.removeObject(forKey: Key.Auth.kaccessToken)
UserDefaults.standard.removeObject(forKey: Key.Auth.krefreshToken)
}

func get(key: String) -> String? {
public func get(key: String) -> String? {
if let value = try? keyChain.get(key) {
return value
} else if let value = UserDefaults.standard.string(forKey: key) {
Expand Down
21 changes: 21 additions & 0 deletions project/Projects/Data/DataTests/APITesting/TestAssembly.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// TestAssembly.swift
// DataTests
//
// Created by choijunios on 10/15/24.
//

import Foundation
import DataSource


import Swinject

class TestAssembly: Assembly {

func assemble(container: Swinject.Container) {
container.register(KeyValueStore.self) { _ in
TestKeyValueStore()
}
}
}
Loading