elCaribe app - customization and branding
This commit is contained in:
124
news-app/lib/data/models/AppSystemSettingModel.dart
Normal file
124
news-app/lib/data/models/AppSystemSettingModel.dart
Normal file
@@ -0,0 +1,124 @@
|
||||
import 'package:news/data/models/appLanguageModel.dart';
|
||||
import 'package:news/utils/constant.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class AppSystemSettingModel {
|
||||
String? breakNewsMode, liveStreamMode, catMode, subCatMode, commentMode, inAppAdsMode, iosInAppAdsMode, adsType, iosAdsType;
|
||||
String? goRewardedId, goInterId, goBannerId, goNativeId;
|
||||
String? goIOSRewardedId, goIOSInterId, goIOSBannerId, goIOSNativeId;
|
||||
String? gameId, iosGameId;
|
||||
String? unityRewardedId, unityInterId, unityBannerId, unityIOSRewardedId, unityIOSInterId, unityIOSBannerId;
|
||||
String? locationWiseNewsMode, weatherMode, maintenanceMode, forceUpdateMode;
|
||||
LanguageModel? defaultLangDataModel;
|
||||
String? rssFeedMode, mobileLoginMode, countryCode, shareAppText, appstoreId, androidAppLink, iosAppLink;
|
||||
VideoViewType? videoTypePreference;
|
||||
String? androidAppVersion, iosAppVersion, googleGeminiApiKey;
|
||||
|
||||
AppSystemSettingModel(
|
||||
{this.breakNewsMode,
|
||||
this.liveStreamMode,
|
||||
this.catMode,
|
||||
this.subCatMode,
|
||||
this.commentMode,
|
||||
this.inAppAdsMode,
|
||||
this.iosInAppAdsMode,
|
||||
this.adsType,
|
||||
this.iosAdsType,
|
||||
this.goRewardedId,
|
||||
this.goBannerId,
|
||||
this.goInterId,
|
||||
this.goNativeId,
|
||||
this.goIOSBannerId,
|
||||
this.goIOSInterId,
|
||||
this.goIOSNativeId,
|
||||
this.goIOSRewardedId,
|
||||
this.gameId,
|
||||
this.iosGameId,
|
||||
this.unityRewardedId,
|
||||
this.unityInterId,
|
||||
this.unityBannerId,
|
||||
this.unityIOSRewardedId,
|
||||
this.unityIOSInterId,
|
||||
this.unityIOSBannerId,
|
||||
this.defaultLangDataModel,
|
||||
this.locationWiseNewsMode,
|
||||
this.weatherMode,
|
||||
this.maintenanceMode,
|
||||
this.rssFeedMode,
|
||||
this.mobileLoginMode,
|
||||
this.countryCode,
|
||||
this.shareAppText,
|
||||
this.appstoreId,
|
||||
this.androidAppLink,
|
||||
this.iosAppLink,
|
||||
this.videoTypePreference,
|
||||
this.forceUpdateMode,
|
||||
this.androidAppVersion,
|
||||
this.iosAppVersion,
|
||||
this.googleGeminiApiKey});
|
||||
|
||||
factory AppSystemSettingModel.fromJson(Map<String, dynamic> json) {
|
||||
var defaultList = (json[DEFAULT_LANG]);
|
||||
|
||||
LanguageModel defaultLangData;
|
||||
if (defaultList == null && defaultList.isEmpty) {
|
||||
defaultLangData = LanguageModel();
|
||||
} else {
|
||||
defaultLangData = LanguageModel.fromJson(defaultList);
|
||||
}
|
||||
|
||||
return AppSystemSettingModel(
|
||||
breakNewsMode: json[BREAK_NEWS_MODE],
|
||||
liveStreamMode: json[LIVE_STREAM_MODE],
|
||||
catMode: json[CATEGORY_MODE],
|
||||
subCatMode: json[SUBCAT_MODE],
|
||||
commentMode: json[COMM_MODE],
|
||||
inAppAdsMode: json[ADS_MODE],
|
||||
iosInAppAdsMode: json[IOS_ADS_MODE],
|
||||
adsType: json[ADS_TYPE],
|
||||
iosAdsType: json[IOS_ADS_TYPE],
|
||||
goRewardedId: json[GO_REWARDED_ID],
|
||||
goInterId: json[GO_INTER_ID],
|
||||
goBannerId: json[GO_BANNER_ID],
|
||||
goNativeId: json[GO_NATIVE_ID],
|
||||
goIOSRewardedId: json[IOS_GO_REWARDED_ID],
|
||||
goIOSNativeId: json[IOS_GO_NATIVE_ID],
|
||||
goIOSInterId: json[IOS_GO_INTER_ID],
|
||||
goIOSBannerId: json[IOS_GO_BANNER_ID],
|
||||
gameId: json[U_AND_GAME_ID],
|
||||
iosGameId: json[IOS_U_GAME_ID],
|
||||
unityRewardedId: json[U_REWARDED_ID],
|
||||
unityInterId: json[U_INTER_ID],
|
||||
unityBannerId: json[U_BANNER_ID],
|
||||
unityIOSRewardedId: json[IOS_U_REWARDED_ID],
|
||||
unityIOSInterId: json[IOS_U_INTER_ID],
|
||||
unityIOSBannerId: json[IOS_U_BANNER_ID],
|
||||
defaultLangDataModel: defaultLangData,
|
||||
locationWiseNewsMode: json[LOCATION_WISE_NEWS_MODE],
|
||||
weatherMode: json[WEATHER_MODE],
|
||||
maintenanceMode: json[MAINTENANCE_MODE],
|
||||
rssFeedMode: json[RSS_FEED_MODE],
|
||||
mobileLoginMode: json[MOBILE_LOGIN_MODE],
|
||||
countryCode: json[COUNTRY_CODE],
|
||||
shareAppText: json[SHARE_APP_TEXT],
|
||||
appstoreId: json[APPSTORE_ID],
|
||||
androidAppLink: json[WEB_SETTING][ANDROID_APP_LINK],
|
||||
iosAppLink: json[WEB_SETTING][IOS_APP_LINK],
|
||||
videoTypePreference: fromVideoTypeJson(json[VIDEO_TYPE_PREFERENCE]),
|
||||
forceUpdateMode: json[FORCE_UPDT_APP_MODE] ?? "0",
|
||||
androidAppVersion: json[ANDROID_APP_VERSION] ?? '',
|
||||
iosAppVersion: json[IOS_APP_VERSION] ?? '',
|
||||
googleGeminiApiKey: json[GEMINI_API_KEY]);
|
||||
}
|
||||
|
||||
static VideoViewType? fromVideoTypeJson(String? value) {
|
||||
switch (value) {
|
||||
case 'normal_style':
|
||||
return VideoViewType.normal;
|
||||
case 'page_style':
|
||||
return VideoViewType.page;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
34
news-app/lib/data/models/AuthModel.dart
Normal file
34
news-app/lib/data/models/AuthModel.dart
Normal file
@@ -0,0 +1,34 @@
|
||||
import 'package:news/data/models/authorModel.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class AuthModel {
|
||||
String? id;
|
||||
String? name;
|
||||
String? email;
|
||||
String? mobile;
|
||||
String? profile;
|
||||
String? type;
|
||||
String? status;
|
||||
String? isFirstLogin; // 0 - new user, 1 - existing user
|
||||
String? role;
|
||||
String? jwtToken;
|
||||
int? isAuthor;
|
||||
Author? authorDetails;
|
||||
|
||||
AuthModel({this.id, this.name, this.email, this.mobile, this.profile, this.type, this.status, this.isFirstLogin, this.role, this.jwtToken, this.authorDetails, this.isAuthor = 0});
|
||||
|
||||
AuthModel.fromJson(Map<String, dynamic> json) {
|
||||
id = json[ID].toString();
|
||||
name = json[NAME] ?? "";
|
||||
email = json[EMAIL] ?? "";
|
||||
mobile = json[MOBILE] ?? "";
|
||||
profile = json[PROFILE] ?? "";
|
||||
type = json[TYPE] ?? "";
|
||||
status = json[STATUS].toString();
|
||||
isFirstLogin = (json[IS_LOGIN] != null) ? json[IS_LOGIN].toString() : "";
|
||||
role = json[ROLE].toString();
|
||||
jwtToken = json[TOKEN] ?? "";
|
||||
isAuthor = json[IS_AUTHOR];
|
||||
authorDetails = (isAuthor == 1 && json[AUTHOR] != null) ? Author.fromJson(json[AUTHOR]) : null;
|
||||
}
|
||||
}
|
||||
19
news-app/lib/data/models/BreakingNewsModel.dart
Normal file
19
news-app/lib/data/models/BreakingNewsModel.dart
Normal file
@@ -0,0 +1,19 @@
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class BreakingNewsModel {
|
||||
String? id, image, title, desc, contentType, contentValue, totalViews, slug;
|
||||
|
||||
BreakingNewsModel({this.id, this.image, this.title, this.desc, this.contentValue, this.contentType, this.totalViews, this.slug});
|
||||
|
||||
factory BreakingNewsModel.fromJson(Map<String, dynamic> json) {
|
||||
return BreakingNewsModel(
|
||||
id: json[ID].toString(),
|
||||
image: json[IMAGE],
|
||||
title: json[TITLE],
|
||||
desc: json[DESCRIPTION] ?? '',
|
||||
contentValue: json[CONTENT_VALUE],
|
||||
contentType: json[CONTENT_TYPE],
|
||||
totalViews: json[TOTAL_VIEWS].toString(),
|
||||
slug: json[SLUG]);
|
||||
}
|
||||
}
|
||||
26
news-app/lib/data/models/CategoryModel.dart
Normal file
26
news-app/lib/data/models/CategoryModel.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class CategoryModel {
|
||||
String? id, image, categoryName;
|
||||
List<SubCategoryModel>? subData;
|
||||
|
||||
CategoryModel({this.id, this.image, this.categoryName, this.subData});
|
||||
|
||||
factory CategoryModel.fromJson(Map<String, dynamic> json) {
|
||||
var subList = (json.containsKey(SUBCATEGORIES)) ? (json[SUBCATEGORIES] as List) : [];
|
||||
List<SubCategoryModel> subCatData = [];
|
||||
subCatData = (subList.isEmpty) ? [] : subList.map((data) => SubCategoryModel.fromJson(data)).toList();
|
||||
|
||||
return CategoryModel(id: json[ID].toString(), image: json[IMAGE] ?? "", categoryName: json[CATEGORY_NAME], subData: subCatData);
|
||||
}
|
||||
}
|
||||
|
||||
class SubCategoryModel {
|
||||
String? id, categoryId, subCatName;
|
||||
|
||||
SubCategoryModel({this.id, this.categoryId, this.subCatName});
|
||||
|
||||
factory SubCategoryModel.fromJson(Map<String, dynamic> json) {
|
||||
return SubCategoryModel(id: json[ID].toString(), categoryId: json[CATEGORY_ID].toString(), subCatName: json[SUBCAT_NAME] ?? json[SUBCATEGORY]);
|
||||
}
|
||||
}
|
||||
60
news-app/lib/data/models/CommentModel.dart
Normal file
60
news-app/lib/data/models/CommentModel.dart
Normal file
@@ -0,0 +1,60 @@
|
||||
import 'package:news/data/models/AuthModel.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class CommentModel {
|
||||
String? id, message, profile, date, name, status, like, dislike, totalLikes, totalDislikes, userId;
|
||||
List<ReplyModel>? replyComList;
|
||||
|
||||
CommentModel({this.id, this.message, this.profile, this.date, this.name, this.replyComList, this.status, this.like, this.dislike, this.totalLikes, this.totalDislikes, this.userId});
|
||||
|
||||
factory CommentModel.fromJson(Map<String, dynamic> json) {
|
||||
var replyList = (json[REPLY] as List);
|
||||
List<ReplyModel> replyData = [];
|
||||
if (replyList.isEmpty) {
|
||||
replyList = [];
|
||||
} else {
|
||||
replyData = replyList.map((data) => ReplyModel.fromJson(data)).toList();
|
||||
}
|
||||
|
||||
var userDetails = AuthModel.fromJson(json[USER]);
|
||||
|
||||
return CommentModel(
|
||||
id: json[ID].toString(),
|
||||
message: json[MESSAGE],
|
||||
profile: userDetails.profile,
|
||||
name: userDetails.name,
|
||||
date: json[DATE],
|
||||
status: json[STATUS].toString(),
|
||||
replyComList: replyData,
|
||||
like: json[LIKE].toString(),
|
||||
dislike: json[DISLIKE].toString(),
|
||||
totalDislikes: json[TOTAL_DISLIKE].toString(),
|
||||
totalLikes: json[TOTAL_LIKE].toString(),
|
||||
userId: json[USER_ID].toString());
|
||||
}
|
||||
}
|
||||
|
||||
class ReplyModel {
|
||||
String? id, message, profile, date, name, userId, parentId, newsId, status, like, dislike, totalLikes, totalDislikes;
|
||||
|
||||
ReplyModel({this.id, this.message, this.profile, this.date, this.name, this.userId, this.parentId, this.status, this.newsId, this.like, this.dislike, this.totalLikes, this.totalDislikes});
|
||||
|
||||
factory ReplyModel.fromJson(Map<String, dynamic> json) {
|
||||
var userDetails = AuthModel.fromJson(json[USER]);
|
||||
|
||||
return ReplyModel(
|
||||
id: json[ID].toString(),
|
||||
message: json[MESSAGE],
|
||||
profile: userDetails.profile,
|
||||
name: userDetails.name,
|
||||
date: json[DATE],
|
||||
userId: json[USER_ID].toString(),
|
||||
parentId: json[PARENT_ID].toString(),
|
||||
newsId: json[NEWS_ID].toString(),
|
||||
status: json[STATUS].toString(),
|
||||
like: json[LIKE].toString(),
|
||||
dislike: json[DISLIKE].toString(),
|
||||
totalDislikes: json[TOTAL_DISLIKE].toString(),
|
||||
totalLikes: json[TOTAL_LIKE].toString());
|
||||
}
|
||||
}
|
||||
97
news-app/lib/data/models/FeatureSectionModel.dart
Normal file
97
news-app/lib/data/models/FeatureSectionModel.dart
Normal file
@@ -0,0 +1,97 @@
|
||||
import 'package:news/data/models/BreakingNewsModel.dart';
|
||||
import 'package:news/data/models/NewsModel.dart';
|
||||
import 'package:news/data/models/adSpaceModel.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class FeatureSectionModel {
|
||||
String? id, languageId, title, shortDescription, newsType, videosType, categoryIds, subcategoryIds, newsIds, styleApp, createdAt, status, summarizedDesc;
|
||||
int? newsTotal, breakNewsTotal, videosTotal;
|
||||
List<NewsModel>? news;
|
||||
List<BreakingNewsModel>? breakNews, breakVideos;
|
||||
List<NewsModel>? videos;
|
||||
AdSpaceModel? adSpaceDetails;
|
||||
|
||||
FeatureSectionModel(
|
||||
{this.id,
|
||||
this.languageId,
|
||||
this.title,
|
||||
this.shortDescription,
|
||||
this.newsType,
|
||||
this.videosType,
|
||||
this.categoryIds,
|
||||
this.subcategoryIds,
|
||||
this.newsIds,
|
||||
this.styleApp,
|
||||
this.createdAt,
|
||||
this.newsTotal,
|
||||
this.breakNewsTotal,
|
||||
this.videosTotal,
|
||||
this.news,
|
||||
this.breakNews,
|
||||
this.videos,
|
||||
this.breakVideos,
|
||||
this.adSpaceDetails,
|
||||
this.summarizedDesc});
|
||||
|
||||
factory FeatureSectionModel.fromJson(Map<String, dynamic> json) {
|
||||
List<NewsModel> newsData = [];
|
||||
if (json.containsKey(NEWS)) {
|
||||
var newsList = (json[NEWS] as List);
|
||||
if (newsList.isEmpty) {
|
||||
newsList = [];
|
||||
} else {
|
||||
newsData = newsList.map((data) => NewsModel.fromJson(data)).toList();
|
||||
}
|
||||
}
|
||||
|
||||
List<BreakingNewsModel> breakNewsData = [];
|
||||
if (json.containsKey(BREAKING_NEWS)) {
|
||||
var breakNewsList = (json[BREAKING_NEWS] as List);
|
||||
if (breakNewsList.isEmpty) {
|
||||
breakNewsList = [];
|
||||
} else {
|
||||
breakNewsData = breakNewsList.map((data) => BreakingNewsModel.fromJson(data)).toList();
|
||||
}
|
||||
}
|
||||
|
||||
List<NewsModel> videosData = [];
|
||||
List<BreakingNewsModel> breakVideosData = [];
|
||||
if (json.containsKey(VIDEOS)) {
|
||||
var videosList = (json[VIDEOS] as List);
|
||||
if (videosList.isEmpty) {
|
||||
videosList = [];
|
||||
} else {
|
||||
if (json[VIDEOS_TYPE] == 'news') {
|
||||
videosData = videosList.map((data) => NewsModel.fromVideos(data)).toList();
|
||||
} else {
|
||||
breakVideosData = videosList.map((data) => BreakingNewsModel.fromJson(data)).toList();
|
||||
}
|
||||
}
|
||||
}
|
||||
AdSpaceModel? adSpaceData;
|
||||
if (json.containsKey(AD_SPACES)) {
|
||||
adSpaceData = AdSpaceModel.fromJson(json[AD_SPACES]);
|
||||
}
|
||||
|
||||
return FeatureSectionModel(
|
||||
id: json[ID].toString(),
|
||||
languageId: json[LANGUAGE_ID].toString(),
|
||||
title: json[TITLE],
|
||||
shortDescription: json[SHORT_DESC],
|
||||
newsType: json[NEWS_TYPE],
|
||||
videosType: json[VIDEOS_TYPE],
|
||||
categoryIds: json[CAT_IDS],
|
||||
subcategoryIds: json[SUBCAT_IDS],
|
||||
newsIds: json[NEWS_IDS],
|
||||
styleApp: json[STYLE_APP],
|
||||
newsTotal: json[NEWS_TOTAL],
|
||||
breakNewsTotal: json[BREAK_NEWS_TOTAL],
|
||||
videosTotal: json[VIDEOS_TOTAL],
|
||||
summarizedDesc: json[SUMM_DESCRIPTION],
|
||||
news: newsData,
|
||||
breakNews: breakNewsData,
|
||||
videos: videosData,
|
||||
breakVideos: breakVideosData,
|
||||
adSpaceDetails: adSpaceData);
|
||||
}
|
||||
}
|
||||
11
news-app/lib/data/models/LiveStreamingModel.dart
Normal file
11
news-app/lib/data/models/LiveStreamingModel.dart
Normal file
@@ -0,0 +1,11 @@
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class LiveStreamingModel {
|
||||
String? id, image, title, type, url, updatedDate;
|
||||
|
||||
LiveStreamingModel({this.id, this.image, this.title, this.type, this.url, this.updatedDate});
|
||||
|
||||
factory LiveStreamingModel.fromJson(Map<String, dynamic> json) {
|
||||
return LiveStreamingModel(id: json[ID].toString(), image: json[IMAGE], title: json[TITLE], type: json[TYPE], url: json[URL], updatedDate: json[UPDATED_DATE]);
|
||||
}
|
||||
}
|
||||
196
news-app/lib/data/models/NewsModel.dart
Normal file
196
news-app/lib/data/models/NewsModel.dart
Normal file
@@ -0,0 +1,196 @@
|
||||
import 'package:news/data/models/CategoryModel.dart';
|
||||
import 'package:news/data/models/authorModel.dart';
|
||||
import 'package:news/data/models/locationCityModel.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
import 'package:news/data/models/OptionModel.dart';
|
||||
|
||||
class NewsModel {
|
||||
String? id, userId, newsId, categoryId, title, date, contentType, contentValue, image, desc, categoryName, dateSent, totalLikes, like, shortDesc;
|
||||
String? bookmark, keyName, tagId, tagName, subCatId, img, subCatName, showTill, langId, totalViews, locationId, locationName, metaKeyword, metaTitle, metaDescription, slug, publishDate;
|
||||
|
||||
List<ImageDataModel>? imageDataList;
|
||||
|
||||
bool? history = false;
|
||||
String? question, status, type, sourceType;
|
||||
List<OptionModel>? optionDataList;
|
||||
int? from, isExpired, isCommentEnabled;
|
||||
Author? authorDetails;
|
||||
UserAuthorModel? userAthorDetails;
|
||||
|
||||
NewsModel(
|
||||
{this.id,
|
||||
this.userId,
|
||||
this.newsId,
|
||||
this.categoryId,
|
||||
this.title,
|
||||
this.date,
|
||||
this.contentType,
|
||||
this.contentValue,
|
||||
this.image,
|
||||
this.desc,
|
||||
this.categoryName,
|
||||
this.dateSent,
|
||||
this.imageDataList,
|
||||
this.totalLikes,
|
||||
this.like,
|
||||
this.keyName,
|
||||
this.tagName,
|
||||
this.subCatId,
|
||||
this.tagId,
|
||||
this.history,
|
||||
this.optionDataList,
|
||||
this.question,
|
||||
this.status,
|
||||
this.type,
|
||||
this.from,
|
||||
this.img,
|
||||
this.subCatName,
|
||||
this.showTill,
|
||||
this.bookmark,
|
||||
this.langId,
|
||||
this.totalViews,
|
||||
this.locationId,
|
||||
this.locationName,
|
||||
this.metaTitle,
|
||||
this.metaDescription,
|
||||
this.metaKeyword,
|
||||
this.slug,
|
||||
this.publishDate,
|
||||
this.isExpired,
|
||||
this.isCommentEnabled,
|
||||
this.sourceType,
|
||||
this.shortDesc,
|
||||
this.authorDetails,
|
||||
this.userAthorDetails});
|
||||
|
||||
factory NewsModel.history(String history) {
|
||||
return NewsModel(title: history, history: true);
|
||||
}
|
||||
|
||||
factory NewsModel.fromSurvey(Map<String, dynamic> json) {
|
||||
List<OptionModel> optionList = (json[OPTION] as List).map((data) => OptionModel.fromJson(data)).toList();
|
||||
|
||||
return NewsModel(id: json[ID].toString(), question: json[QUESTION], status: json[STATUS].toString(), optionDataList: optionList, type: "survey", from: 1);
|
||||
}
|
||||
|
||||
factory NewsModel.fromVideos(Map<String, dynamic> json) {
|
||||
String? tagName;
|
||||
|
||||
tagName = (json[TAG] == null) ? "" : json[TAG];
|
||||
return NewsModel(
|
||||
id: json[ID].toString(),
|
||||
newsId: json[ID].toString(),
|
||||
//for bookmark get/set
|
||||
desc: json[DESCRIPTION] ?? '',
|
||||
date: json[DATE],
|
||||
image: json[IMAGE],
|
||||
title: json[TITLE],
|
||||
contentType: json[CONTENT_TYPE],
|
||||
contentValue: json[CONTENT_VALUE],
|
||||
tagId: json[TAG_ID],
|
||||
tagName: tagName,
|
||||
categoryName: json[CATEGORY_NAME] ?? '',
|
||||
sourceType: json[SOURCE_TYPE],
|
||||
shortDesc: json[SUMM_DESCRIPTION] ?? '');
|
||||
}
|
||||
|
||||
factory NewsModel.fromJson(Map<String, dynamic> json) {
|
||||
bool isAuthor = (json[USER] == null) ? false : (json[USER][IS_AUTHOR] == 1);
|
||||
|
||||
String? tagName;
|
||||
|
||||
tagName = (json[TAG] == null) ? "" : json[TAG];
|
||||
|
||||
List<ImageDataModel> imageData = [];
|
||||
var imageList = (json.containsKey(IMAGES))
|
||||
? json[IMAGES] as List<dynamic>
|
||||
: (json.containsKey(IMAGE_DATA))
|
||||
? json[IMAGE_DATA] as List
|
||||
: [];
|
||||
imageList = (imageList.isEmpty) ? [] : imageList.map((data) => ImageDataModel.fromJson(data)).toList();
|
||||
if (imageList.isNotEmpty) imageData = imageList as List<ImageDataModel>;
|
||||
var categoryName = '';
|
||||
try {
|
||||
categoryName = (json.containsKey(CATEGORY_NAME))
|
||||
? json[CATEGORY_NAME]
|
||||
: (json.containsKey(CATEGORY))
|
||||
? CategoryModel.fromJson(json[CATEGORY]).categoryName
|
||||
: '';
|
||||
} catch (e) {}
|
||||
|
||||
var subcategoryName =
|
||||
(json.containsKey(SUBCAT_NAME)) ? json[SUBCAT_NAME] : ((json.containsKey(SUBCATEGORY) && json[SUBCATEGORY] != null) ? SubCategoryModel.fromJson(json[SUBCATEGORY]).subCatName : '');
|
||||
|
||||
return NewsModel(
|
||||
id: json[ID].toString(),
|
||||
userId: json[USER_ID].toString(),
|
||||
newsId: (json[NEWS_ID] != null && json[NEWS_ID].toString().trim().isNotEmpty) ? json[NEWS_ID].toString() : json[ID].toString(),
|
||||
//incase of null newsId in Response
|
||||
categoryId: json[CATEGORY_ID].toString(),
|
||||
title: json[TITLE],
|
||||
date: json[DATE],
|
||||
contentType: json[CONTENT_TYPE],
|
||||
contentValue: json[CONTENT_VALUE],
|
||||
image: json[IMAGE],
|
||||
desc: json[DESCRIPTION] ?? '',
|
||||
categoryName: categoryName,
|
||||
dateSent: json[DATE_SENT],
|
||||
imageDataList: imageData,
|
||||
totalLikes: json[TOTAL_LIKE].toString(),
|
||||
like: json[LIKE].toString(),
|
||||
bookmark: json[BOOKMARK].toString(),
|
||||
tagId: json[TAG_ID],
|
||||
tagName: tagName,
|
||||
subCatId: json[SUBCAT_ID].toString(),
|
||||
history: false,
|
||||
type: "news",
|
||||
img: "",
|
||||
subCatName: subcategoryName,
|
||||
showTill: json[SHOW_TILL],
|
||||
langId: json[LANGUAGE_ID].toString(),
|
||||
totalViews: json[TOTAL_VIEWS].toString(),
|
||||
locationId: (json.containsKey(LOCATION) && json[LOCATION] != null) ? LocationCityModel.fromJson(json[LOCATION]).id.toString() : json[LOCATION_ID].toString(),
|
||||
locationName: (json.containsKey(LOCATION) && json[LOCATION] != null) ? LocationCityModel.fromJson(json[LOCATION]).locationName : json[LOCATION_NAME],
|
||||
metaKeyword: json[META_KEYWORD],
|
||||
metaTitle: json[META_TITLE],
|
||||
metaDescription: json[META_DESC],
|
||||
slug: json[SLUG],
|
||||
publishDate: json[PUBLISHED_DATE],
|
||||
isExpired: json[IS_EXPIRED] ?? 0,
|
||||
status: json[STATUS].toString(),
|
||||
isCommentEnabled: json[IS_COMMENT_ENABLED] ?? 1,
|
||||
shortDesc: json[SUMM_DESCRIPTION] ?? '',
|
||||
userAthorDetails: (json[USER] == null) ? null : UserAuthorModel.fromJson(json[USER]),
|
||||
authorDetails: (isAuthor && json[AUTHOR] != null) ? Author.fromJson(json[AUTHOR]) : null);
|
||||
}
|
||||
}
|
||||
|
||||
class ImageDataModel {
|
||||
String? id;
|
||||
String? otherImage;
|
||||
|
||||
ImageDataModel({this.otherImage, this.id});
|
||||
|
||||
factory ImageDataModel.fromJson(Map<String, dynamic> json) {
|
||||
return ImageDataModel(otherImage: json[OTHER_IMAGE], id: json[ID].toString());
|
||||
}
|
||||
}
|
||||
|
||||
class UserAuthorModel {
|
||||
String? id;
|
||||
String? name;
|
||||
String? profile;
|
||||
int? isAuthor;
|
||||
Author? authorData;
|
||||
|
||||
UserAuthorModel({this.id, this.name, this.profile, this.isAuthor, this.authorData});
|
||||
|
||||
factory UserAuthorModel.fromJson(Map<String, dynamic> json) {
|
||||
return UserAuthorModel(
|
||||
id: json[ID].toString(),
|
||||
name: json[NAME],
|
||||
profile: json[PROFILE].toString(),
|
||||
isAuthor: json[IS_AUTHOR] ?? 0,
|
||||
authorData: (json.containsKey(AUTHOR) && json[AUTHOR] != null) ? Author.fromJson(json[AUTHOR]) : null);
|
||||
}
|
||||
}
|
||||
20
news-app/lib/data/models/OptionModel.dart
Normal file
20
news-app/lib/data/models/OptionModel.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class OptionModel {
|
||||
String? id;
|
||||
String? options;
|
||||
String? counter;
|
||||
double? percentage;
|
||||
String? questionId;
|
||||
|
||||
OptionModel({this.id, this.options, this.counter, this.percentage, this.questionId});
|
||||
|
||||
factory OptionModel.fromJson(Map<String, dynamic> json) {
|
||||
return OptionModel(
|
||||
id: json[ID].toString(),
|
||||
options: json[OPTIONS],
|
||||
counter: json[COUNTER].toString(),
|
||||
percentage: (json[PERCENTAGE].runtimeType == int) ? double.parse(json[PERCENTAGE].toString()) : json[PERCENTAGE],
|
||||
questionId: json[QUESTION_ID].toString());
|
||||
}
|
||||
}
|
||||
15
news-app/lib/data/models/OtherPageModel.dart
Normal file
15
news-app/lib/data/models/OtherPageModel.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class OtherPageModel {
|
||||
String? id, pageContent, title, image;
|
||||
//slug,meta_description,meta_keywords not in use.
|
||||
OtherPageModel({this.id, this.pageContent, this.title, this.image});
|
||||
|
||||
factory OtherPageModel.fromJson(Map<String, dynamic> json) {
|
||||
return OtherPageModel(id: json[ID].toString(), pageContent: json[PAGE_CONTENT], title: json[TITLE], image: json[PAGE_ICON]);
|
||||
}
|
||||
|
||||
factory OtherPageModel.fromPrivacyTermsJson(Map<String, dynamic> json) {
|
||||
return OtherPageModel(id: json[ID].toString().toString(), pageContent: json[PAGE_CONTENT], title: json[TITLE]);
|
||||
}
|
||||
}
|
||||
23
news-app/lib/data/models/RSSFeedModel.dart
Normal file
23
news-app/lib/data/models/RSSFeedModel.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
import 'package:news/data/models/CategoryModel.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class RSSFeedModel {
|
||||
String? id, feedName, feedUrl, categoryId, categoryName, subCatName, tagName;
|
||||
|
||||
RSSFeedModel({this.id, this.feedName, this.feedUrl, this.categoryId, this.tagName, this.categoryName, this.subCatName});
|
||||
|
||||
factory RSSFeedModel.fromJson(Map<String, dynamic> json) {
|
||||
String? tagName;
|
||||
|
||||
tagName = (json[TAG] == null) ? "" : json[TAG];
|
||||
var categoryName = (json.containsKey(CATEGORY_NAME))
|
||||
? json[CATEGORY_NAME]
|
||||
: (json.containsKey(CATEGORY) && (json[CATEGORY] != null))
|
||||
? CategoryModel.fromJson(json[CATEGORY]).categoryName
|
||||
: '';
|
||||
var subcategoryName =
|
||||
(json.containsKey(SUBCAT_NAME)) ? json[SUBCAT_NAME] : ((json.containsKey(SUBCATEGORY) && json[SUBCATEGORY] != null) ? SubCategoryModel.fromJson(json[SUBCATEGORY]).subCatName : '');
|
||||
|
||||
return RSSFeedModel(id: json[ID].toString(), feedName: json[FEED_NAME].toString(), feedUrl: json[FEED_URL], tagName: tagName, categoryName: categoryName, subCatName: subcategoryName);
|
||||
}
|
||||
}
|
||||
42
news-app/lib/data/models/SettingsModel.dart
Normal file
42
news-app/lib/data/models/SettingsModel.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
class SettingsModel {
|
||||
bool showIntroSlider;
|
||||
bool notification;
|
||||
String languageCode;
|
||||
String theme;
|
||||
String token;
|
||||
|
||||
SettingsModel({
|
||||
required this.languageCode,
|
||||
required this.showIntroSlider,
|
||||
required this.theme,
|
||||
required this.notification,
|
||||
required this.token,
|
||||
});
|
||||
|
||||
static SettingsModel fromJson(var settingsJson) {
|
||||
//to see the json response go to getCurrentSettings() function in settingsRepository
|
||||
return SettingsModel(
|
||||
theme: settingsJson['theme'],
|
||||
showIntroSlider: settingsJson['showIntroSlider'],
|
||||
notification: settingsJson['notification'],
|
||||
languageCode: settingsJson['languageCode'],
|
||||
token: settingsJson['token'],
|
||||
);
|
||||
}
|
||||
|
||||
SettingsModel copyWith({
|
||||
String? theme,
|
||||
bool? showIntroSlider,
|
||||
bool? notification,
|
||||
String? languageCode,
|
||||
String? token,
|
||||
}) {
|
||||
return SettingsModel(
|
||||
theme: theme ?? this.theme,
|
||||
notification: notification ?? this.notification,
|
||||
showIntroSlider: showIntroSlider ?? this.showIntroSlider,
|
||||
languageCode: languageCode ?? this.languageCode,
|
||||
token: token ?? this.token,
|
||||
);
|
||||
}
|
||||
}
|
||||
11
news-app/lib/data/models/TagModel.dart
Normal file
11
news-app/lib/data/models/TagModel.dart
Normal file
@@ -0,0 +1,11 @@
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class TagModel {
|
||||
String? id, tagName;
|
||||
|
||||
TagModel({this.id, this.tagName});
|
||||
|
||||
factory TagModel.fromJson(Map<String, dynamic> json) {
|
||||
return TagModel(id: json[ID].toString(), tagName: json[TAGNAME]);
|
||||
}
|
||||
}
|
||||
24
news-app/lib/data/models/WeatherData.dart
Normal file
24
news-app/lib/data/models/WeatherData.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
class WeatherDetails {
|
||||
String? name;
|
||||
String? region;
|
||||
double? tempC;
|
||||
String? text;
|
||||
String? icon;
|
||||
double? minTempC;
|
||||
double? maxTempC;
|
||||
String? country;
|
||||
|
||||
WeatherDetails({this.name, this.region, this.tempC, this.text, this.icon, this.maxTempC, this.minTempC, this.country});
|
||||
|
||||
factory WeatherDetails.fromJson(Map<String, dynamic> json) {
|
||||
return WeatherDetails(
|
||||
name: json["location"]["name"],
|
||||
region: json["location"]["region"],
|
||||
country: json["location"]["country"],
|
||||
tempC: json["current"]["temp_c"],
|
||||
text: json["current"]["condition"]["text"],
|
||||
icon: json["current"]["condition"]["icon"],
|
||||
maxTempC: json["forecast"]["forecastday"][0]["day"]["maxtemp_c"],
|
||||
minTempC: json["forecast"]["forecastday"][0]["day"]["mintemp_c"]);
|
||||
}
|
||||
}
|
||||
13
news-app/lib/data/models/adSpaceModel.dart
Normal file
13
news-app/lib/data/models/adSpaceModel.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class AdSpaceModel {
|
||||
String? id, adSpace, adFeaturedSectionId, adImage, adUrl;
|
||||
|
||||
AdSpaceModel({this.id, this.adSpace, this.adFeaturedSectionId, this.adImage, this.adUrl});
|
||||
|
||||
//place Ad just above mentioned adFeaturedSectionId
|
||||
|
||||
factory AdSpaceModel.fromJson(Map<String, dynamic> json) {
|
||||
return AdSpaceModel(id: json[ID].toString(), adSpace: json[AD_SPACE], adFeaturedSectionId: json[AD_FEATURED_SECTION_ID].toString(), adImage: json[AD_IMAGE], adUrl: json[AD_URL]);
|
||||
}
|
||||
}
|
||||
16
news-app/lib/data/models/appLanguageModel.dart
Normal file
16
news-app/lib/data/models/appLanguageModel.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class LanguageModel {
|
||||
String? id, language, languageDisplayName, image, code;
|
||||
int? isRTL;
|
||||
LanguageModel({this.id, this.image, this.language, this.languageDisplayName, this.code, this.isRTL});
|
||||
factory LanguageModel.fromJson(Map<String, dynamic> json) {
|
||||
return LanguageModel(
|
||||
id: json[ID].toString(),
|
||||
image: json[IMAGE],
|
||||
language: json[LANGUAGE],
|
||||
languageDisplayName: (json[DISPLAY_NAME_LANG] != "") ? json[DISPLAY_NAME_LANG] : json[LANGUAGE],
|
||||
code: json[CODE],
|
||||
isRTL: (json[ISRTL].runtimeType == int) ? json[ISRTL] : int.tryParse(json[ISRTL]));
|
||||
}
|
||||
}
|
||||
49
news-app/lib/data/models/authorModel.dart
Normal file
49
news-app/lib/data/models/authorModel.dart
Normal file
@@ -0,0 +1,49 @@
|
||||
import 'package:news/utils/constant.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class Author {
|
||||
final int? id;
|
||||
final int? userId;
|
||||
final String? bio;
|
||||
final String? telegramLink;
|
||||
final String? linkedinLink;
|
||||
final String? facebookLink;
|
||||
final String? whatsappLink;
|
||||
final AuthorStatus? status;
|
||||
|
||||
Author({
|
||||
this.id,
|
||||
this.userId,
|
||||
this.bio,
|
||||
this.telegramLink,
|
||||
this.linkedinLink,
|
||||
this.facebookLink,
|
||||
this.whatsappLink,
|
||||
this.status,
|
||||
});
|
||||
|
||||
factory Author.fromJson(Map<String, dynamic> json) {
|
||||
return Author(
|
||||
id: json['id'] as int?,
|
||||
userId: json['user_id'] as int?,
|
||||
bio: json['bio'] ?? "",
|
||||
telegramLink: json['telegram_link'] ?? "",
|
||||
linkedinLink: json['linkedin_link'] ?? "",
|
||||
facebookLink: json['facebook_link'] ?? "",
|
||||
whatsappLink: json['whatsapp_link'] ?? "",
|
||||
status: fromAuthorStatus(json[STATUS]));
|
||||
}
|
||||
}
|
||||
|
||||
AuthorStatus? fromAuthorStatus(String? value) {
|
||||
switch (value) {
|
||||
case 'pending':
|
||||
return AuthorStatus.pending;
|
||||
case 'approved':
|
||||
return AuthorStatus.approved;
|
||||
case 'rejected':
|
||||
return AuthorStatus.rejected;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
14
news-app/lib/data/models/locationCityModel.dart
Normal file
14
news-app/lib/data/models/locationCityModel.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class LocationCityModel {
|
||||
final String id;
|
||||
final String locationName;
|
||||
final String latitude;
|
||||
final String longitude;
|
||||
|
||||
LocationCityModel({required this.latitude, required this.longitude, required this.id, required this.locationName});
|
||||
|
||||
factory LocationCityModel.fromJson(Map<String, dynamic> json) {
|
||||
return LocationCityModel(id: json[ID].toString(), locationName: json[LOCATION_NAME], latitude: json[LATITUDE].toString(), longitude: json[LONGITUDE].toString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
import 'dart:io';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:news/utils/uiUtils.dart';
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class AddNewsRemoteDataSource {
|
||||
//to update fcmId of user's
|
||||
Future<dynamic> addNewsData(
|
||||
{required BuildContext context,
|
||||
required String actionType,
|
||||
required String catId,
|
||||
required String title,
|
||||
required String conTypeId,
|
||||
required String conType,
|
||||
required String langId,
|
||||
File? image,
|
||||
String? newsId,
|
||||
String? subCatId,
|
||||
String? showTill,
|
||||
String? tagId,
|
||||
String? url,
|
||||
String? desc,
|
||||
String? summDescription,
|
||||
String? locationId,
|
||||
File? videoUpload,
|
||||
List<File>? otherImage,
|
||||
String? publishDate,
|
||||
required String metaTitle,
|
||||
required String metaDescription,
|
||||
required String metaKeyword,
|
||||
required String slug,
|
||||
required int isDraft}) async {
|
||||
try {
|
||||
Map<String, dynamic> body = {
|
||||
ACTION_TYPE: actionType,
|
||||
CATEGORY_ID: catId,
|
||||
TITLE: title,
|
||||
CONTENT_TYPE: conTypeId,
|
||||
LANGUAGE_ID: langId,
|
||||
META_TITLE: metaTitle,
|
||||
META_DESC: metaDescription,
|
||||
META_KEYWORD: metaKeyword,
|
||||
SLUG: slug,
|
||||
SUMM_DESCRIPTION: summDescription,
|
||||
IS_DRAFT_KEY: isDraft
|
||||
};
|
||||
Map<String, dynamic> result = {};
|
||||
|
||||
if (image != null) body[IMAGE] = await MultipartFile.fromFile(image.path);
|
||||
if (newsId != null) body[NEWS_ID] = newsId; // in case of update news only
|
||||
if (subCatId != null) body[SUBCAT_ID] = subCatId;
|
||||
if (showTill != null) body[SHOW_TILL] = showTill;
|
||||
if (tagId != null) body[TAG_ID] = tagId;
|
||||
if (desc != null) body[DESCRIPTION] = desc;
|
||||
if (locationId != null) body[LOCATION_ID] = locationId;
|
||||
if (publishDate != null) body[PUBLISHED_DATE] = publishDate;
|
||||
|
||||
if (url != null && (conType == UiUtils.getTranslatedLabel(context, 'videoOtherUrlLbl') || conType == UiUtils.getTranslatedLabel(context, 'videoYoutubeLbl'))) {
|
||||
body[CONTENT_DATA] = url;
|
||||
} else if (conType == UiUtils.getTranslatedLabel(context, 'videoUploadLbl')) {
|
||||
if (videoUpload != null) body[CONTENT_DATA] = await MultipartFile.fromFile(videoUpload.path);
|
||||
}
|
||||
|
||||
if (otherImage!.isNotEmpty) {
|
||||
for (var i = 0; i < otherImage.length; i++) {
|
||||
body["ofile[$i]"] = await MultipartFile.fromFile(otherImage[i].path);
|
||||
}
|
||||
}
|
||||
|
||||
result = await Api.sendApiRequest(body: body, url: Api.setNewsApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:news/data/repositories/AddNews/addNewsRemoteDataSource.dart';
|
||||
|
||||
class AddNewsRepository {
|
||||
static final AddNewsRepository _addNewsRepository = AddNewsRepository._internal();
|
||||
|
||||
late AddNewsRemoteDataSource _addNewsRemoteDataSource;
|
||||
|
||||
factory AddNewsRepository() {
|
||||
_addNewsRepository._addNewsRemoteDataSource = AddNewsRemoteDataSource();
|
||||
return _addNewsRepository;
|
||||
}
|
||||
|
||||
AddNewsRepository._internal();
|
||||
|
||||
Future<Map<String, dynamic>> addNews(
|
||||
{required BuildContext context,
|
||||
required String actionType,
|
||||
required String catId,
|
||||
required String title,
|
||||
required String conTypeId,
|
||||
required String conType,
|
||||
required String langId,
|
||||
File? image,
|
||||
String? newsId,
|
||||
String? subCatId,
|
||||
String? showTill,
|
||||
String? tagId,
|
||||
String? url,
|
||||
String? desc,
|
||||
String? summDescription,
|
||||
String? locationId,
|
||||
File? videoUpload,
|
||||
List<File>? otherImage,
|
||||
String? publishDate,
|
||||
required String metaTitle,
|
||||
required String metaDescription,
|
||||
required String metaKeyword,
|
||||
required String slug,
|
||||
required int isDraft}) async {
|
||||
final result = await _addNewsRemoteDataSource.addNewsData(
|
||||
context: context,
|
||||
actionType: actionType,
|
||||
newsId: newsId,
|
||||
catId: catId,
|
||||
langId: langId,
|
||||
conType: conType,
|
||||
conTypeId: conTypeId,
|
||||
image: image,
|
||||
title: title,
|
||||
subCatId: subCatId,
|
||||
showTill: showTill,
|
||||
desc: desc,
|
||||
otherImage: otherImage,
|
||||
tagId: tagId,
|
||||
url: url,
|
||||
videoUpload: videoUpload,
|
||||
locationId: locationId,
|
||||
metaTitle: metaTitle,
|
||||
metaDescription: metaDescription,
|
||||
metaKeyword: metaKeyword,
|
||||
slug: slug,
|
||||
publishDate: publishDate ?? null,
|
||||
summDescription: summDescription,
|
||||
isDraft: isDraft);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class SystemRepository {
|
||||
Future<dynamic> fetchSettings() async {
|
||||
try {
|
||||
final result = await Api.sendApiRequest(url: Api.getSettingApi, body: null, isGet: true);
|
||||
return result[DATA];
|
||||
} catch (e) {
|
||||
throw ApiException(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
119
news-app/lib/data/repositories/Auth/authLocalDataSource.dart
Normal file
119
news-app/lib/data/repositories/Auth/authLocalDataSource.dart
Normal file
@@ -0,0 +1,119 @@
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:news/utils/constant.dart';
|
||||
import 'package:news/utils/hiveBoxKeys.dart';
|
||||
|
||||
//AuthLocalDataSource will communicate with local database (hive)
|
||||
class AuthLocalDataSource {
|
||||
bool? checkIsAuth() {
|
||||
return Hive.box(authBoxKey).get(isLogInKey, defaultValue: false) ?? false;
|
||||
}
|
||||
|
||||
String? getId() {
|
||||
return Hive.box(authBoxKey).get(userIdKey, defaultValue: "0");
|
||||
}
|
||||
|
||||
Future<void> setId(String? id) async {
|
||||
Hive.box(authBoxKey).put(userIdKey, id);
|
||||
}
|
||||
|
||||
String? getName() {
|
||||
return Hive.box(authBoxKey).get(userNameKey, defaultValue: "");
|
||||
}
|
||||
|
||||
Future<void> setName(String? name) async {
|
||||
Hive.box(authBoxKey).put(userNameKey, name);
|
||||
}
|
||||
|
||||
String? getEmail() {
|
||||
return Hive.box(authBoxKey).get(userEmailKey, defaultValue: "");
|
||||
}
|
||||
|
||||
Future<void> setEmail(String? email) async {
|
||||
Hive.box(authBoxKey).put(userEmailKey, email);
|
||||
}
|
||||
|
||||
String? getMobile() {
|
||||
return Hive.box(authBoxKey).get(userMobKey, defaultValue: "");
|
||||
}
|
||||
|
||||
Future<void> setMobile(String? mobile) async {
|
||||
Hive.box(authBoxKey).put(userMobKey, mobile);
|
||||
}
|
||||
|
||||
String? getType() {
|
||||
return Hive.box(authBoxKey).get(userTypeKey, defaultValue: "");
|
||||
}
|
||||
|
||||
Future<void> setType(String? type) async {
|
||||
Hive.box(authBoxKey).put(userTypeKey, type);
|
||||
}
|
||||
|
||||
String? getProfile() {
|
||||
return Hive.box(authBoxKey).get(userProfileKey, defaultValue: "");
|
||||
}
|
||||
|
||||
Future<void> setProfile(String? image) async {
|
||||
Hive.box(authBoxKey).put(userProfileKey, image);
|
||||
}
|
||||
|
||||
String? getStatus() {
|
||||
return Hive.box(authBoxKey).get(userStatusKey, defaultValue: "");
|
||||
}
|
||||
|
||||
Future<void> setStatus(String? status) async {
|
||||
Hive.box(authBoxKey).put(userStatusKey, status);
|
||||
}
|
||||
|
||||
String getJWTtoken() {
|
||||
return Hive.box(authBoxKey).get(jwtTokenKey, defaultValue: "");
|
||||
}
|
||||
|
||||
Future<void> setJWTtoken(String? jwtToken) async {
|
||||
Hive.box(authBoxKey).put(jwtTokenKey, jwtToken);
|
||||
}
|
||||
|
||||
Future<void> changeAuthStatus(bool? authStatus) async {
|
||||
Hive.box(authBoxKey).put(isLogInKey, authStatus);
|
||||
}
|
||||
|
||||
String? getAuthorWhatsappLink() {
|
||||
return Hive.box(authBoxKey).get(authorWhatsappLinkKey, defaultValue: "");
|
||||
}
|
||||
|
||||
String? getAuthorFacebookLink() {
|
||||
return Hive.box(authBoxKey).get(authorfacebookLinkKey, defaultValue: "");
|
||||
}
|
||||
|
||||
String? getAuthorTelegramLink() {
|
||||
return Hive.box(authBoxKey).get(authorTelegramLinkKey, defaultValue: "");
|
||||
}
|
||||
|
||||
String? getAuthorLinkedInLink() {
|
||||
return Hive.box(authBoxKey).get(authorLinkedInLinkKey, defaultValue: "");
|
||||
}
|
||||
|
||||
Future<void> setSocialMediaLinks(String? whatsappLink, facebookLink, telegramLink, linkedInLink) async {
|
||||
Hive.box(authBoxKey).put(authorWhatsappLinkKey, whatsappLink);
|
||||
Hive.box(authBoxKey).put(authorfacebookLinkKey, facebookLink);
|
||||
Hive.box(authBoxKey).put(authorTelegramLinkKey, telegramLink);
|
||||
Hive.box(authBoxKey).put(authorLinkedInLinkKey, linkedInLink);
|
||||
}
|
||||
|
||||
String getAuthorBio() {
|
||||
return Hive.box(authBoxKey).get(authorBioKey, defaultValue: "");
|
||||
}
|
||||
|
||||
Future<void> setAuthorBio(String? authorBio) async {
|
||||
Hive.box(authBoxKey).put(authorBioKey, authorBio);
|
||||
}
|
||||
|
||||
AuthorStatus getAuthorStatus() {
|
||||
final value = Hive.box(authBoxKey).get(authorStatusKey, defaultValue: AuthorStatus.rejected.name);
|
||||
|
||||
return AuthorStatus.values.byName(value);
|
||||
}
|
||||
|
||||
Future<void> setAuthorStatus(AuthorStatus authorStatus) async {
|
||||
Hive.box(authBoxKey).put(authorStatusKey, authorStatus.name);
|
||||
}
|
||||
}
|
||||
299
news-app/lib/data/repositories/Auth/authRemoteDataSource.dart
Normal file
299
news-app/lib/data/repositories/Auth/authRemoteDataSource.dart
Normal file
@@ -0,0 +1,299 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:flutter_login_facebook/flutter_login_facebook.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:google_sign_in/google_sign_in.dart';
|
||||
import 'package:news/cubits/appLocalizationCubit.dart';
|
||||
import 'package:news/data/repositories/Settings/settingsLocalDataRepository.dart';
|
||||
import 'package:sign_in_with_apple/sign_in_with_apple.dart';
|
||||
import 'package:news/cubits/Auth/authCubit.dart';
|
||||
import 'package:news/ui/widgets/SnackBarWidget.dart';
|
||||
import 'package:news/utils/uiUtils.dart';
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class AuthRemoteDataSource {
|
||||
final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
|
||||
final GoogleSignIn _googleSignIn = GoogleSignIn(scopes: ["profile", "email"]);
|
||||
final _facebookSignin = FacebookLogin();
|
||||
|
||||
Future<dynamic> loginAuth({
|
||||
required String firebaseId,
|
||||
required String name,
|
||||
required String email,
|
||||
required String type,
|
||||
required String profile,
|
||||
required String mobile,
|
||||
}) async {
|
||||
try {
|
||||
final Map<String, String> body = {FIREBASE_ID: firebaseId, NAME: name, TYPE: type, EMAIL: email};
|
||||
if (profile != "") body[PROFILE] = profile;
|
||||
if (mobile != "") body[MOBILE] = mobile;
|
||||
|
||||
var result = await Api.sendApiRequest(body: body, url: Api.getUserSignUpApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> deleteUserAcc() async {
|
||||
try {
|
||||
final result = await Api.sendApiRequest(body: {}, url: Api.userDeleteApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
//to update fcmId of user's
|
||||
Future<dynamic> updateUserData(
|
||||
{String? name, String? mobile, String? email, String? filePath, String? authorBio, String? whatsappLink, String? facebookLink, String? telegramLink, String? linkedInLink}) async {
|
||||
try {
|
||||
Map<String, dynamic> body = {};
|
||||
Map<String, dynamic> result = {};
|
||||
|
||||
if (name != null) body[NAME] = name;
|
||||
if (mobile != null) body[MOBILE] = mobile;
|
||||
if (email != null) body[EMAIL] = email;
|
||||
if (filePath != null && filePath.isNotEmpty) body[PROFILE] = await MultipartFile.fromFile(filePath);
|
||||
if (authorBio != null) body[AUTHOR_BIO] = authorBio;
|
||||
if (whatsappLink != null) body[AUTHOR_WHATSAPP_LINK] = whatsappLink;
|
||||
if (telegramLink != null) body[AUTHOR_TELEGRAM_LINK] = telegramLink;
|
||||
if (facebookLink != null) body[AUTHOR_FACEBOOK_LINK] = facebookLink;
|
||||
if (linkedInLink != null) body[AUTHOR_LINKEDIN_LINK] = linkedInLink;
|
||||
result = await Api.sendApiRequest(body: body, url: Api.setUpdateProfileApi);
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> registerToken({required String fcmId, required BuildContext context}) async {
|
||||
try {
|
||||
final body = {TOKEN: fcmId, LANGUAGE_ID: context.read<AppLocalizationCubit>().state.id}; //Pass languageId for specific language Notifications
|
||||
|
||||
String latitude = SettingsLocalDataRepository().getLocationCityValues().first;
|
||||
String longitude = SettingsLocalDataRepository().getLocationCityValues().last;
|
||||
|
||||
if (latitude != '' && latitude != "null") body[LATITUDE] = latitude;
|
||||
if (longitude != '' && longitude != "null") body[LONGITUDE] = longitude;
|
||||
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.setRegisterToken);
|
||||
return result;
|
||||
} on SocketException catch (e) {
|
||||
throw SocketException(e.toString());
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> socialSignInUser({required AuthProviders authProvider, required BuildContext context, String? email, String? password, String? otp, String? verifiedId}) async {
|
||||
Map<String, dynamic> result = {};
|
||||
|
||||
try {
|
||||
switch (authProvider) {
|
||||
case AuthProviders.gmail:
|
||||
UserCredential? userCredential = await signInWithGoogle(context);
|
||||
if (userCredential != null) {
|
||||
result['user'] = userCredential.user!;
|
||||
return result;
|
||||
} else {
|
||||
throw ApiMessageAndCodeException(errorMessage: UiUtils.getTranslatedLabel(context, 'somethingMSg'));
|
||||
}
|
||||
|
||||
case AuthProviders.mobile:
|
||||
UserCredential? userCredential = await signInWithPhone(context: context, otp: otp!, verifiedId: verifiedId!);
|
||||
if (userCredential != null) {
|
||||
result['user'] = userCredential.user!;
|
||||
return result;
|
||||
} else {
|
||||
throw ApiMessageAndCodeException(errorMessage: UiUtils.getTranslatedLabel(context, 'somethingMSg'));
|
||||
}
|
||||
case AuthProviders.fb:
|
||||
final faceBookAuthResult = await signInWithFacebook();
|
||||
if (faceBookAuthResult != null) {
|
||||
result['user'] = faceBookAuthResult.user!;
|
||||
return result;
|
||||
} else {
|
||||
throw ApiMessageAndCodeException(errorMessage: UiUtils.getTranslatedLabel(context, 'somethingMSg'));
|
||||
}
|
||||
case AuthProviders.apple:
|
||||
UserCredential? userCredential = await signInWithApple(context);
|
||||
if (userCredential != null) {
|
||||
result['user'] = userCredential.user!;
|
||||
return result;
|
||||
} else {
|
||||
throw ApiMessageAndCodeException(errorMessage: UiUtils.getTranslatedLabel(context, 'somethingMSg'));
|
||||
}
|
||||
case AuthProviders.email:
|
||||
final userCredential = await signInWithEmailPassword(email: email!, password: password!, context: context);
|
||||
if (userCredential != null) {
|
||||
result['user'] = userCredential.user!;
|
||||
return result;
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
} on SocketException catch (_) {
|
||||
throw ApiMessageAndCodeException(errorMessage: UiUtils.getTranslatedLabel(context, 'internetmsg'));
|
||||
} on FirebaseAuthException catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<UserCredential?> signInWithPhone({required BuildContext context, required String otp, required String verifiedId}) async {
|
||||
String code = otp.trim();
|
||||
|
||||
if (code.length == 6) {
|
||||
//As OTP is of Fixed length 6
|
||||
try {
|
||||
final PhoneAuthCredential credential = PhoneAuthProvider.credential(verificationId: verifiedId, smsCode: otp);
|
||||
final UserCredential authResult = await _firebaseAuth.signInWithCredential(credential);
|
||||
final User? user = authResult.user;
|
||||
if (user != null) {
|
||||
assert(!user.isAnonymous);
|
||||
|
||||
final User? currentUser = _firebaseAuth.currentUser;
|
||||
assert(user.uid == currentUser?.uid);
|
||||
showSnackBar(UiUtils.getTranslatedLabel(context, 'otpMsg'), context);
|
||||
return authResult;
|
||||
} else {
|
||||
showSnackBar(UiUtils.getTranslatedLabel(context, 'otpError'), context);
|
||||
return null;
|
||||
}
|
||||
} on FirebaseAuthException catch (authError) {
|
||||
if (authError.code == 'invalidVerificationCode') {
|
||||
showSnackBar(UiUtils.getTranslatedLabel(context, 'invalidVerificationCode'), context);
|
||||
return null;
|
||||
} else {
|
||||
showSnackBar(authError.message.toString(), context);
|
||||
return null;
|
||||
}
|
||||
} on FirebaseException catch (e) {
|
||||
showSnackBar(e.message.toString(), context);
|
||||
return null;
|
||||
} catch (e) {
|
||||
showSnackBar(e.toString(), context);
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
showSnackBar(UiUtils.getTranslatedLabel(context, 'enterOtpTxt'), context);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//sign in with email and password in firebase
|
||||
Future<UserCredential?> signInWithEmailPassword({required String email, required String password, required BuildContext context}) async {
|
||||
try {
|
||||
final UserCredential userCredential = await _firebaseAuth.signInWithEmailAndPassword(email: email, password: password);
|
||||
|
||||
return userCredential;
|
||||
} on FirebaseAuthException catch (authError) {
|
||||
if (authError.code == 'userNotFound') {
|
||||
showSnackBar(UiUtils.getTranslatedLabel(context, 'userNotFound'), context);
|
||||
} else if (authError.code == 'wrongPassword') {
|
||||
showSnackBar(UiUtils.getTranslatedLabel(context, 'wrongPassword'), context);
|
||||
} else {
|
||||
throw ApiMessageAndCodeException(errorMessage: authError.message!);
|
||||
}
|
||||
} on FirebaseException catch (e) {
|
||||
showSnackBar(e.toString(), context);
|
||||
} catch (e) {
|
||||
String errorMessage = e.toString();
|
||||
showSnackBar(errorMessage, context);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//signIn using google account
|
||||
Future<UserCredential?> signInWithGoogle(BuildContext context) async {
|
||||
final GoogleSignInAccount? googleUser = await _googleSignIn.signIn();
|
||||
if (googleUser == null) {
|
||||
ApiMessageAndCodeException(errorMessage: UiUtils.getTranslatedLabel(context, 'somethingMSg'));
|
||||
return null;
|
||||
}
|
||||
final GoogleSignInAuthentication googleAuth = await googleUser.authentication;
|
||||
|
||||
final AuthCredential credential = GoogleAuthProvider.credential(accessToken: googleAuth.accessToken, idToken: googleAuth.idToken);
|
||||
final UserCredential userCredential = await _firebaseAuth.signInWithCredential(credential);
|
||||
return userCredential;
|
||||
}
|
||||
|
||||
Future<UserCredential?> signInWithFacebook() async {
|
||||
final res = await _facebookSignin.logIn(permissions: [FacebookPermission.publicProfile, FacebookPermission.email]);
|
||||
|
||||
// Check result status
|
||||
switch (res.status) {
|
||||
case FacebookLoginStatus.success:
|
||||
// Send access token to server for validation and auth
|
||||
final FacebookAccessToken? accessToken = res.accessToken;
|
||||
AuthCredential authCredential = FacebookAuthProvider.credential(accessToken!.token);
|
||||
final UserCredential userCredential = await _firebaseAuth.signInWithCredential(authCredential);
|
||||
return userCredential;
|
||||
case FacebookLoginStatus.cancel:
|
||||
return null;
|
||||
|
||||
case FacebookLoginStatus.error:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
String sha256ofString(String input) {
|
||||
final bytes = utf8.encode(input);
|
||||
final digest = sha256.convert(bytes);
|
||||
return digest.toString();
|
||||
}
|
||||
|
||||
Future<UserCredential?> signInWithApple(BuildContext context) async {
|
||||
try {
|
||||
final rawNonce = generateNonce();
|
||||
final nonce = sha256ofString(rawNonce);
|
||||
|
||||
final appleCredential = await SignInWithApple.getAppleIDCredential(scopes: [AppleIDAuthorizationScopes.email, AppleIDAuthorizationScopes.fullName], nonce: nonce);
|
||||
|
||||
final oauthCredential = OAuthProvider("apple.com").credential(idToken: appleCredential.identityToken, rawNonce: rawNonce, accessToken: appleCredential.authorizationCode);
|
||||
|
||||
final UserCredential authResult = await FirebaseAuth.instance.signInWithCredential(oauthCredential);
|
||||
|
||||
return authResult;
|
||||
} on FirebaseAuthException catch (authError) {
|
||||
showSnackBar(authError.message!, context);
|
||||
return null;
|
||||
} on FirebaseException catch (e) {
|
||||
showSnackBar(e.toString(), context);
|
||||
return null;
|
||||
} catch (e) {
|
||||
String errorMessage = e.toString();
|
||||
|
||||
if (errorMessage == "Null check operator used on a null value") {
|
||||
//if user goes back from selecting Account
|
||||
//in case of User gmail not selected & back to Login screen
|
||||
showSnackBar(UiUtils.getTranslatedLabel(context, 'cancelLogin'), context);
|
||||
return null;
|
||||
} else {
|
||||
showSnackBar(errorMessage, context);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> signOut(AuthProviders? authProvider) async {
|
||||
_firebaseAuth.signOut();
|
||||
if (authProvider == AuthProviders.gmail) {
|
||||
_googleSignIn.signOut();
|
||||
} else if (authProvider == AuthProviders.fb) {
|
||||
_facebookSignin.logOut();
|
||||
} else {
|
||||
_firebaseAuth.signOut();
|
||||
}
|
||||
}
|
||||
}
|
||||
171
news-app/lib/data/repositories/Auth/authRepository.dart
Normal file
171
news-app/lib/data/repositories/Auth/authRepository.dart
Normal file
@@ -0,0 +1,171 @@
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:news/data/models/authorModel.dart';
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/constant.dart';
|
||||
import 'package:news/utils/hiveBoxKeys.dart';
|
||||
import 'package:news/utils/uiUtils.dart';
|
||||
import 'package:news/cubits/Auth/authCubit.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
import 'package:news/data/repositories/Auth/authLocalDataSource.dart';
|
||||
import 'package:news/data/repositories/Auth/authRemoteDataSource.dart';
|
||||
|
||||
class AuthRepository {
|
||||
static final AuthRepository _authRepository = AuthRepository._internal();
|
||||
late AuthLocalDataSource _authLocalDataSource;
|
||||
late AuthRemoteDataSource _authRemoteDataSource;
|
||||
|
||||
factory AuthRepository() {
|
||||
_authRepository._authLocalDataSource = AuthLocalDataSource();
|
||||
_authRepository._authRemoteDataSource = AuthRemoteDataSource();
|
||||
return _authRepository;
|
||||
}
|
||||
|
||||
AuthRepository._internal();
|
||||
|
||||
AuthLocalDataSource get authLocalDataSource => _authLocalDataSource;
|
||||
|
||||
//to get auth detials stored in hive box
|
||||
getLocalAuthDetails() {
|
||||
return {
|
||||
"isLogIn": _authLocalDataSource.checkIsAuth(),
|
||||
ID: _authLocalDataSource.getId(),
|
||||
NAME: _authLocalDataSource.getName(),
|
||||
EMAIL: _authLocalDataSource.getEmail(),
|
||||
MOBILE: _authLocalDataSource.getMobile(),
|
||||
TYPE: _authLocalDataSource.getType(),
|
||||
PROFILE: _authLocalDataSource.getProfile(),
|
||||
STATUS: _authLocalDataSource.getStatus(),
|
||||
TOKEN: _authLocalDataSource.getJWTtoken(),
|
||||
AUTHOR_BIO: _authLocalDataSource.getAuthorBio(),
|
||||
AUTHOR_STATUS: _authLocalDataSource.getAuthorStatus().name,
|
||||
AUTHOR_WHATSAPP_LINK: _authLocalDataSource.getAuthorWhatsappLink(),
|
||||
AUTHOR_FACEBOOK_LINK: _authLocalDataSource.getAuthorFacebookLink(),
|
||||
AUTHOR_TELEGRAM_LINK: _authLocalDataSource.getAuthorTelegramLink(),
|
||||
AUTHOR_LINKEDIN_LINK: _authLocalDataSource.getAuthorLinkedInLink()
|
||||
};
|
||||
}
|
||||
|
||||
setLocalAuthDetails(
|
||||
{required bool authStatus,
|
||||
required String id,
|
||||
required String name,
|
||||
required String email,
|
||||
required String mobile,
|
||||
required String type,
|
||||
required String profile,
|
||||
required String status,
|
||||
required String role,
|
||||
required String jwtToken,
|
||||
required int isAuthor,
|
||||
Author? authorDetails}) {
|
||||
_authLocalDataSource.changeAuthStatus(authStatus);
|
||||
_authLocalDataSource.setId(id);
|
||||
_authLocalDataSource.setName(name);
|
||||
_authLocalDataSource.setEmail(email);
|
||||
_authLocalDataSource.setMobile(mobile);
|
||||
_authLocalDataSource.setType(type);
|
||||
_authLocalDataSource.setProfile(profile);
|
||||
_authLocalDataSource.setStatus(status);
|
||||
_authLocalDataSource.setJWTtoken(jwtToken);
|
||||
_authLocalDataSource.setAuthorStatus((authorDetails != null) ? authorDetails.status! : AuthorStatus.rejected);
|
||||
_authLocalDataSource.setAuthorBio((authorDetails != null) ? authorDetails.bio : "");
|
||||
_authLocalDataSource.setSocialMediaLinks((authorDetails != null) ? authorDetails.whatsappLink : "", (authorDetails != null) ? authorDetails.facebookLink : "",
|
||||
(authorDetails != null) ? authorDetails.telegramLink : "", (authorDetails != null) ? authorDetails.linkedinLink : "");
|
||||
}
|
||||
|
||||
//First we signin user with given provider then add user details
|
||||
Future<Map<String, dynamic>> signInUser({required BuildContext context, required AuthProviders authProvider, String? email, String? password, String? otp, String? verifiedId}) async {
|
||||
try {
|
||||
final result = await _authRemoteDataSource.socialSignInUser(context: context, authProvider: authProvider, email: email, password: password, verifiedId: verifiedId, otp: otp);
|
||||
final user = result['user'] as User;
|
||||
var providerData = user.providerData[0];
|
||||
if (authProvider == AuthProviders.email && !user.emailVerified) {
|
||||
throw ApiException(UiUtils.getTranslatedLabel(context, 'verifyEmailMsg'));
|
||||
}
|
||||
|
||||
Map<String, dynamic> userDataTest = await _authRemoteDataSource.loginAuth(
|
||||
mobile: providerData.phoneNumber ?? "",
|
||||
email: providerData.email ?? "",
|
||||
firebaseId: user.uid,
|
||||
name: providerData.displayName ?? "",
|
||||
profile: providerData.photoURL ?? "",
|
||||
type: authProvider.name);
|
||||
if (!userDataTest[ERROR]) {
|
||||
if (userDataTest[DATA][STATUS].toString() != "0") {
|
||||
setLocalAuthDetails(
|
||||
type: userDataTest[DATA][TYPE] ?? "",
|
||||
profile: userDataTest[DATA][PROFILE] ?? "",
|
||||
name: userDataTest[DATA][NAME] ?? "",
|
||||
email: userDataTest[DATA][EMAIL] ?? "",
|
||||
authStatus: true,
|
||||
id: (userDataTest[DATA][ID].toString() != "") ? userDataTest[DATA][ID].toString() : "0",
|
||||
mobile: userDataTest[DATA][MOBILE] ?? "",
|
||||
role: userDataTest[DATA][ROLE].toString(),
|
||||
status: userDataTest[DATA][STATUS].toString(),
|
||||
jwtToken: userDataTest[DATA][TOKEN] ?? "",
|
||||
isAuthor: userDataTest[DATA][IS_AUTHOR] ?? 0,
|
||||
authorDetails: (userDataTest[DATA][IS_AUTHOR] == 1 && userDataTest[DATA][AUTHOR] != null) ? Author.fromJson(userDataTest[DATA][AUTHOR]) : null);
|
||||
}
|
||||
return userDataTest;
|
||||
} else {
|
||||
signOut(authProvider);
|
||||
throw ApiMessageAndCodeException(errorMessage: userDataTest[MESSAGE]);
|
||||
}
|
||||
} catch (e) {
|
||||
signOut(authProvider);
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> updateUserData(
|
||||
{String? name, String? mobile, String? email, String? filePath, String? authorBio, String? whatsappLink, String? facebookLink, String? telegramLink, String? linkedInLink}) async {
|
||||
final result = await _authRemoteDataSource.updateUserData(
|
||||
email: email,
|
||||
name: name,
|
||||
mobile: mobile,
|
||||
filePath: filePath,
|
||||
authorBio: authorBio,
|
||||
whatsappLink: whatsappLink,
|
||||
facebookLink: facebookLink,
|
||||
telegramLink: telegramLink,
|
||||
linkedInLink: linkedInLink);
|
||||
if (name != null) _authLocalDataSource.setName(name);
|
||||
if (mobile != null) _authLocalDataSource.setMobile(mobile);
|
||||
if (email != null) _authLocalDataSource.setEmail(email);
|
||||
if (filePath != null && filePath.isNotEmpty) _authLocalDataSource.setProfile(result[PROFILE]);
|
||||
if (authorBio != null) _authLocalDataSource.setAuthorBio(authorBio);
|
||||
if (whatsappLink != null || facebookLink != null || telegramLink != null || linkedInLink != null) _authLocalDataSource.setSocialMediaLinks(whatsappLink, facebookLink, telegramLink, linkedInLink);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> registerToken({required String fcmId, required BuildContext context}) async {
|
||||
final result = await _authRemoteDataSource.registerToken(fcmId: fcmId, context: context);
|
||||
return result;
|
||||
}
|
||||
|
||||
//to delete my account
|
||||
Future<dynamic> deleteUser() async {
|
||||
final result = await _authRemoteDataSource.deleteUserAcc();
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<void> signOut(AuthProviders authProvider) async {
|
||||
_authRemoteDataSource.signOut(authProvider);
|
||||
await _authLocalDataSource.changeAuthStatus(false);
|
||||
await _authLocalDataSource.setId("0");
|
||||
await _authLocalDataSource.setName("");
|
||||
await _authLocalDataSource.setEmail("");
|
||||
await _authLocalDataSource.setMobile("");
|
||||
await _authLocalDataSource.setType("");
|
||||
await _authLocalDataSource.setProfile("");
|
||||
await _authLocalDataSource.setStatus("");
|
||||
await _authLocalDataSource.setJWTtoken("");
|
||||
await _authLocalDataSource.setAuthorBio("");
|
||||
await _authLocalDataSource.setAuthorStatus(AuthorStatus.rejected);
|
||||
await _authLocalDataSource.setSocialMediaLinks("", "", "", "");
|
||||
await Hive.box(authBoxKey).clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import 'package:news/utils/strings.dart';
|
||||
import 'package:news/utils/api.dart';
|
||||
|
||||
class BookmarkRemoteDataSource {
|
||||
Future<dynamic> getBookmark({required String langId, required String offset, required String perPage}) async {
|
||||
try {
|
||||
final body = {LANGUAGE_ID: langId, OFFSET: offset, LIMIT: perPage};
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.getBookmarkApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future addBookmark({required String newsId, required String status}) async {
|
||||
try {
|
||||
final body = {NEWS_ID: newsId, STATUS: status};
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.setBookmarkApi);
|
||||
return result[DATA];
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import 'package:news/data/models/NewsModel.dart';
|
||||
import 'package:news/data/repositories/Bookmark/bookmarkRemoteDataSource.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class BookmarkRepository {
|
||||
static final BookmarkRepository _bookmarkRepository = BookmarkRepository._internal();
|
||||
late BookmarkRemoteDataSource _bookmarkRemoteDataSource;
|
||||
|
||||
factory BookmarkRepository() {
|
||||
_bookmarkRepository._bookmarkRemoteDataSource = BookmarkRemoteDataSource();
|
||||
return _bookmarkRepository;
|
||||
}
|
||||
|
||||
BookmarkRepository._internal();
|
||||
|
||||
Future<Map<String, dynamic>> getBookmark({required String offset, required String limit, required String langId}) async {
|
||||
final result = await _bookmarkRemoteDataSource.getBookmark(perPage: limit, offset: offset, langId: langId);
|
||||
return (result[ERROR])
|
||||
? {ERROR: result[ERROR], MESSAGE: result[MESSAGE]}
|
||||
: {ERROR: result[ERROR], "total": result[TOTAL], "Bookmark": (result[DATA] as List).map((e) => NewsModel.fromJson(e)).toList()};
|
||||
}
|
||||
|
||||
Future setBookmark({required String newsId, required String status}) async {
|
||||
final result = await _bookmarkRemoteDataSource.addBookmark(status: status, newsId: newsId);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class BreakingNewsRemoteDataSource {
|
||||
Future<dynamic> getBreakingNews({required String langId}) async {
|
||||
try {
|
||||
final body = {LANGUAGE_ID: langId};
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.getBreakingNewsApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:news/data/models/BreakingNewsModel.dart';
|
||||
import 'package:news/data/repositories/BreakingNews/breakNewsRemoteDataSource.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class BreakingNewsRepository {
|
||||
static final BreakingNewsRepository _breakingNewsRepository = BreakingNewsRepository._internal();
|
||||
|
||||
late BreakingNewsRemoteDataSource _breakingNewsRemoteDataSource;
|
||||
|
||||
factory BreakingNewsRepository() {
|
||||
_breakingNewsRepository._breakingNewsRemoteDataSource = BreakingNewsRemoteDataSource();
|
||||
return _breakingNewsRepository;
|
||||
}
|
||||
|
||||
BreakingNewsRepository._internal();
|
||||
|
||||
Future<dynamic> getBreakingNews({required String langId}) async {
|
||||
final result = await _breakingNewsRemoteDataSource.getBreakingNews(langId: langId);
|
||||
|
||||
return (result[ERROR]) ? {ERROR: result[ERROR], MESSAGE: result[MESSAGE]} : {ERROR: result[ERROR], "BreakingNews": (result[DATA] as List).map((e) => BreakingNewsModel.fromJson(e)).toList()};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class CategoryRemoteDataSource {
|
||||
Future<dynamic> getCategory({required String limit, required String offset, required String langId}) async {
|
||||
try {
|
||||
final body = {LIMIT: limit, OFFSET: offset, LANGUAGE_ID: langId};
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.getCatApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import 'package:news/data/models/CategoryModel.dart';
|
||||
import 'package:news/data/repositories/Category/categoryRemoteDataSource.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class CategoryRepository {
|
||||
static final CategoryRepository _notificationRepository = CategoryRepository._internal();
|
||||
|
||||
late CategoryRemoteDataSource _notificationRemoteDataSource;
|
||||
|
||||
factory CategoryRepository() {
|
||||
_notificationRepository._notificationRemoteDataSource = CategoryRemoteDataSource();
|
||||
return _notificationRepository;
|
||||
}
|
||||
|
||||
CategoryRepository._internal();
|
||||
|
||||
Future<Map<String, dynamic>> getCategory({required String offset, required String limit, required String langId}) async {
|
||||
final result = await _notificationRemoteDataSource.getCategory(limit: limit, offset: offset, langId: langId);
|
||||
|
||||
return (result[ERROR])
|
||||
? {ERROR: result[ERROR], MESSAGE: result[MESSAGE]}
|
||||
: {ERROR: result[ERROR], "total": result[TOTAL], "Category": (result[DATA] as List).map((e) => CategoryModel.fromJson(e)).toList()};
|
||||
}
|
||||
}
|
||||
@@ -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};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import '../../../utils/api.dart';
|
||||
import '../../../utils/strings.dart';
|
||||
|
||||
class DeleteImageRemoteDataSource {
|
||||
Future deleteImage({required String imageId}) async {
|
||||
try {
|
||||
final body = {
|
||||
ID: imageId,
|
||||
};
|
||||
final result = await Api.sendApiRequest(
|
||||
body: body,
|
||||
url: Api.setDeleteImageApi,
|
||||
);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import 'deleteImageIdRemoteDataSource.dart';
|
||||
|
||||
class DeleteImageRepository {
|
||||
static final DeleteImageRepository _deleteImageRepository = DeleteImageRepository._internal();
|
||||
late DeleteImageRemoteDataSource _deleteImageRemoteDataSource;
|
||||
|
||||
factory DeleteImageRepository() {
|
||||
_deleteImageRepository._deleteImageRemoteDataSource = DeleteImageRemoteDataSource();
|
||||
return _deleteImageRepository;
|
||||
}
|
||||
|
||||
DeleteImageRepository._internal();
|
||||
|
||||
Future setDeleteImage({
|
||||
required String imageId,
|
||||
}) async {
|
||||
final result = await _deleteImageRemoteDataSource.deleteImage(imageId: imageId);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class DeleteUserNewsRemoteDataSource {
|
||||
Future deleteUserNews({required String newsId}) async {
|
||||
try {
|
||||
final body = {
|
||||
ID: newsId,
|
||||
};
|
||||
final result = await Api.sendApiRequest(
|
||||
body: body,
|
||||
url: Api.setDeleteNewsApi,
|
||||
);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import 'deleteUserNewsRemoteDataSource.dart';
|
||||
|
||||
class DeleteUserNewsRepository {
|
||||
static final DeleteUserNewsRepository _deleteUserNewsRepository = DeleteUserNewsRepository._internal();
|
||||
late DeleteUserNewsRemoteDataSource _deleteUserNewsRemoteDataSource;
|
||||
|
||||
factory DeleteUserNewsRepository() {
|
||||
_deleteUserNewsRepository._deleteUserNewsRemoteDataSource = DeleteUserNewsRemoteDataSource();
|
||||
return _deleteUserNewsRepository;
|
||||
}
|
||||
|
||||
DeleteUserNewsRepository._internal();
|
||||
|
||||
Future setDeleteUserNews({
|
||||
required String newsId,
|
||||
}) async {
|
||||
final result = await _deleteUserNewsRemoteDataSource.deleteUserNews(newsId: newsId);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class DeleteUserNotiRemoteDataSource {
|
||||
Future deleteUserNotification({required String id}) async {
|
||||
try {
|
||||
final body = {ID: id};
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.deleteUserNotiApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:news/data/repositories/DeleteUserNotification/deleteUserNotiRemoteDataSource.dart';
|
||||
|
||||
class DeleteUserNotiRepository {
|
||||
static final DeleteUserNotiRepository _deleteUserNotiRepository = DeleteUserNotiRepository._internal();
|
||||
late DeleteUserNotiRemoteDataSource _deleteUserNotiRemoteDataSource;
|
||||
|
||||
factory DeleteUserNotiRepository() {
|
||||
_deleteUserNotiRepository._deleteUserNotiRemoteDataSource = DeleteUserNotiRemoteDataSource();
|
||||
return _deleteUserNotiRepository;
|
||||
}
|
||||
|
||||
DeleteUserNotiRepository._internal();
|
||||
|
||||
Future deleteUserNotification({required String id}) async {
|
||||
final result = await _deleteUserNotiRemoteDataSource.deleteUserNotification(id: id);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/constant.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class SectionRemoteDataSource {
|
||||
Future<dynamic> getSections({required String langId, String? latitude, String? longitude, String? limit, String? offset, String? sectionOffset}) async {
|
||||
try {
|
||||
final body = {LANGUAGE_ID: langId, LIMIT: limit, OFFSET: offset, SECTION_LIMIT: limitOfSectionsData, SECTION_OFFSET: sectionOffset};
|
||||
|
||||
if (latitude != null && latitude != "null") body[LATITUDE] = latitude;
|
||||
if (longitude != null && longitude != "null") body[LONGITUDE] = longitude;
|
||||
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.getFeatureSectionApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import 'package:news/data/models/FeatureSectionModel.dart';
|
||||
import 'package:news/data/repositories/FeatureSection/sectionRemoteDataSource.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class SectionRepository {
|
||||
static final SectionRepository _sectionRepository = SectionRepository._internal();
|
||||
|
||||
late SectionRemoteDataSource _sectionRemoteDataSource;
|
||||
|
||||
factory SectionRepository() {
|
||||
_sectionRepository._sectionRemoteDataSource = SectionRemoteDataSource();
|
||||
return _sectionRepository;
|
||||
}
|
||||
|
||||
SectionRepository._internal();
|
||||
|
||||
Future<Map<String, dynamic>> getSection({required String langId, String? latitude, String? longitude, String? limit, String? offset, String? sectionOffset}) async {
|
||||
final result = await _sectionRemoteDataSource.getSections(langId: langId, latitude: latitude, longitude: longitude, limit: limit, offset: offset, sectionOffset: sectionOffset);
|
||||
|
||||
return (result[ERROR])
|
||||
? {ERROR: result[ERROR], MESSAGE: result[MESSAGE]}
|
||||
: {ERROR: result[ERROR], "Section": (result[DATA] as List).map((e) => FeatureSectionModel.fromJson(e)).toList(), TOTAL: result[TOTAL]};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:news/utils/strings.dart';
|
||||
import 'package:news/utils/api.dart';
|
||||
|
||||
class GetSurveyAnsRemoteDataSource {
|
||||
Future<dynamic> getSurveyAns({required String langId}) async {
|
||||
try {
|
||||
final body = {LANGUAGE_ID: langId};
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.getQueResultApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import 'package:news/data/models/NewsModel.dart';
|
||||
import 'package:news/data/repositories/GetSurveyAnswer/getSurveyAnsRemoteDataSource.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class GetSurveyAnsRepository {
|
||||
static final GetSurveyAnsRepository _getSurveyAnsRepository = GetSurveyAnsRepository._internal();
|
||||
|
||||
late GetSurveyAnsRemoteDataSource _getSurveyAnsRemoteDataSource;
|
||||
|
||||
factory GetSurveyAnsRepository() {
|
||||
_getSurveyAnsRepository._getSurveyAnsRemoteDataSource = GetSurveyAnsRemoteDataSource();
|
||||
return _getSurveyAnsRepository;
|
||||
}
|
||||
|
||||
GetSurveyAnsRepository._internal();
|
||||
Future<Map<String, dynamic>> getSurveyAns({required String langId}) async {
|
||||
final result = await _getSurveyAnsRemoteDataSource.getSurveyAns(langId: langId);
|
||||
return {"GetSurveyAns": (result[DATA] as List).map((e) => NewsModel.fromSurvey(e)).toList()};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
|
||||
class GetUserByIdRemoteDataSource {
|
||||
Future<dynamic> getUserById() async {
|
||||
try {
|
||||
final result = await Api.sendApiRequest(body: {}, url: Api.getUserByIdApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import 'package:news/data/repositories/GetUserById/getUserByIdDataSource.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class GetUserByIdRepository {
|
||||
static final GetUserByIdRepository _getUserByIdRepository = GetUserByIdRepository._internal();
|
||||
|
||||
late GetUserByIdRemoteDataSource _getUserByIdRemoteDataSource;
|
||||
|
||||
factory GetUserByIdRepository() {
|
||||
_getUserByIdRepository._getUserByIdRemoteDataSource = GetUserByIdRemoteDataSource();
|
||||
return _getUserByIdRepository;
|
||||
}
|
||||
|
||||
GetUserByIdRepository._internal();
|
||||
|
||||
Future<Map<String, dynamic>> getUserById() async {
|
||||
final result = await _getUserByIdRemoteDataSource.getUserById();
|
||||
return result[DATA];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class GetUserNewsRemoteDataSource {
|
||||
Future<dynamic> getGetUserNews({required String limit, required String offset, String? latitude, String? longitude}) async {
|
||||
try {
|
||||
final body = {LIMIT: limit, OFFSET: offset, USER_NEWS: 1};
|
||||
if (latitude != null && latitude != "null") body[LATITUDE] = latitude;
|
||||
if (longitude != null && longitude != "null") body[LONGITUDE] = longitude;
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.getNewsApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import 'package:news/data/models/NewsModel.dart';
|
||||
import 'package:news/data/repositories/GetUserNews/getUserNewsRemoteDataSource.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class GetUserNewsRepository {
|
||||
static final GetUserNewsRepository _getUserNewsRepository = GetUserNewsRepository._internal();
|
||||
|
||||
late GetUserNewsRemoteDataSource _getUserNewsRemoteDataSource;
|
||||
|
||||
factory GetUserNewsRepository() {
|
||||
_getUserNewsRepository._getUserNewsRemoteDataSource = GetUserNewsRemoteDataSource();
|
||||
return _getUserNewsRepository;
|
||||
}
|
||||
|
||||
GetUserNewsRepository._internal();
|
||||
|
||||
Future<dynamic> getGetUserNews({required String offset, required String limit, String? latitude, String? longitude}) async {
|
||||
final result = await _getUserNewsRemoteDataSource.getGetUserNews(limit: limit, offset: offset, latitude: latitude, longitude: longitude);
|
||||
|
||||
return (result[ERROR])
|
||||
? {ERROR: result[ERROR], MESSAGE: result[MESSAGE]}
|
||||
: {ERROR: result[ERROR], "total": result[TOTAL], "GetUserNews": (result[DATA] as List).map((e) => NewsModel.fromJson(e)).toList()};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class LanguageJsonRemoteDataSource {
|
||||
Future<dynamic> getLanguageJson({required String lanCode}) async {
|
||||
try {
|
||||
final body = {CODE: lanCode};
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.getLangJsonDataApi);
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/hiveBoxKeys.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
import 'languageJsonRemoteDataRepo.dart';
|
||||
|
||||
class LanguageJsonRepository {
|
||||
static final LanguageJsonRepository _languageRepository = LanguageJsonRepository._internal();
|
||||
|
||||
late LanguageJsonRemoteDataSource _languageRemoteDataSource;
|
||||
|
||||
factory LanguageJsonRepository() {
|
||||
_languageRepository._languageRemoteDataSource = LanguageJsonRemoteDataSource();
|
||||
return _languageRepository;
|
||||
}
|
||||
|
||||
LanguageJsonRepository._internal();
|
||||
|
||||
Future<dynamic> getLanguageJson({required String lanCode}) async {
|
||||
try {
|
||||
final result = await _languageRemoteDataSource.getLanguageJson(lanCode: lanCode);
|
||||
return result[DATA];
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<Map<dynamic, dynamic>> fetchLanguageLabels(String langCode) async {
|
||||
try {
|
||||
Map<dynamic, dynamic> languageLabelsJson = {};
|
||||
await getLanguageJson(lanCode: langCode).then((value) async {
|
||||
languageLabelsJson = value as Map<dynamic, dynamic>;
|
||||
await Hive.box(settingsBoxKey).put(langCode, languageLabelsJson);
|
||||
});
|
||||
return languageLabelsJson;
|
||||
} catch (e) {
|
||||
throw ApiException(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import 'package:news/utils/strings.dart';
|
||||
import 'package:news/utils/api.dart';
|
||||
|
||||
class LikeAndDisLikeRemoteDataSource {
|
||||
Future<dynamic> getLike({required String langId, required String offset, required String perPage}) async {
|
||||
try {
|
||||
final body = {LANGUAGE_ID: langId, OFFSET: offset, LIMIT: perPage};
|
||||
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.getLikeNewsApi);
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future addAndRemoveLike({required String newsId, required String status}) async {
|
||||
try {
|
||||
final body = {NEWS_ID: newsId, STATUS: status};
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.setLikesDislikesApi);
|
||||
return result[DATA];
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import 'package:news/data/models/NewsModel.dart';
|
||||
import 'package:news/data/repositories/LikeAndDisLikeNews/LikeAndDisLikeNewsDataSource.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class LikeAndDisLikeRepository {
|
||||
static final LikeAndDisLikeRepository _LikeAndDisLikeRepository = LikeAndDisLikeRepository._internal();
|
||||
late LikeAndDisLikeRemoteDataSource _LikeAndDisLikeRemoteDataSource;
|
||||
|
||||
factory LikeAndDisLikeRepository() {
|
||||
_LikeAndDisLikeRepository._LikeAndDisLikeRemoteDataSource = LikeAndDisLikeRemoteDataSource();
|
||||
return _LikeAndDisLikeRepository;
|
||||
}
|
||||
|
||||
LikeAndDisLikeRepository._internal();
|
||||
|
||||
Future<Map<String, dynamic>> getLike({required String offset, required String limit, required String langId}) async {
|
||||
final result = await _LikeAndDisLikeRemoteDataSource.getLike(perPage: limit, offset: offset, langId: langId);
|
||||
|
||||
return {"total": result[TOTAL], "LikeAndDisLike": (result[DATA] as List).map((e) => NewsModel.fromJson(e)).toList()};
|
||||
}
|
||||
|
||||
Future setLike({required String newsId, required String status}) async {
|
||||
final result = await _LikeAndDisLikeRemoteDataSource.addAndRemoveLike(status: status, newsId: newsId);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class LiveStreamRemoteDataSource {
|
||||
Future<dynamic> getLiveStreams({required String langId}) async {
|
||||
try {
|
||||
final body = {LANGUAGE_ID: langId};
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.getLiveStreamingApi);
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:news/data/models/LiveStreamingModel.dart';
|
||||
import 'package:news/data/repositories/LiveStream/liveRemoteDataSource.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class LiveStreamRepository {
|
||||
static final LiveStreamRepository _liveStreamRepository = LiveStreamRepository._internal();
|
||||
|
||||
late LiveStreamRemoteDataSource _liveStreamRemoteDataSource;
|
||||
|
||||
factory LiveStreamRepository() {
|
||||
_liveStreamRepository._liveStreamRemoteDataSource = LiveStreamRemoteDataSource();
|
||||
return _liveStreamRepository;
|
||||
}
|
||||
|
||||
LiveStreamRepository._internal();
|
||||
|
||||
Future<dynamic> getLiveStream({required String langId}) async {
|
||||
final result = await _liveStreamRemoteDataSource.getLiveStreams(langId: langId);
|
||||
|
||||
return (result[ERROR]) ? {ERROR: result[ERROR], MESSAGE: result[MESSAGE]} : {ERROR: result[ERROR], "LiveStream": (result[DATA] as List).map((e) => LiveStreamingModel.fromJson(e)).toList()};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class NewsByIdRemoteDataSource {
|
||||
Future<dynamic> getNewsById({required String newsId, required String langId}) async {
|
||||
try {
|
||||
final body = {LANGUAGE_ID: langId, ID: newsId};
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.getNewsApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:news/data/models/NewsModel.dart';
|
||||
import 'package:news/data/repositories/NewsById/NewsByIdRemoteDataSource.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class NewsByIdRepository {
|
||||
static final NewsByIdRepository _newsByIdRepository = NewsByIdRepository._internal();
|
||||
|
||||
late NewsByIdRemoteDataSource _newsByIdRemoteDataSource;
|
||||
|
||||
factory NewsByIdRepository() {
|
||||
_newsByIdRepository._newsByIdRemoteDataSource = NewsByIdRemoteDataSource();
|
||||
return _newsByIdRepository;
|
||||
}
|
||||
|
||||
NewsByIdRepository._internal();
|
||||
|
||||
Future<Map<String, dynamic>> getNewsById({required String newsId, required String langId}) async {
|
||||
final result = await _newsByIdRemoteDataSource.getNewsById(newsId: newsId, langId: langId);
|
||||
|
||||
return {"NewsById": (result[DATA] as List).map((e) => NewsModel.fromJson(e)).toList()};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class DeleteCommRemoteDataSource {
|
||||
Future deleteComm({required String commId}) async {
|
||||
try {
|
||||
final body = {COMMENT_ID: commId};
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.setCommentDeleteApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:news/data/repositories/NewsComment/DeleteComment/deleteCommDataSource.dart';
|
||||
|
||||
class DeleteCommRepository {
|
||||
static final DeleteCommRepository _deleteCommRepository = DeleteCommRepository._internal();
|
||||
late DeleteCommRemoteDataSource _deleteCommRemoteDataSource;
|
||||
|
||||
factory DeleteCommRepository() {
|
||||
_deleteCommRepository._deleteCommRemoteDataSource = DeleteCommRemoteDataSource();
|
||||
return _deleteCommRepository;
|
||||
}
|
||||
|
||||
DeleteCommRepository._internal();
|
||||
|
||||
Future setDeleteComm({required String commId}) async {
|
||||
final result = await _deleteCommRemoteDataSource.deleteComm(commId: commId);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class SetFlagRemoteDataSource {
|
||||
Future<dynamic> setFlag({required String commId, required String newsId, required String message}) async {
|
||||
try {
|
||||
final body = {COMMENT_ID: commId, NEWS_ID: newsId, MESSAGE: message};
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.setFlagApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'package:news/data/repositories/NewsComment/FlagComment/flagCommRemoteDataSource.dart';
|
||||
|
||||
class SetFlagRepository {
|
||||
static final SetFlagRepository _setFlagRepository = SetFlagRepository._internal();
|
||||
|
||||
late SetFlagRemoteDataSource _setFlagRemoteDataSource;
|
||||
|
||||
factory SetFlagRepository() {
|
||||
_setFlagRepository._setFlagRemoteDataSource = SetFlagRemoteDataSource();
|
||||
return _setFlagRepository;
|
||||
}
|
||||
|
||||
SetFlagRepository._internal();
|
||||
|
||||
Future<Map<String, dynamic>> setFlag({required String commId, required String newsId, required String message}) async {
|
||||
final result = await _setFlagRemoteDataSource.setFlag(commId: commId, newsId: newsId, message: message);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class LikeAndDislikeCommRemoteDataSource {
|
||||
Future likeAndDislikeComm({required String langId, required String commId, required String status}) async {
|
||||
try {
|
||||
final body = {LANGUAGE_ID: langId, COMMENT_ID: commId, STATUS: status};
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.setLikeDislikeComApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import 'package:news/data/models/CommentModel.dart';
|
||||
import 'package:news/data/repositories/NewsComment/LikeAndDislikeComment/likeAndDislikeCommDataSource.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class LikeAndDislikeCommRepository {
|
||||
static final LikeAndDislikeCommRepository _likeAndDislikeCommRepository = LikeAndDislikeCommRepository._internal();
|
||||
late LikeAndDislikeCommRemoteDataSource _likeAndDislikeCommRemoteDataSource;
|
||||
|
||||
factory LikeAndDislikeCommRepository() {
|
||||
_likeAndDislikeCommRepository._likeAndDislikeCommRemoteDataSource = LikeAndDislikeCommRemoteDataSource();
|
||||
return _likeAndDislikeCommRepository;
|
||||
}
|
||||
|
||||
LikeAndDislikeCommRepository._internal();
|
||||
|
||||
Future<Map<String, dynamic>> setLikeAndDislikeComm({required String langId, required String commId, required String status}) async {
|
||||
final result = await _likeAndDislikeCommRemoteDataSource.likeAndDislikeComm(langId: langId, commId: commId, status: status);
|
||||
|
||||
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();
|
||||
CommentModel? updatedComment;
|
||||
|
||||
commentsList.forEach((element) {
|
||||
if (element.id! == commId) {
|
||||
updatedComment = element;
|
||||
} else if (element.replyComList!.any((sublist) => sublist.id == commId) == true) {
|
||||
updatedComment = element;
|
||||
}
|
||||
});
|
||||
return {ERROR: result[ERROR], "total": result[TOTAL], "updatedComment": updatedComment ?? CommentModel.fromJson({})};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class SetCommentRemoteDataSource {
|
||||
Future<dynamic> setComment({required String parentId, required String newsId, required String message}) async {
|
||||
try {
|
||||
final body = {PARENT_ID: parentId, NEWS_ID: newsId, MESSAGE: message};
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.setCommentApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'package:news/data/repositories/NewsComment/SetComment/setComRemoteDataSource.dart';
|
||||
import 'package:news/data/models/CommentModel.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class SetCommentRepository {
|
||||
static final SetCommentRepository _setCommentRepository = SetCommentRepository._internal();
|
||||
|
||||
late SetCommentRemoteDataSource _setCommentRemoteDataSource;
|
||||
|
||||
factory SetCommentRepository() {
|
||||
_setCommentRepository._setCommentRemoteDataSource = SetCommentRemoteDataSource();
|
||||
return _setCommentRepository;
|
||||
}
|
||||
SetCommentRepository._internal();
|
||||
Future<Map<String, dynamic>> setComment({required String parentId, required String newsId, required String message}) async {
|
||||
final result = await _setCommentRemoteDataSource.setComment(parentId: parentId, newsId: newsId, message: message);
|
||||
return {"SetComment": (result[DATA] as List).map((e) => CommentModel.fromJson(e)).toList(), "total": result[TOTAL]};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class OtherPageRemoteDataSource {
|
||||
Future<dynamic> getOtherPages({required String langId}) async {
|
||||
try {
|
||||
final body = {LANGUAGE_ID: langId};
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.getPagesApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
import 'package:news/data/models/OtherPageModel.dart';
|
||||
import 'package:news/data/repositories/OtherPages/otherPageRemoteDataSorce.dart';
|
||||
|
||||
class OtherPageRepository {
|
||||
static final OtherPageRepository _otherPageRepository = OtherPageRepository._internal();
|
||||
|
||||
late OtherPageRemoteDataSource _otherPageRemoteDataSource;
|
||||
|
||||
factory OtherPageRepository() {
|
||||
_otherPageRepository._otherPageRemoteDataSource = OtherPageRemoteDataSource();
|
||||
return _otherPageRepository;
|
||||
}
|
||||
|
||||
OtherPageRepository._internal();
|
||||
|
||||
Future<Map<String, dynamic>> getOtherPage({required String langId}) async {
|
||||
final result = await _otherPageRemoteDataSource.getOtherPages(langId: langId);
|
||||
|
||||
return {"OtherPage": (result[DATA] as List).map((e) => OtherPageModel.fromJson(e)).toList()};
|
||||
}
|
||||
|
||||
//get only privacy policy & Terms Conditions
|
||||
Future<Map<String, dynamic>> getPrivacyTermsPage({required String langId}) async {
|
||||
try {
|
||||
final body = {LANGUAGE_ID: langId};
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.getPolicyPagesApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class RelatedNewsRemoteDataSource {
|
||||
Future<dynamic> getRelatedNews({required String langId, String? catId, String? subCatId, String? latitude, String? longitude, required String offset, required String perPage}) async {
|
||||
try {
|
||||
final body = {LANGUAGE_ID: langId, OFFSET: offset, LIMIT: perPage, MERGE_TAG: 1}; //merge_tag used to get related news according to tagId along with cat or Subcat Id
|
||||
(subCatId != "0" && subCatId != '') ? body[SUBCAT_ID] = subCatId! : body[CATEGORY_ID] = catId!;
|
||||
if (latitude != null && latitude != "null") body[LATITUDE] = latitude;
|
||||
if (longitude != null && longitude != "null") body[LONGITUDE] = longitude;
|
||||
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.getNewsApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:news/data/repositories/RelatedNews/relatedNewsDataSource.dart';
|
||||
import 'package:news/data/models/NewsModel.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class RelatedNewsRepository {
|
||||
static final RelatedNewsRepository _relatedNewsRepository = RelatedNewsRepository._internal();
|
||||
|
||||
late RelatedNewsRemoteDataSource _relatedNewsRemoteDataSource;
|
||||
|
||||
factory RelatedNewsRepository() {
|
||||
_relatedNewsRepository._relatedNewsRemoteDataSource = RelatedNewsRemoteDataSource();
|
||||
return _relatedNewsRepository;
|
||||
}
|
||||
|
||||
RelatedNewsRepository._internal();
|
||||
|
||||
Future<Map<String, dynamic>> getRelatedNews({required String langId, required String offset, required String perPage, String? catId, String? subCatId, String? latitude, String? longitude}) async {
|
||||
final result = await _relatedNewsRemoteDataSource.getRelatedNews(langId: langId, catId: catId, subCatId: subCatId, latitude: latitude, longitude: longitude, offset: offset, perPage: perPage);
|
||||
|
||||
return {"RelatedNews": (result[DATA] as List).map((e) => NewsModel.fromJson(e)).toList(), "total": result[TOTAL]};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class SectionByIdRemoteDataSource {
|
||||
Future<dynamic> getSectionById({required String langId, required String limit, required String offset, required String sectionId, String? latitude, String? longitude}) async {
|
||||
try {
|
||||
final body = {LANGUAGE_ID: langId, SECTION_ID: sectionId};
|
||||
if (latitude != null && latitude != "null") body[LATITUDE] = latitude;
|
||||
if (longitude != null && longitude != "null") body[LONGITUDE] = longitude;
|
||||
|
||||
if (sectionId.isNotEmpty) {
|
||||
body[SECTION_ID] = sectionId;
|
||||
}
|
||||
body[LIMIT] = limit;
|
||||
body[OFFSET] = offset;
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.getFeatureSectionApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import 'package:news/data/models/FeatureSectionModel.dart';
|
||||
import 'package:news/data/repositories/SectionById/sectionByIdRemoteDataSource.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class SectionByIdRepository {
|
||||
static final SectionByIdRepository _sectionByIdRepository = SectionByIdRepository._internal();
|
||||
|
||||
late SectionByIdRemoteDataSource _sectionByIdRemoteDataSource;
|
||||
|
||||
factory SectionByIdRepository() {
|
||||
_sectionByIdRepository._sectionByIdRemoteDataSource = SectionByIdRemoteDataSource();
|
||||
return _sectionByIdRepository;
|
||||
}
|
||||
|
||||
SectionByIdRepository._internal();
|
||||
Future<Map<String, dynamic>> getSectionById({required String langId, required String sectionId, required String limit, required String offset, String? latitude, String? longitude}) async {
|
||||
final result = await _sectionByIdRemoteDataSource.getSectionById(langId: langId, sectionId: sectionId, latitude: latitude, longitude: longitude, limit: limit, offset: offset);
|
||||
|
||||
if ((result[ERROR])) {
|
||||
return {ERROR: result[ERROR], MESSAGE: result[MESSAGE]};
|
||||
} else {
|
||||
return {ERROR: result[ERROR], DATA: (result[DATA] as List).map((e) => FeatureSectionModel.fromJson(e)).toList()};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class SetNewsViewsDataRemoteDataSource {
|
||||
Future<dynamic> setNewsViews({required String newsId, required bool isBreakingNews}) async {
|
||||
try {
|
||||
final body = {if (isBreakingNews) BR_NEWS_ID: newsId, if (!isBreakingNews) NEWS_ID: newsId};
|
||||
final result = await Api.sendApiRequest(body: body, url: (isBreakingNews) ? Api.setBreakingNewsViewApi : Api.setNewsViewApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'package:news/data/repositories/SetNewsViews/setNewsViewsDataRemoteSource.dart';
|
||||
|
||||
class SetNewsViewsRepository {
|
||||
static final SetNewsViewsRepository setNewsViewsRepository = SetNewsViewsRepository._internal();
|
||||
|
||||
late SetNewsViewsDataRemoteDataSource setNewsViewsDataRemoteDataSource;
|
||||
|
||||
factory SetNewsViewsRepository() {
|
||||
setNewsViewsRepository.setNewsViewsDataRemoteDataSource = SetNewsViewsDataRemoteDataSource();
|
||||
return setNewsViewsRepository;
|
||||
}
|
||||
|
||||
SetNewsViewsRepository._internal();
|
||||
|
||||
Future<Map<String, dynamic>> setNewsViews({required String newsId, required bool isBreakingNews}) async {
|
||||
final result = await setNewsViewsDataRemoteDataSource.setNewsViews(newsId: newsId, isBreakingNews: isBreakingNews);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class SetSurveyAnsRemoteDataSource {
|
||||
Future<dynamic> setSurveyAns({required String queId, required String optId}) async {
|
||||
try {
|
||||
final body = {QUESTION_ID: queId, OPTION_ID: optId};
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.setQueResultApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import 'package:news/data/repositories/SetSurveyAnswer/setSurveyAnsDataRemoteSource.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class SetSurveyAnsRepository {
|
||||
static final SetSurveyAnsRepository _setSurveyAnsRepository = SetSurveyAnsRepository._internal();
|
||||
|
||||
late SetSurveyAnsRemoteDataSource _setSurveyAnsRemoteDataSource;
|
||||
|
||||
factory SetSurveyAnsRepository() {
|
||||
_setSurveyAnsRepository._setSurveyAnsRemoteDataSource = SetSurveyAnsRemoteDataSource();
|
||||
return _setSurveyAnsRepository;
|
||||
}
|
||||
|
||||
SetSurveyAnsRepository._internal();
|
||||
|
||||
Future<Map<String, dynamic>> setSurveyAns({required String queId, required String optId}) async {
|
||||
final result = await _setSurveyAnsRemoteDataSource.setSurveyAns(optId: optId, queId: queId);
|
||||
|
||||
return {"SetSurveyAns": result[DATA]};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class SetUserPrefCatRemoteDataSource {
|
||||
Future<dynamic> setUserPrefCat({required String catId}) async {
|
||||
try {
|
||||
final body = {CATEGORY_ID: catId};
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.setUserCatApi);
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import 'package:news/data/repositories/SetUserPreferenceCat/setUserPrefCatRemoteDataSource.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class SetUserPrefCatRepository {
|
||||
static final SetUserPrefCatRepository _setUserPrefCatRepository = SetUserPrefCatRepository._internal();
|
||||
|
||||
late SetUserPrefCatRemoteDataSource _setUserPrefCatRemoteDataSource;
|
||||
|
||||
factory SetUserPrefCatRepository() {
|
||||
_setUserPrefCatRepository._setUserPrefCatRemoteDataSource = SetUserPrefCatRemoteDataSource();
|
||||
return _setUserPrefCatRepository;
|
||||
}
|
||||
|
||||
SetUserPrefCatRepository._internal();
|
||||
|
||||
Future<Map<String, dynamic>> setUserPrefCat({required String catId}) async {
|
||||
final result = await _setUserPrefCatRemoteDataSource.setUserPrefCat(catId: catId);
|
||||
|
||||
return {"SetUserPrefCat": result[DATA]};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import 'package:news/data/repositories/Settings/settingsLocalDataRepository.dart';
|
||||
|
||||
class SettingsRepository {
|
||||
static final SettingsRepository _settingsRepository = SettingsRepository._internal();
|
||||
late SettingsLocalDataRepository _settingsLocalDataSource;
|
||||
|
||||
factory SettingsRepository() {
|
||||
_settingsRepository._settingsLocalDataSource = SettingsLocalDataRepository();
|
||||
return _settingsRepository;
|
||||
}
|
||||
|
||||
SettingsRepository._internal();
|
||||
|
||||
Map<String, dynamic> getCurrentSettings() {
|
||||
return {
|
||||
"showIntroSlider": _settingsLocalDataSource.getIntroSlider(),
|
||||
"languageCode": _settingsLocalDataSource.getCurrentLanguageCode(),
|
||||
"theme": _settingsLocalDataSource.getCurrentTheme(),
|
||||
"notification": _settingsLocalDataSource.getNotification(),
|
||||
"token": _settingsLocalDataSource.getFcmToken()
|
||||
};
|
||||
}
|
||||
|
||||
void changeIntroSlider(bool value) => _settingsLocalDataSource.setIntroSlider(value);
|
||||
|
||||
void changeFcmToken(String value) => _settingsLocalDataSource.setFcmToken(value);
|
||||
|
||||
void changeNotification(bool value) => _settingsLocalDataSource.setNotification(value);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import 'package:flutter/src/foundation/change_notifier.dart';
|
||||
import 'package:hive_flutter/adapters.dart';
|
||||
import 'package:news/utils/hiveBoxKeys.dart';
|
||||
import 'package:news/utils/uiUtils.dart';
|
||||
|
||||
class SettingsLocalDataRepository {
|
||||
Future<void> setLanguagePreferences({required String code, required String id, required int rtl}) async {
|
||||
final box = Hive.box(settingsBoxKey);
|
||||
await Future.wait([
|
||||
box.put(currentLanguageCodeKey, code),
|
||||
box.put(currentLanguageIDKey, id),
|
||||
box.put(currentLanguageRTLKey, rtl),
|
||||
]);
|
||||
|
||||
UiUtils.checkIfValidLocale(langCode: code); // only if you want to validate locale after setting
|
||||
}
|
||||
|
||||
String getCurrentLanguageCode() {
|
||||
return Hive.box(settingsBoxKey).get(currentLanguageCodeKey) ?? "";
|
||||
}
|
||||
|
||||
String getCurrentLanguageId() {
|
||||
return Hive.box(settingsBoxKey).get(currentLanguageIDKey) ?? '';
|
||||
}
|
||||
|
||||
int getCurrentLanguageRTL() {
|
||||
return Hive.box(settingsBoxKey).get(currentLanguageRTLKey) ?? 0;
|
||||
}
|
||||
|
||||
Future<void> setIntroSlider(bool value) async {
|
||||
Hive.box(settingsBoxKey).put(introSliderKey, value);
|
||||
}
|
||||
|
||||
bool getIntroSlider() {
|
||||
return Hive.box(settingsBoxKey).get(introSliderKey) ?? true;
|
||||
}
|
||||
|
||||
Future<void> setFcmToken(String value) async {
|
||||
Hive.box(settingsBoxKey).put(tokenKey, value);
|
||||
}
|
||||
|
||||
String getFcmToken() {
|
||||
return Hive.box(settingsBoxKey).get(tokenKey) ?? "";
|
||||
}
|
||||
|
||||
Future<void> setCurrentTheme(String value) async {
|
||||
Hive.box(settingsBoxKey).put(currentThemeKey, value);
|
||||
}
|
||||
|
||||
String getCurrentTheme() {
|
||||
return Hive.box(settingsBoxKey).get(currentThemeKey) ?? "";
|
||||
}
|
||||
|
||||
Future<void> setNotification(bool value) async {
|
||||
Hive.box(settingsBoxKey).put(notificationKey, value);
|
||||
}
|
||||
|
||||
bool getNotification() {
|
||||
return Hive.box(settingsBoxKey).get(notificationKey) ?? true;
|
||||
}
|
||||
|
||||
Future<void> setLocationCityKeys(double? latitude, double? longitude) async {
|
||||
Hive.box(locationCityBoxKey).put(latitudeKey, latitude);
|
||||
Hive.box(locationCityBoxKey).put(longitudeKey, longitude);
|
||||
}
|
||||
|
||||
Set<String> getLocationCityValues() {
|
||||
Set<String> locationValues = {Hive.box(locationCityBoxKey).get(latitudeKey).toString(), Hive.box(locationCityBoxKey).get(longitudeKey).toString()};
|
||||
return locationValues;
|
||||
}
|
||||
|
||||
ValueListenable<Box> getVideoScreenStyle() {
|
||||
return Hive.box(videoPreferenceKey).listenable();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class SubCatNewsRemoteDataSource {
|
||||
Future<dynamic> getSubCatNews({required String limit, required String offset, String? catId, String? subCatId, String? latitude, String? longitude, required String langId}) async {
|
||||
try {
|
||||
final body = {LIMIT: limit, OFFSET: offset, LANGUAGE_ID: langId};
|
||||
if (catId != null) body[CATEGORY_ID] = catId;
|
||||
if (subCatId != null) body[SUBCAT_ID] = subCatId;
|
||||
if (latitude != null && latitude != "null") body[LATITUDE] = latitude;
|
||||
if (longitude != null && longitude != "null") body[LONGITUDE] = longitude;
|
||||
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.getNewsApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import 'package:news/data/models/NewsModel.dart';
|
||||
import 'package:news/data/repositories/SubCatNews/subCatNewsRemoteDataSource.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class SubCatNewsRepository {
|
||||
static final SubCatNewsRepository _subCatNewsRepository = SubCatNewsRepository._internal();
|
||||
|
||||
late SubCatNewsRemoteDataSource _subCatNewsRemoteDataSource;
|
||||
|
||||
factory SubCatNewsRepository() {
|
||||
_subCatNewsRepository._subCatNewsRemoteDataSource = SubCatNewsRemoteDataSource();
|
||||
return _subCatNewsRepository;
|
||||
}
|
||||
|
||||
SubCatNewsRepository._internal();
|
||||
|
||||
Future<Map<String, dynamic>> getSubCatNews({required String offset, required String limit, String? catId, String? subCatId, String? latitude, String? longitude, required String langId}) async {
|
||||
final result = await _subCatNewsRemoteDataSource.getSubCatNews(limit: limit, offset: offset, langId: langId, subCatId: subCatId, catId: catId, latitude: latitude, longitude: longitude);
|
||||
|
||||
if (result[ERROR]) {
|
||||
return {ERROR: result[ERROR]};
|
||||
} else {
|
||||
return {ERROR: result[ERROR], "total": result[TOTAL], "SubCatNews": (result[DATA] as List).map((e) => NewsModel.fromJson(e)).toList()};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class SubCategoryRemoteDataSource {
|
||||
Future<dynamic> getSubCategory({required String catId, required String langId}) async {
|
||||
try {
|
||||
final body = {CATEGORY_ID: catId, LANGUAGE_ID: langId};
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.getSubCategoryApi);
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:news/data/repositories/SubCategory/subCatRemoteDataSource.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
import 'package:news/utils/uiUtils.dart';
|
||||
import 'package:news/data/models/CategoryModel.dart';
|
||||
|
||||
class SubCategoryRepository {
|
||||
static final SubCategoryRepository _subCategoryRepository = SubCategoryRepository._internal();
|
||||
|
||||
late SubCategoryRemoteDataSource _subCategoryRemoteDataSource;
|
||||
|
||||
factory SubCategoryRepository() {
|
||||
_subCategoryRepository._subCategoryRemoteDataSource = SubCategoryRemoteDataSource();
|
||||
return _subCategoryRepository;
|
||||
}
|
||||
|
||||
SubCategoryRepository._internal();
|
||||
|
||||
Future<Map<String, dynamic>> getSubCategory({required BuildContext context, required String catId, required String langId}) async {
|
||||
final result = await _subCategoryRemoteDataSource.getSubCategory(langId: langId, catId: catId);
|
||||
|
||||
List<SubCategoryModel> subCatList = [];
|
||||
|
||||
subCatList.insert(0, SubCategoryModel(id: "0", subCatName: UiUtils.getTranslatedLabel(context, 'allLbl')));
|
||||
|
||||
subCatList.addAll((result[DATA] as List).map((e) => SubCategoryModel.fromJson(e)).toList());
|
||||
return {"SubCategory": subCatList};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class SurveyQuestionRemoteDataSource {
|
||||
Future<dynamic> getSurveyQuestions({required String langId}) async {
|
||||
try {
|
||||
final body = {LANGUAGE_ID: langId};
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.getQueApi);
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:news/data/models/NewsModel.dart';
|
||||
import 'package:news/data/repositories/SurveyQuestion/surveyQueRemoteDataSource.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class SurveyQuestionRepository {
|
||||
static final SurveyQuestionRepository _surveyQuestionRepository = SurveyQuestionRepository._internal();
|
||||
|
||||
late SurveyQuestionRemoteDataSource _surveyQuestionRemoteDataSource;
|
||||
|
||||
factory SurveyQuestionRepository() {
|
||||
_surveyQuestionRepository._surveyQuestionRemoteDataSource = SurveyQuestionRemoteDataSource();
|
||||
return _surveyQuestionRepository;
|
||||
}
|
||||
|
||||
SurveyQuestionRepository._internal();
|
||||
|
||||
Future<Map<String, dynamic>> getSurveyQuestion({required String langId}) async {
|
||||
final result = await _surveyQuestionRemoteDataSource.getSurveyQuestions(langId: langId);
|
||||
|
||||
return {"SurveyQuestion": (result[DATA] as List).map((e) => NewsModel.fromSurvey(e)).toList()};
|
||||
}
|
||||
}
|
||||
14
news-app/lib/data/repositories/Tag/tagRemoteDataSource.dart
Normal file
14
news-app/lib/data/repositories/Tag/tagRemoteDataSource.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class TagRemoteDataSource {
|
||||
Future<dynamic> getTag({required String langId, required String offset, required String limit}) async {
|
||||
try {
|
||||
final body = {LANGUAGE_ID: langId, LIMIT: limit, OFFSET: offset};
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.getTagsApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
22
news-app/lib/data/repositories/Tag/tagRepository.dart
Normal file
22
news-app/lib/data/repositories/Tag/tagRepository.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
import 'package:news/data/models/TagModel.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
import 'package:news/data/repositories/Tag/tagRemoteDataSource.dart';
|
||||
|
||||
class TagRepository {
|
||||
static final TagRepository _tagRepository = TagRepository._internal();
|
||||
|
||||
late TagRemoteDataSource _tagRemoteDataSource;
|
||||
|
||||
factory TagRepository() {
|
||||
_tagRepository._tagRemoteDataSource = TagRemoteDataSource();
|
||||
return _tagRepository;
|
||||
}
|
||||
|
||||
TagRepository._internal();
|
||||
|
||||
Future<Map<String, dynamic>> getTag({required String langId, required String offset, required String limit}) async {
|
||||
final result = await _tagRemoteDataSource.getTag(langId: langId, limit: limit, offset: offset);
|
||||
|
||||
return {"Tag": (result[DATA] as List).map((e) => TagModel.fromJson(e)).toList(), "total": result[TOTAL]};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class TagNewsRemoteDataSource {
|
||||
Future<dynamic> getTagNews({required String tagId, required String langId, String? latitude, String? longitude}) async {
|
||||
try {
|
||||
final body = {TAG_ID: tagId, LANGUAGE_ID: langId};
|
||||
if (latitude != null && latitude != "null") body[LATITUDE] = latitude;
|
||||
if (longitude != null && longitude != "null") body[LONGITUDE] = longitude;
|
||||
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.getNewsApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:news/data/models/NewsModel.dart';
|
||||
import 'package:news/data/repositories/TagNews/tagNewsDataSource.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class TagNewsRepository {
|
||||
static final TagNewsRepository _tagNewsRepository = TagNewsRepository._internal();
|
||||
|
||||
late TagNewsRemoteDataSource _tagNewsRemoteDataSource;
|
||||
|
||||
factory TagNewsRepository() {
|
||||
_tagNewsRepository._tagNewsRemoteDataSource = TagNewsRemoteDataSource();
|
||||
return _tagNewsRepository;
|
||||
}
|
||||
|
||||
TagNewsRepository._internal();
|
||||
|
||||
Future<Map<String, dynamic>> getTagNews({required String tagId, required String langId, String? latitude, String? longitude}) async {
|
||||
final result = await _tagNewsRemoteDataSource.getTagNews(tagId: tagId, langId: langId, latitude: latitude, longitude: longitude);
|
||||
|
||||
return {"TagNews": (result[DATA] as List).map((e) => NewsModel.fromJson(e)).toList()};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
|
||||
class UserByCatRemoteDataSource {
|
||||
Future<dynamic> getUserById() async {
|
||||
try {
|
||||
final result = await Api.sendApiRequest(body: {}, url: Api.getUserByIdApi);
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import 'package:news/data/repositories/UserByCategory/userByCatRemoteDataSource.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class UserByCatRepository {
|
||||
static final UserByCatRepository _userByCatRepository = UserByCatRepository._internal();
|
||||
|
||||
late UserByCatRemoteDataSource _userByCatRemoteDataSource;
|
||||
|
||||
factory UserByCatRepository() {
|
||||
_userByCatRepository._userByCatRemoteDataSource = UserByCatRemoteDataSource();
|
||||
return _userByCatRepository;
|
||||
}
|
||||
|
||||
UserByCatRepository._internal();
|
||||
|
||||
Future<Map<String, dynamic>> getUserById() async {
|
||||
final result = await _userByCatRemoteDataSource.getUserById();
|
||||
|
||||
return {"UserByCat": result[DATA]};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class VideoRemoteDataSource {
|
||||
Future<dynamic> getVideos({required String limit, required String offset, required String langId, String? latitude, String? longitude}) async {
|
||||
try {
|
||||
final body = {LIMIT: limit, OFFSET: offset, LANGUAGE_ID: langId};
|
||||
if (latitude != null && latitude != "null") body[LATITUDE] = latitude;
|
||||
if (longitude != null && longitude != "null") body[LONGITUDE] = longitude;
|
||||
|
||||
final result = await Api.sendApiRequest(body: body, url: Api.getVideosApi);
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
23
news-app/lib/data/repositories/Videos/videosRepository.dart
Normal file
23
news-app/lib/data/repositories/Videos/videosRepository.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
import 'package:news/data/models/NewsModel.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
import 'package:news/data/repositories/Videos/videoRemoteDataSource.dart';
|
||||
|
||||
class VideoRepository {
|
||||
static final VideoRepository _videoRepository = VideoRepository._internal();
|
||||
|
||||
late VideoRemoteDataSource _videoRemoteDataSource;
|
||||
|
||||
factory VideoRepository() {
|
||||
_videoRepository._videoRemoteDataSource = VideoRemoteDataSource();
|
||||
return _videoRepository;
|
||||
}
|
||||
|
||||
VideoRepository._internal();
|
||||
|
||||
Future<Map<String, dynamic>> getVideo({required String offset, required String limit, required String langId, String? latitude, String? longitude}) async {
|
||||
final result = await _videoRemoteDataSource.getVideos(limit: limit, offset: offset, langId: langId, latitude: latitude, longitude: longitude);
|
||||
return (result[ERROR])
|
||||
? {ERROR: result[ERROR], MESSAGE: result[MESSAGE]}
|
||||
: {ERROR: result[ERROR], "total": result[TOTAL], "Video": (result[DATA] as List).map((e) => NewsModel.fromVideos(e)).toList()};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import 'package:news/utils/api.dart';
|
||||
|
||||
class LanguageRemoteDataSource {
|
||||
Future<dynamic> getLanguages() async {
|
||||
try {
|
||||
final result = await Api.sendApiRequest(url: Api.getLanguagesApi, body: {});
|
||||
return result;
|
||||
} catch (e) {
|
||||
throw ApiMessageAndCodeException(errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:news/data/models/appLanguageModel.dart';
|
||||
import 'package:news/data/repositories/language/languageRemoteDataSource.dart';
|
||||
import 'package:news/utils/strings.dart';
|
||||
|
||||
class LanguageRepository {
|
||||
static final LanguageRepository _languageRepository = LanguageRepository._internal();
|
||||
|
||||
late LanguageRemoteDataSource _languageRemoteDataSource;
|
||||
|
||||
factory LanguageRepository() {
|
||||
_languageRepository._languageRemoteDataSource = LanguageRemoteDataSource();
|
||||
return _languageRepository;
|
||||
}
|
||||
|
||||
LanguageRepository._internal();
|
||||
|
||||
Future<Map<String, dynamic>> getLanguage() async {
|
||||
final result = await _languageRemoteDataSource.getLanguages();
|
||||
|
||||
return {"Language": (result[DATA] as List).map((e) => LanguageModel.fromJson(e)).toList()};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user