Skip to content

Commit

Permalink
Merge branch 'PalisadoesFoundation:develop' into create_image_service
Browse files Browse the repository at this point in the history
  • Loading branch information
Azad99-9 authored Dec 24, 2023
2 parents 52d6220 + c902baa commit b1d594f
Show file tree
Hide file tree
Showing 14 changed files with 476 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ jobs:
uses: VeryGoodOpenSource/very_good_coverage@v2
with:
path: './coverage/lcov.info'
min_coverage: 87.0
min_coverage: 88.0

Android-Build:
name: Testing build for android
Expand Down
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,12 @@ test/fixtures/core
# Ignoring file that are generated during talawa testing and firebase initialization
genhtml.perl
test_img.png


# Ignoring Node files that are generated if user uses any node command which is not required for the project
node_modules/
package.json
package-lock.json
yarn.lock
npm-debug.log
yarn-error.log
47 changes: 29 additions & 18 deletions lib/services/comment_service.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// ignore_for_file: talawa_api_doc, avoid_dynamic_calls
// ignore_for_file: talawa_good_doc_comments

import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:talawa/locator.dart';
import 'package:talawa/services/database_mutation_functions.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.
///
Expand All @@ -18,11 +17,14 @@ class CommentService {

/// This function is used to add comment on the post.
///
/// parameters:
/// * [postId] - Post id where comment need to be added.
/// * [text] - content of the comment.
/// To verify things are working, check out the native platform logs.
/// **params**:
/// * `postId`: The post id on which comment is to be added.
/// * `text`: The comment text.
///
/// **returns**:
/// * `Future<void>`: promise that will be fulfilled message background activities are successful.
Future<void> createComments(String postId, String text) async {
print("comment service called");
final String createCommentQuery = CommentQueries().createComment();
final result = await _dbFunctions.gqlAuthMutation(
createCommentQuery,
Expand All @@ -31,21 +33,30 @@ class CommentService {
'text': text,
},
);
print("comment added");
print(result);
return result;
}

/// This function is used to fetch all comments on the post.
/// This function is used to get all comments on the post.
///
/// To verify things are working, check out the native platform logs.
/// **params**:
/// * `postId`: The post id for which comments are to be fetched.
///
/// **returns**:
/// * `Future<List<dynamic>>`: promise that will be fulfilled with list of comments.
///
/// parameters:
/// * [postId] - Post id for which comments need to be fetched.
Future getCommentsForPost(String postId) async {
final String getCommmentQuery = CommentQueries().getPostsComments(postId);
final result = await _dbFunctions.gqlAuthMutation(getCommmentQuery);
if (result.data != null) {
return result.data["commentsByPost"] as List;
Future<List<dynamic>> getCommentsForPost(String postId) async {
final String getCommmentQuery = PostQueries().getPostById(postId);

final dynamic result = await _dbFunctions.gqlAuthMutation(getCommmentQuery);

if (result == null) {
return [];
}
return [];
final resultData = (result as QueryResult<Object?>).data;

final resultDataPostComments = (resultData?['post']
as Map<String, dynamic>)['comments'] as List<dynamic>;
return resultDataPostComments;
}
}
2 changes: 2 additions & 0 deletions lib/services/user_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class UserConfig {
_currentOrgInfoController.add(_currentOrg!);

_currentUser = boxUser.get('user');

// if there is not currentUser then returns false.
if (_currentUser == null) {
_currentUser = User(id: 'null', authToken: 'null');
Expand All @@ -108,6 +109,7 @@ class UserConfig {
_currentOrgInfoController.add(_currentOrg!);

saveUserInHive();

return true;
} on Exception catch (e) {
print(e);
Expand Down
46 changes: 46 additions & 0 deletions lib/utils/post_queries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,52 @@ class PostQueries {
""";
}

/// Getting Post by Post Id.
///
/// **params**:
/// * `postId`: The post id
///
/// **returns**:
/// * `String`: The query related to gettingPostsbyId
String getPostById(String postId) {
return """
query {
post(id: "$postId")
{
_id
text
createdAt
imageUrl
videoUrl
title
commentCount
likeCount
creator{
_id
firstName
lastName
image
}
organization{
_id
}
likedBy{
_id
}
comments{
_id,
text,
createdAt
creator{
firstName
lastName
}
}
}
}
""";
}

/// Add Like to a post.
///
/// **params**:
Expand Down
2 changes: 0 additions & 2 deletions lib/view_model/access_request_view_model.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ignore_for_file: talawa_api_doc
import 'package:flutter/cupertino.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:talawa/constants/routing_constants.dart';
Expand All @@ -23,7 +22,6 @@ class AccessScreenViewModel extends BaseModel {

/// initialization function.
///
///
/// **params**:
/// * `org`: Org to send request to.
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:talawa/locator.dart';
import 'package:talawa/services/third_party_service/multi_media_pick_service.dart';
Expand Down
66 changes: 47 additions & 19 deletions lib/view_model/widgets_view_models/comments_view_model.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// ignore_for_file: talawa_api_doc
// ignore_for_file: talawa_good_doc_comments

import 'package:talawa/enums/enums.dart';
import 'package:talawa/locator.dart';
import 'package:talawa/models/comment/comment_model.dart';
Expand All @@ -9,25 +6,41 @@ import 'package:talawa/services/post_service.dart';
import 'package:talawa/services/user_config.dart';
import 'package:talawa/view_model/base_view_model.dart';

/// CommentsViewModel class helps to serve the data from model
/// and to react to user's input for Comment Widget.
/// CommentsViewModel class helps to serve the data from model and to react to user's input for Comment Widget.
///
/// Methods include:
/// * `getComments` : to get all comments on the post.
/// * `createComment` : to add comment on the post.
class CommentsViewModel extends BaseModel {
/// Constructor
late CommentService _commentService;

/// PostService instance.
late PostService _postService;

/// Post id on which comments are to be fetched.
late String _postID;

/// List of comments on the post.
late List<Comment> _commentlist;

/// UserConfig instance.
late UserConfig _userConfig;

// Getters
List<Comment> get commentList => _commentlist;
String get postId => _postID;

// initialiser.
Future initialise(String postID) async {
/// This function is used to initialise the CommentViewModel.
///
/// To verify things are working, check out the native platform logs.
/// **params**:
/// * `postID`: The post id for which comments are to be fetched.
///
/// **returns**:
/// * `Future<void>`: promise that will be fulfilled message background activities are successful.
///
Future<void> initialise(String postID) async {
_commentlist = [];
_postID = postID;
_commentService = locator<CommentService>();
Expand All @@ -37,31 +50,46 @@ class CommentsViewModel extends BaseModel {
await getComments();
}

/// This methods fetch all comments on the post.
/// The function uses `getCommentsForPost` method by Comment Service.
Future getComments() async {
/// This function is used to get all comments on the post.
///
/// To verify things are working, check out the native platform logs.
/// **params**:
/// None
///
/// **returns**:
/// * `Future<void>`: promise that will be fulfilled when comments are fetched.
///
Future<void> getComments() async {
setState(ViewState.busy);
final List commentsJSON =
await _commentService.getCommentsForPost(_postID) as List;
final List commentsJSON = await _commentService.getCommentsForPost(_postID);
print(commentsJSON);
commentsJSON.forEach((commentJson) {
_commentlist.add(Comment.fromJson(commentJson as Map<String, dynamic>));
});
setState(ViewState.idle);
}

/// This function add comment on the post.
/// The function uses `createComments` method provided by Comment Service.
/// This function add comment on the post. The function uses `createComments` method provided by Comment Service.
///
/// **params**:
/// * `msg`: The comment text.
///
/// params:
/// * `msg` : text of the comment to add.
Future createComment(String msg) async {
/// **returns**:
/// * `Future<void>`: promise that will be fulfilled when comment is added.
///
Future<void> createComment(String msg) async {
print("comment viewModel called");
await _commentService.createComments(_postID, msg);
addCommentLocally(msg);
}

// This function add comment locally.
/// This function add comment locally.
///
/// **params**:
/// * `msg`: BuildContext, contain parent info
///
/// **returns**:
/// None
void addCommentLocally(String msg) {
_postService.addCommentLocally(_postID);
final creator = _userConfig.currentUser;
Expand All @@ -70,7 +98,7 @@ class CommentsViewModel extends BaseModel {
createdAt: DateTime.now().toString(),
creator: creator,
);
_commentlist.insert(0, localComment);
_commentlist.add(localComment);
notifyListeners();
}
}
24 changes: 12 additions & 12 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
url: "https://pub.dev"
source: hosted
version: "1.18.0"
version: "1.17.2"
connectivity_plus:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1049,10 +1049,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
url: "https://pub.dev"
source: hosted
version: "1.10.0"
version: "1.9.1"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -1518,18 +1518,18 @@ packages:
dependency: transitive
description:
name: stack_trace
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
url: "https://pub.dev"
source: hosted
version: "1.11.1"
version: "1.11.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
url: "https://pub.dev"
source: hosted
version: "2.1.2"
version: "2.1.1"
stream_transform:
dependency: transitive
description:
Expand Down Expand Up @@ -1597,10 +1597,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
url: "https://pub.dev"
source: hosted
version: "0.6.1"
version: "0.6.0"
timelines:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1781,10 +1781,10 @@ packages:
dependency: transitive
description:
name: web
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
url: "https://pub.dev"
source: hosted
version: "0.3.0"
version: "0.1.4-beta"
web_socket_channel:
dependency: transitive
description:
Expand Down
2 changes: 2 additions & 0 deletions test/helpers/test_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ GraphqlConfig getAndRegisterGraphqlConfig() {
);
});

when(service.getToken()).thenAnswer((_) async => "sample_token");

locator.registerSingleton<GraphqlConfig>(service);
return service;
}
Expand Down
Loading

0 comments on commit b1d594f

Please sign in to comment.