164 lines
5.5 KiB
Dart
164 lines
5.5 KiB
Dart
import 'package:didvan/models/requests/news.dart';
|
|
import 'package:didvan/models/requests/radar.dart';
|
|
import 'package:didvan/models/requests/studio.dart';
|
|
|
|
class RequestHelper {
|
|
static const String baseUrl = 'https://test.api.didvan.app';
|
|
static const String _baseUserUrl = baseUrl + '/user';
|
|
static const String _baseRadarUrl = baseUrl + '/radar';
|
|
static const String _baseNewsUrl = baseUrl + '/news';
|
|
static const String _baseStudioUrl = baseUrl + '/studio';
|
|
static const String _baseDirectUrl = _baseUserUrl + '/direct';
|
|
|
|
static const String confirmUsername = _baseUserUrl + '/confirmUsername';
|
|
static const String changePassword = _baseUserUrl + '/changePassword';
|
|
static const String login = _baseUserUrl + '/login';
|
|
static const String directs = _baseUserUrl + '/direct';
|
|
static const String userInfo = _baseUserUrl + '/info';
|
|
static const String firebaseToken = _baseUserUrl + '/firebaseToken';
|
|
static const String silenceInterval = _baseUserUrl + '/silenceInterval';
|
|
static const String updateProfilePhoto = _baseUserUrl + '/profile/photo';
|
|
static const String checkUsername = _baseUserUrl + '/CheckUsername';
|
|
static const String updateProfile = _baseUserUrl + '/profile/edit';
|
|
static const String otp = _baseUserUrl + '/otp';
|
|
static String bookmarks({
|
|
required int page,
|
|
String? search,
|
|
String? type,
|
|
String? studioType,
|
|
}) =>
|
|
_baseUserUrl +
|
|
'/marked/${type ?? ''}' +
|
|
_urlConcatGenerator([
|
|
MapEntry('page', page),
|
|
MapEntry('type', studioType),
|
|
MapEntry('search', search),
|
|
]);
|
|
|
|
static const String directTypes = baseUrl + '/direct/types';
|
|
static String direct(int id) => _baseDirectUrl + '/$id';
|
|
static String sendDirectMessage(int id) =>
|
|
_baseDirectUrl + '/$id/sendMessage';
|
|
static String tag({
|
|
required List<int> ids,
|
|
String? type,
|
|
int? itemId,
|
|
int? page,
|
|
int? limit,
|
|
}) =>
|
|
baseUrl +
|
|
'/tag' +
|
|
_urlConcatGenerator([
|
|
MapEntry('page', page),
|
|
MapEntry('limit', limit ?? '3'),
|
|
MapEntry('type', type),
|
|
MapEntry('id', itemId ?? '1'),
|
|
MapEntry('tags', _urlListConcatGenerator(ids)),
|
|
]);
|
|
|
|
static String radarDetails(int id, RadarRequestArgs args) =>
|
|
_baseRadarUrl +
|
|
'/$id' +
|
|
_urlConcatGenerator([
|
|
MapEntry('page', args.page),
|
|
MapEntry('start', args.startDate),
|
|
MapEntry('end', args.endDate),
|
|
MapEntry('search', args.search),
|
|
MapEntry('categories', _urlListConcatGenerator(args.categories)),
|
|
]);
|
|
static String radarOverviews({required RadarRequestArgs args}) =>
|
|
_baseRadarUrl +
|
|
_urlConcatGenerator([
|
|
MapEntry('page', args.page),
|
|
MapEntry('start', args.startDate),
|
|
MapEntry('end', args.endDate),
|
|
MapEntry('search', args.search),
|
|
MapEntry('categories', _urlListConcatGenerator(args.categories)),
|
|
]);
|
|
|
|
static String newsDetails(int id, NewsRequestArgs args) =>
|
|
_baseNewsUrl +
|
|
'/$id' +
|
|
_urlConcatGenerator([
|
|
MapEntry('page', args.page),
|
|
MapEntry('start', args.startDate),
|
|
MapEntry('end', args.endDate),
|
|
MapEntry('search', args.search),
|
|
]);
|
|
static String newsOverviews({required NewsRequestArgs args}) =>
|
|
_baseNewsUrl +
|
|
_urlConcatGenerator([
|
|
MapEntry('page', args.page),
|
|
MapEntry('start', args.startDate),
|
|
MapEntry('end', args.endDate),
|
|
MapEntry('search', args.search),
|
|
]);
|
|
|
|
static String sudioSlider(String type) =>
|
|
_baseStudioUrl +
|
|
'/slider' +
|
|
_urlConcatGenerator([MapEntry('type', type)]);
|
|
static String studioDetails(int id, StudioRequestArgs args) =>
|
|
_baseStudioUrl +
|
|
'/$id' +
|
|
_urlConcatGenerator([
|
|
MapEntry('page', args.page),
|
|
MapEntry('type', args.type),
|
|
MapEntry('order', args.order),
|
|
MapEntry('search', args.search),
|
|
MapEntry('asc', args.asc),
|
|
]);
|
|
static String studioOverviews({required StudioRequestArgs args}) =>
|
|
_baseStudioUrl +
|
|
_urlConcatGenerator([
|
|
MapEntry('page', args.page),
|
|
MapEntry('type', args.type),
|
|
MapEntry('order', args.order),
|
|
MapEntry('search', args.search),
|
|
MapEntry('asc', args.asc),
|
|
]);
|
|
|
|
static String mark(int id, String type) => baseUrl + '/$type/$id/mark';
|
|
static String tracking(int id, String type) =>
|
|
baseUrl + '/$type/$id/tracking';
|
|
static String comments(int id, String type) =>
|
|
baseUrl + '/$type/$id/comments';
|
|
static String feedback(int id, int commentId, String type) =>
|
|
baseUrl + '/$type/$id/comments/$commentId/feedback';
|
|
static String addComment(int id, String type) =>
|
|
baseUrl + '/$type/$id/comments/add';
|
|
|
|
static String _urlConcatGenerator(List<MapEntry<String, dynamic>> additions) {
|
|
String result = '';
|
|
additions.removeWhere(
|
|
(element) => element.value == null || element.value.toString().isEmpty,
|
|
);
|
|
if (additions.isNotEmpty) {
|
|
result += '?';
|
|
for (var i = 0; i < additions.length; i++) {
|
|
result += (additions[i].key + '=' + additions[i].value!.toString());
|
|
if (i != additions.length - 1) {
|
|
result += '&';
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
static String? _urlListConcatGenerator(List? input) {
|
|
String? result;
|
|
if (input == null) return null;
|
|
if (input.isNotEmpty) {
|
|
result = '';
|
|
for (var i = 0; i < input.length; i++) {
|
|
result = result! + input[i].toString();
|
|
if (i != input.length - 1) {
|
|
result += ',';
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
return null;
|
|
}
|
|
}
|