Skip to content
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

addViewToPost() method (adds a userId under the VIEWS collection of a post) #98

Merged
merged 2 commits into from
Feb 20, 2025
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
13 changes: 13 additions & 0 deletions Gauge/Feed/ViewModels/PostFirebase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,17 @@ class PostFirebase: ObservableObject {
}
}
}


func addViewToPost(postId: String, userId: String) {
let documentRef = Firebase.db.collection("POSTS").document(postId).collection("VIEWS").document(userId)

documentRef.setData(["userId": userId]) { error in
if let error = error {
print("Error adding view to post: \(error)")
} else {
print("Added view to post \(postId).")
}
}
}
}
7 changes: 7 additions & 0 deletions Gauge/Feed/Views/FirebaseTesting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ struct FirebaseTesting: View {
responseOptions: ["Kendrick Lamar", "Rihanna", "The Weeknd", "Shakira + J Lo"]
)
}

Button("Add user to VIEWS of a post (hardcoded for Firebase testing)") {
postVM.addViewToPost(
postId: "B2A9F081-A10C-4957-A6B8-0295F0C700A2",
userId: "2lCFmL9FRjhY1v1NMogD5H6YuMV2"
)
}

Button("Add response") {
postVM.addResponse(
Expand Down