forked from depromeet/14th-team5-iOS
-
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.
feat: add widget usecase(depromeet#543)
- Loading branch information
Showing
16 changed files
with
317 additions
and
63 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
27 changes: 27 additions & 0 deletions
27
14th-team5-iOS/App/WidgetExtension/Sources/FamilyWidget/FamilyWidgetDIContainer.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 @@ | ||
// | ||
// FamilyWidgetDIContainer.swift | ||
// WidgetExtension | ||
// | ||
// Created by 마경미 on 05.06.24. | ||
// | ||
|
||
import Foundation | ||
|
||
import Core | ||
import Data | ||
import Domain | ||
|
||
final class FamilyWidgetDIContainer { | ||
|
||
func makeRepository() -> WidgetRepositoryProtocol { | ||
return WidgetRepository() | ||
} | ||
|
||
func makeUseCase() -> FetchRecentFamilyPostUseCaseProtocol { | ||
return FetchRecentFamilyPostUseCase(widgetRepository: makeRepository()) | ||
} | ||
|
||
func makeProvider() -> FamilyWidgetTimelineProvider { | ||
return .init(repository: makeRepository()) | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
14th-team5-iOS/Data/Sources/APIs/Widget/Repository/WidgetRepository.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,33 @@ | ||
// | ||
// WidgetRepository.swift | ||
// Data | ||
// | ||
// Created by 마경미 on 05.06.24. | ||
// | ||
|
||
import Foundation | ||
|
||
import Domain | ||
|
||
import RxSwift | ||
|
||
public final class WidgetRepository: WidgetRepositoryProtocol { | ||
|
||
public let disposeBag: DisposeBag = DisposeBag() | ||
private let widgetAPIWorker: WidgetAPIWorker = WidgetAPIWorker() | ||
|
||
public init () { } | ||
|
||
public func fetchRecentFamilyPost(completion: @escaping (Result<Domain.RecentFamilyPostData?, Error>) -> Void) { | ||
widgetAPIWorker.fetchRecentFamilyPost() | ||
.subscribe( | ||
onNext: { result in | ||
completion(.success(result)) | ||
}, | ||
onError: { error in | ||
completion(.failure(error)) | ||
} | ||
) | ||
.disposed(by: disposeBag) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...team5-iOS/Data/Sources/APIs/Widget/WidgetAPI/DataMaaping/RecentFamilyPostRequestDTO.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,12 @@ | ||
// | ||
// RecentFamilyPostRequestDTO.swift | ||
// Data | ||
// | ||
// Created by 마경미 on 05.06.24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct RecentFamilyPostParameter: Codable { | ||
let date: String = Date().toFormatString(with: "yyyy-MM-dd") | ||
} |
26 changes: 26 additions & 0 deletions
26
...eam5-iOS/Data/Sources/APIs/Widget/WidgetAPI/DataMaaping/RecentFamilyPostResponseDTO.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,26 @@ | ||
// | ||
// RecentFamilyPostResponseDTO.swift | ||
// Data | ||
// | ||
// Created by 마경미 on 05.06.24. | ||
// | ||
|
||
import Foundation | ||
|
||
import Domain | ||
|
||
struct RecentFamilyPostResponseDTO: Codable { | ||
let authorName: String | ||
let authorProfileImageUrl: String? | ||
let postId: String? | ||
let postImageUrl: String? | ||
let postContent: String? | ||
|
||
func toDomain() -> RecentFamilyPostData { | ||
return .init(authorName: authorName, | ||
authorProfileImageUrl: authorProfileImageUrl, | ||
postId: postId, | ||
postImageUrl: postImageUrl, | ||
postContent: postContent) | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
14th-team5-iOS/Data/Sources/APIs/Widget/WidgetAPI/WidgetAPIWorker.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,56 @@ | ||
// | ||
// WidgetAPIWorker.swift | ||
// Data | ||
// | ||
// Created by 마경미 on 05.06.24. | ||
// | ||
|
||
import Foundation | ||
|
||
import Core | ||
import Domain | ||
|
||
import RxSwift | ||
|
||
typealias WidgetAPIWorker = WidgetAPIs.Worker | ||
extension WidgetAPIs { | ||
public final class Worker: APIWorker { | ||
static let queue = { | ||
ConcurrentDispatchQueueScheduler(queue: DispatchQueue(label: "WidgetAPIQueue", qos: .utility)) | ||
}() | ||
|
||
public override init() { | ||
super.init() | ||
self.id = "WidgetAPIWorker" | ||
} | ||
|
||
var headers: [APIHeader] { | ||
guard let token = App.Repository.token.keychain.string(forKey: "accessToken") else { | ||
return [] | ||
} | ||
|
||
let headers = [BibbiAPI.Header.xAppKey, BibbiAPI.Header.xAuthToken(token), BibbiAPI.Header.acceptJson] | ||
return headers | ||
} | ||
} | ||
} | ||
|
||
extension WidgetAPIWorker { | ||
func fetchRecentFamilyPost() -> Observable<RecentFamilyPostData?> { | ||
|
||
let spec = WidgetAPIs.fetchRecentFamilyPost.spec | ||
let parameters = RecentFamilyPostParameter() | ||
|
||
return request(spec: spec, headers: headers, parameters: parameters) | ||
.subscribe(on: Self.queue) | ||
.do { | ||
if let str = String(data: $0.1, encoding: .utf8) { | ||
debugPrint("Fetch Recent Family Post Result: \(str)") | ||
} | ||
} | ||
.map(RecentFamilyPostResponseDTO.self) | ||
.catchAndReturn(nil) | ||
.map { $0?.toDomain() } | ||
.asObservable() | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
14th-team5-iOS/Data/Sources/APIs/Widget/WidgetAPI/WidgetAPIs.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,22 @@ | ||
// | ||
// WidgetAPIs.swift | ||
// Data | ||
// | ||
// Created by 마경미 on 05.06.24. | ||
// | ||
|
||
import Foundation | ||
|
||
import Core | ||
|
||
enum WidgetAPIs: API { | ||
case fetchRecentFamilyPost | ||
|
||
public var spec: APISpec { | ||
switch self { | ||
case .fetchRecentFamilyPost: | ||
let urlString = "\(BibbiAPI.hostApi)/widgets/single-recent-family-post" | ||
return APISpec(method: .get, url: urlString) | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
14th-team5-iOS/Domain/Sources/Widget/Entities/RecentFamilyPostData.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,29 @@ | ||
// | ||
// RecentFamilyPostData.swift | ||
// Domain | ||
// | ||
// Created by 마경미 on 05.06.24. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct RecentFamilyPostData: Codable { | ||
public var authorName: String | ||
public var authorProfileImageUrl: String? | ||
public var postId: String? | ||
public var postImageUrl: String? | ||
public var postContent: String? | ||
|
||
public init( | ||
authorName: String, | ||
authorProfileImageUrl: String? = nil, | ||
postId: String? = nil, | ||
postImageUrl: String? = nil, | ||
postContent: String? = nil) { | ||
self.authorName = authorName | ||
self.authorProfileImageUrl = authorProfileImageUrl | ||
self.postId = postId | ||
self.postImageUrl = postImageUrl | ||
self.postContent = postContent | ||
} | ||
} |
Oops, something went wrong.