Skip to content

Commit

Permalink
Merge pull request #98 from gtiosclub/feed-sameer-addView
Browse files Browse the repository at this point in the history
addViewToPost() method (adds a userId under the VIEWS collection of a post)
  • Loading branch information
jifonthespoon authored Feb 20, 2025
2 parents 621d6ad + a30d7ad commit af31438
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Gauge/Feed/ViewModels/PostFirebase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,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

0 comments on commit af31438

Please sign in to comment.