Repository: PalisadoesFoundation/talawa (language: dart)

Issue:
Bug: Post comments are invisible in Individual Post Page.
**Describe the bug**
`Post comments` in `individual post page` are empty and `invisible` despite the `existence` of comments.

**To Reproduce**
Steps to reproduce the behavior:

1. Login and Join an organisation.
2. Create a post in case of empty posts.
3. Find the created post in news feed and click on its comment option.
4. Add a new comment.
5. Navigate back to news feed.
6. Once again click on same post comment option.

**Expected behavior**
The previously created comment should be visible.

**Actual behavior**
The comment list is empty despite the comment icon showing non zero value.

**Screenshots**

https://github.com/PalisadoesFoundation/talawa/assets/120930148/981d45d6-854d-4823-9028-f3d2a058ff81



**Additional details**
Add any other context or screenshots about the feature request here.

**Potential internship candidates**
Please read this if you are planning to apply for a Palisadoes Foundation internship https://github.com/PalisadoesFoundation/talawa/issues/359



Discussion hints:
@noman2002 @Cioppolo14
 Can you please assign this to me

I have found the cause of bug and will try to create a PR to fix this till tomorrow.

Pull request: Post comments were invisible in Individual Post Page with Image
**What kind of change does this PR introduce?**

BugFix: Comments were not visible for posts with images. 

**Issue Number:**

Fixes #2333 

**Did you add tests for your changes?**

Yes

**Snapshots/Videos:**


https://github.com/PalisadoesFoundation/talawa/assets/93479496/2eb8603d-b3dc-48d2-9226-3d1af27aafab


![first](https://github.com/PalisadoesFoundation/talawa/assets/93479496/d1aecd46-bbc3-4ca3-86b8-a6065dae2665)
![seconf](https://github.com/PalisadoesFoundation/talawa/assets/93479496/c1145888-9115-4e0c-9359-fb1c8aa5ff7c)
![third](https://github.com/PalisadoesFoundation/talawa/assets/93479496/499cc804-7414-4f0f-a46d-7e5414313294)

<!--Add snapshots or videos wherever possible.-->

**If relevant, did you update the documentation?**

<!--Add link to Talawa-Docs.-->

**Summary**

Comments were not visible for posts with images

**Does this PR introduce a breaking change?**

No

**Other information**

The bug was there because app was trying to get the complete post data for fetching comments of the post and the `imageurl`  was to be sent in proper format by api for this. That's how `fetchPostsByOrganisation` was working. Now since only comments were needed I removed the extra data fecthed along with comments.

**Have you read the [contributing guide](https://github.com/PalisadoesFoundation/talawa/blob/master/CONTRIBUTING.md)?**

<!--Yes or No-->
Yes


Test command: nan

Fix patch:
diff --git a/lib/services/comment_service.dart b/lib/services/comment_service.dart
index 7b25338eb9..b118b6c003 100644
--- a/lib/services/comment_service.dart
+++ b/lib/services/comment_service.dart
@@ -4,7 +4,6 @@ import 'package:talawa/locator.dart';
 import 'package:talawa/services/database_mutation_functions.dart';
 import 'package:talawa/services/navigation_service.dart';
 import 'package:talawa/utils/comment_queries.dart';
-import 'package:talawa/utils/post_queries.dart';
 
 /// CommentService class have different member functions which provides service in the context of commenting.
 ///
@@ -62,7 +61,7 @@ class CommentService {
   /// * `Future<List<dynamic>>`: promise that will be fulfilled with list of comments.
   ///
   Future<List<dynamic>> getCommentsForPost(String postId) async {
-    final String getCommmentQuery = PostQueries().getPostById(postId);
+    final String getCommmentQuery = CommentQueries().getPostsComments(postId);
 
     final dynamic result = await _dbFunctions.gqlAuthMutation(getCommmentQuery);
 
diff --git a/lib/utils/comment_queries.dart b/lib/utils/comment_queries.dart
index 6c6b36bc34..fa11f6c18b 100644
--- a/lib/utils/comment_queries.dart
+++ b/lib/utils/comment_queries.dart
@@ -1,9 +1,12 @@
-// ignore_for_file: talawa_api_doc
-// ignore_for_file: talawa_good_doc_comments
-
 ///This class creates the queries dealing with comments.
 class CommentQueries {
-  //Returns a query for creating a comment
+  /// Creating a comment.
+  ///
+  /// **params**:
+  ///   None
+  ///
+  /// **returns**:
+  /// * `String`: The query for creating a comment
   String createComment() {
     return """
      mutation createComment(\$postId: ID!, \$text: String!) { 
@@ -18,20 +21,29 @@ class CommentQueries {
   """;
   }
 
-  //Returns a query to get the comments of a post
+  /// Get all comments for a post.
+  ///
+  /// **params**:
+  /// * `postId`: The id of the post to get comments for.
+  ///
+  /// **returns**:
+  /// * `String`: The query for getting all comments for a post.
   String getPostsComments(String postId) {
     return """
-    query{
-      commentsByPost(id: "$postId"){
-        _id
-        text
-        createdAt
+     query {
+        post(id: "$postId")
+        {  _id,
+          comments{
+             _id,
+            text,
+             createdAt
         creator{
           firstName
           lastName
         }
+          }
+        }
       }
-    }
-    """;
+""";
   }
 }
diff --git a/lib/utils/post_queries.dart b/lib/utils/post_queries.dart
index 365c940d00..4d763032d7 100644
--- a/lib/utils/post_queries.dart
+++ b/lib/utils/post_queries.dart
@@ -73,7 +73,7 @@ class PostQueries {
             _id
           }
           comments{
-            _id,
+           _id,
             text,
              createdAt
         creator{


Test patch:
diff --git a/test/service_tests/comment_service_test.dart b/test/service_tests/comment_service_test.dart
index 71233621d7..4a8af56952 100644
--- a/test/service_tests/comment_service_test.dart
+++ b/test/service_tests/comment_service_test.dart
@@ -6,7 +6,6 @@ import 'package:talawa/locator.dart';
 import 'package:talawa/services/comment_service.dart';
 import 'package:talawa/services/database_mutation_functions.dart';
 import 'package:talawa/utils/comment_queries.dart';
-import 'package:talawa/utils/post_queries.dart';
 import '../helpers/test_helpers.dart';
 
 void main() {
@@ -75,7 +74,7 @@ void main() {
     test('test for getCommentsForPost', () async {
       final dataBaseMutationFunctions = locator<DataBaseMutationFunctions>();
       final String getCommmentQuery =
-          PostQueries().getPostById('Ayush s postid');
+          CommentQueries().getPostsComments('Ayush s postid');
 
       when(
         dataBaseMutationFunctions.gqlAuthMutation(getCommmentQuery),
@@ -167,7 +166,7 @@ void main() {
       final dataBaseMutationFunctions = locator<DataBaseMutationFunctions>();
 
       final String getCommmentQuery =
-          PostQueries().getPostById('Ayush s postid');
+          CommentQueries().getPostsComments('Ayush s postid');
       when(
         dataBaseMutationFunctions.gqlAuthMutation(getCommmentQuery),
       ).thenAnswer(
@@ -221,7 +220,7 @@ void main() {
       final dataBaseMutationFunctions = locator<DataBaseMutationFunctions>();
 
       final String getCommmentQuery =
-          PostQueries().getPostById('Ayush s postid');
+          CommentQueries().getPostsComments('Ayush s postid');
       when(
         dataBaseMutationFunctions.gqlAuthMutation(getCommmentQuery),
       ).thenAnswer(
@@ -273,7 +272,7 @@ void main() {
       final dataBaseMutationFunctions = locator<DataBaseMutationFunctions>();
 
       final String getCommmentQuery =
-          PostQueries().getPostById('Ayush s postid');
+          CommentQueries().getPostsComments('Ayush s postid');
       when(
         dataBaseMutationFunctions.gqlAuthMutation(getCommmentQuery),
       ).thenAnswer(
@@ -325,7 +324,7 @@ void main() {
       final dataBaseMutationFunctions = locator<DataBaseMutationFunctions>();
 
       final String getCommmentQuery =
-          PostQueries().getPostById('Ayush s postid');
+          CommentQueries().getPostsComments('Ayush s postid');
       when(
         dataBaseMutationFunctions.gqlAuthMutation(getCommmentQuery),
       ).thenAnswer(
diff --git a/test/utils/comment_queries_test.dart b/test/utils/comment_queries_test.dart
index f73df7de7f..d9b34b9b7f 100644
--- a/test/utils/comment_queries_test.dart
+++ b/test/utils/comment_queries_test.dart
@@ -1,6 +1,3 @@
-// ignore_for_file: talawa_api_doc
-// ignore_for_file: talawa_good_doc_comments
-
 import 'package:flutter_test/flutter_test.dart';
 import 'package:talawa/utils/comment_queries.dart';
 
@@ -8,18 +5,21 @@ void main() {
   group("Tests for comment_queries.dart", () {
     test("Check if getPostsComments works correctly", () {
       const data = """
-    query{
-      commentsByPost(id: "abc"){
-        _id
-        text
-        createdAt
+     query {
+        post(id: "abc")
+        {  _id,
+          comments{
+             _id,
+            text,
+             createdAt
         creator{
           firstName
           lastName
         }
+          }
+        }
       }
-    }
-    """;
+""";
       final fnData = CommentQueries().getPostsComments("abc");
       expect(fnData, data);
     });
diff --git a/test/utils/post_queries_test.dart b/test/utils/post_queries_test.dart
index 5f5029d245..203d193ab5 100644
--- a/test/utils/post_queries_test.dart
+++ b/test/utils/post_queries_test.dart
@@ -54,6 +54,47 @@ void main() {
       expect(fnData, data);
     });
 
+    test("Check if getPostById works correctly", () {
+      const data = """
+      query {
+        post(id: "abc")
+        { 
+          _id
+          text
+          createdAt
+          imageUrl
+          videoUrl
+          title
+          commentCount
+          likeCount
+          creator{
+            _id
+            firstName
+            lastName
+            image
+          }
+          organization{
+            _id
+          }
+          likedBy{
+            _id
+          }
+          comments{
+           _id,
+            text,
+             createdAt
+        creator{
+          firstName
+          lastName
+        }
+          }
+        }
+      }
+""";
+      final fnData = PostQueries().getPostById("abc");
+      expect(fnData, data);
+    });
+
     test("Check if removeLike works correctly", () {
       const data = """
      mutation unlikePost(\$postID: ID!) {