-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
335 additions
and
56 deletions.
There are no files selected for viewing
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
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
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
38 changes: 38 additions & 0 deletions
38
Projects/Data/Sources/DTO/Notifications/NotificationListDTO.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,38 @@ | ||
import Foundation | ||
import Domain | ||
|
||
struct NotificationListResponseDTO: Codable { | ||
let notifications: [NotificationResponseDTO] | ||
} | ||
|
||
public struct NotificationResponseDTO: Codable { | ||
public let notificationID: Int | ||
public let title, content, topic: String | ||
public let detailID: Int | ||
public let createdAt: String | ||
public let new: Bool | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case notificationID = "notification_id" | ||
case title, content, topic | ||
case detailID = "detail_id" | ||
case createdAt = "created_at" | ||
case new | ||
} | ||
} | ||
|
||
extension NotificationListResponseDTO { | ||
func toDomain() -> [NotificationEntity] { | ||
notifications.map { | ||
NotificationEntity( | ||
notificationID: $0.notificationID, | ||
title: $0.title, | ||
content: $0.content, | ||
topic: $0.topic, | ||
detailID: $0.detailID, | ||
createdAt: $0.createdAt.toJobisDate().toStringFormat("yyyy.MM.dd"), | ||
new: $0.new | ||
) | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
Projects/Data/Sources/DataSource/API/NotificationsAPI.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,60 @@ | ||
import Moya | ||
import AppNetwork | ||
import Domain | ||
|
||
public enum NotificationsAPI { | ||
case fetchNotificationList | ||
case patchReadNotification(id: Int) | ||
} | ||
|
||
extension NotificationsAPI: JobisAPI { | ||
public typealias ErrorType = JobisError | ||
|
||
public var domain: JobisDomain { | ||
return .notifications | ||
} | ||
|
||
public var urlPath: String { | ||
switch self { | ||
case .fetchNotificationList: | ||
return "" | ||
|
||
case let .patchReadNotification(id): | ||
return "/\(id)" | ||
} | ||
} | ||
|
||
public var method: Method { | ||
switch self { | ||
case .fetchNotificationList: | ||
return .get | ||
|
||
case .patchReadNotification: | ||
return .patch | ||
} | ||
} | ||
|
||
public var task: Task { | ||
switch self { | ||
case .fetchNotificationList: | ||
return .requestParameters( | ||
parameters: | ||
// // TODO: μΆν μ½μμ μμ½μ λΆκΈ°μ²λ¦¬ νμ | ||
["is_new": ""], | ||
encoding: URLEncoding.queryString) | ||
default: | ||
return .requestPlain | ||
} | ||
} | ||
|
||
public var jwtTokenType: JwtTokenType { | ||
switch self { | ||
default: | ||
return .accessToken | ||
} | ||
} | ||
|
||
public var errorMap: [Int: ErrorType]? { | ||
return [:] | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Projects/Data/Sources/DataSource/Remote/RemoteNotificationsDataSource.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,21 @@ | ||
import RxSwift | ||
import RxCocoa | ||
import Domain | ||
|
||
public protocol RemoteNotificationsDataSource { | ||
func fetchNotificationList() -> Single<[NotificationEntity]> | ||
func patchReadNotification(id: Int) -> Completable | ||
} | ||
|
||
final class RemoteNotificationsDataSourceImpl: RemoteBaseDataSource<NotificationsAPI>, RemoteNotificationsDataSource { | ||
public func fetchNotificationList() -> Single<[NotificationEntity]> { | ||
request(.fetchNotificationList) | ||
.map(NotificationListResponseDTO.self) | ||
.map { $0.toDomain() } | ||
} | ||
|
||
public func patchReadNotification(id: Int) -> Completable { | ||
request(.patchReadNotification(id: id)) | ||
.asCompletable() | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Projects/Data/Sources/Repositories/NotificationsRepositoryImpl.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,20 @@ | ||
import RxSwift | ||
import Domain | ||
|
||
struct NotificationsRepositoryImpl: NotificationsRepository { | ||
private let remoteNotificationsDataSource: any RemoteNotificationsDataSource | ||
|
||
init( | ||
remoteNotificationsDataSource: any RemoteNotificationsDataSource | ||
) { | ||
self.remoteNotificationsDataSource = remoteNotificationsDataSource | ||
} | ||
|
||
func fetchNotificationsList() -> Single<[NotificationEntity]> { | ||
remoteNotificationsDataSource.fetchNotificationList() | ||
} | ||
|
||
func patchReadNotification(id: Int) -> Completable { | ||
remoteNotificationsDataSource.patchReadNotification(id: id) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
Projects/Domain/Sources/Entities/Notifications/NotificationEntity.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,27 @@ | ||
import Foundation | ||
|
||
public struct NotificationEntity: Equatable, Hashable { | ||
public let notificationID: Int | ||
public let title, content, topic: String | ||
public let detailID: Int | ||
public let createdAt: String | ||
public let new: Bool | ||
|
||
public init( | ||
notificationID: Int, | ||
title: String, | ||
content: String, | ||
topic: String, | ||
detailID: Int, | ||
createdAt: String, | ||
new: Bool | ||
) { | ||
self.notificationID = notificationID | ||
self.title = title | ||
self.content = content | ||
self.topic = topic | ||
self.detailID = detailID | ||
self.createdAt = createdAt | ||
self.new = new | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
Projects/Domain/Sources/Repositories/NotificationsRepository.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,6 @@ | ||
import RxSwift | ||
|
||
public protocol NotificationsRepository { | ||
func fetchNotificationsList() -> Single<[NotificationEntity]> | ||
func patchReadNotification(id: Int) -> Completable | ||
} |
13 changes: 13 additions & 0 deletions
13
Projects/Domain/Sources/UseCases/Notifications/FetchNotificationListUseCase.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,13 @@ | ||
import RxSwift | ||
|
||
public struct FetchNotificationListUseCase { | ||
private let notificationsRepository: any NotificationsRepository | ||
|
||
public init(notificationsRepository: any NotificationsRepository) { | ||
self.notificationsRepository = notificationsRepository | ||
} | ||
|
||
public func execute() -> Single<[NotificationEntity]> { | ||
notificationsRepository.fetchNotificationsList() | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Projects/Domain/Sources/UseCases/Notifications/ReadNotificationUseCase.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,13 @@ | ||
import RxSwift | ||
|
||
public struct ReadNotificationUseCase { | ||
private let notificationsRepository: any NotificationsRepository | ||
|
||
public init(notificationsRepository: any NotificationsRepository) { | ||
self.notificationsRepository = notificationsRepository | ||
} | ||
|
||
public func execute(id: Int) -> Completable { | ||
notificationsRepository.patchReadNotification(id: id) | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.