-
Notifications
You must be signed in to change notification settings - Fork 5
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
1 parent
012018a
commit ca6a30a
Showing
15 changed files
with
189 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import SwiftUI | ||
import GoogleSignIn | ||
import Core | ||
import Feed | ||
|
||
@main | ||
struct SwiftBuddiesIOSApp: App { | ||
|
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
32 changes: 32 additions & 0 deletions
32
SwiftBuddiesIOS/Targets/FeedModule/Sources/FeedNetwork/FeedResponse.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,32 @@ | ||
// | ||
// FeedResponse.swift | ||
// SwiftBuddiesIOS | ||
// | ||
// Created by Kate Kashko on 1.11.2024. | ||
// | ||
|
||
import Foundation | ||
|
||
struct FeedResponse: Codable { | ||
let feed: [PostResponse]? | ||
} | ||
|
||
struct PostResponse: Codable { | ||
let user: UserResponse? | ||
let post: PostDataResponse? | ||
} | ||
|
||
struct UserResponse: Codable { | ||
let name: String? | ||
let picture: String? | ||
} | ||
|
||
struct PostDataResponse: Codable { | ||
let uid: String | ||
let sharedDate: String | ||
let content: String | ||
let images: [String]? | ||
let likeCount: Int | ||
let commentCount: Int | ||
} | ||
|
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
File renamed without changes.
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
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
61 changes: 61 additions & 0 deletions
61
SwiftBuddiesIOS/Targets/FeedModule/Sources/ViewModel/FeedViewModel.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,61 @@ | ||
// | ||
// FeedViewModel.swift | ||
// SwiftBuddiesIOS | ||
// | ||
// Created by Kate Kashko on 1.11.2024. | ||
// | ||
|
||
import Foundation | ||
import BuddiesNetwork | ||
import Network | ||
|
||
@MainActor | ||
class FeedViewModel: ObservableObject { | ||
@Published var posts: [PostModel]? | ||
private let apiClient: BuddiesClient | ||
|
||
init() { | ||
self.apiClient = .shared | ||
} | ||
|
||
func fetchFeed() async { | ||
var request = FeedRequest(range: "0-2") | ||
|
||
do { | ||
let response = try await apiClient.perform(request) | ||
self.posts = response.feed?.map { postResponse in | ||
PostModel( | ||
id: postResponse.post?.uid ?? "", | ||
authorId: "", // Add authorId if available | ||
likeCount: postResponse.post?.likeCount ?? 0, | ||
commentsCount: postResponse.post?.commentCount ?? 0, | ||
content: postResponse.post?.content ?? "", | ||
imageUrl: postResponse.post?.images?.first ?? "", | ||
user: UserModel( | ||
id: UUID().uuidString, // Use a unique ID | ||
name: postResponse.user?.name ?? "", | ||
profileImageUrl: postResponse.user?.picture | ||
) | ||
) | ||
} | ||
} catch { | ||
print("Failed to fetch feed: \(error)") | ||
} | ||
} | ||
} | ||
|
||
// MARK: - FeedRequest | ||
struct FeedRequest: Requestable { | ||
var range: String | ||
|
||
typealias Data = FeedResponse | ||
|
||
func toUrlRequest() throws -> URLRequest { | ||
// Construct the base URL with the endpoint | ||
try URLProvider.returnUrlRequest( | ||
method: .get, | ||
url: APIs.Feed.getFeed.url(), | ||
data: self | ||
) | ||
} | ||
} |
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