elCaribe app - customization and branding
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class CommentNewsRemoteDataSource {
|
||||
Future<dynamic> getCommentNews({required String limit, required String offset, required String newsId}) async {
|
||||
try {
|
||||
final body = {LIMIT: limit, OFFSET: offset, NEWS_ID: newsId};
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.getCommentByNewsApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'package:news/data/models/CommentModel.dart';
|
||||
import 'package:news/data/repositories/CommentNews/commNewsRemoteDataSource.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class CommentNewsRepository {
|
||||
static final CommentNewsRepository _commentNewsRepository = CommentNewsRepository._internal();
|
||||
|
||||
late CommentNewsRemoteDataSource _commentNewsRemoteDataSource;
|
||||
|
||||
factory CommentNewsRepository() {
|
||||
_commentNewsRepository._commentNewsRemoteDataSource = CommentNewsRemoteDataSource();
|
||||
return _commentNewsRepository;
|
||||
}
|
||||
|
||||
CommentNewsRepository._internal();
|
||||
|
||||
Future<Map<String, dynamic>> getCommentNews({required String offset, required String limit, required String newsId}) async {
|
||||
final result = await _commentNewsRemoteDataSource.getCommentNews(limit: limit, offset: offset, newsId: newsId);
|
||||
if (result[ERROR]) {
|
||||
return {ERROR: result[ERROR], MESSAGE: result[MESSAGE]};
|
||||
} else {
|
||||
final List<CommentModel> commentsList = (result[DATA] as List).map((e) => CommentModel.fromJson(e)).toList();
|
||||
final List<ReplyModel> replyList = [];
|
||||
for (var i in commentsList) {
|
||||
replyList.addAll(i.replyComList as List<ReplyModel>);
|
||||
}
|
||||
return {ERROR: result[ERROR], "total": result[TOTAL], "CommentNews": commentsList};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user