Added notification logic and view api
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
// notification_service.dart
|
||||
import 'dart:convert';
|
||||
import 'package:tm_app/data/services/api/notification_api.dart';
|
||||
import 'package:tm_app/data/services/model/notification__response/notification_response_model.dart';
|
||||
|
||||
import 'package:tm_app/core/utils/result.dart';
|
||||
import '../../core/network/network_manager.dart';
|
||||
|
||||
class NotificationsService {
|
||||
NotificationsService({required NetworkManager networkManager})
|
||||
: _networkManager = networkManager;
|
||||
final NetworkManager _networkManager;
|
||||
|
||||
Future<Result<NotificationResponseModel>> getNotifications({
|
||||
required int limit,
|
||||
required int offset,
|
||||
}) async {
|
||||
final result = await _networkManager.makeRequest(
|
||||
NotificationApi.getNotifications(limit: limit, offset: offset),
|
||||
//NotificationApi.notifications,
|
||||
method: 'GET',
|
||||
(json) => NotificationResponseModel.fromJson(json),
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<Result<NotificationResponseModel>> markAllAsRead() async {
|
||||
final result = await _networkManager.makeRequest(
|
||||
NotificationApi.markAllAsRead,
|
||||
method: 'POST',
|
||||
(json) => NotificationResponseModel.fromJson(json),
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<Result<NotificationResponseModel>> markAsRead({
|
||||
required String notificationId,
|
||||
}) async {
|
||||
final data = jsonEncode({'notification_id': notificationId});
|
||||
final result = await _networkManager.makeRequest(
|
||||
NotificationApi.markAsRead,
|
||||
method: 'POST',
|
||||
(json) => NotificationResponseModel.fromJson(json),
|
||||
data: data,
|
||||
);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user