101 lines
3.8 KiB
Dart
101 lines
3.8 KiB
Dart
import 'package:didvan/models/requests/news.dart';
|
|
import 'package:didvan/models/requests/radar.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 confirmUsername = _baseUserUrl + '/confirmUsername';
|
|
static const String login = _baseUserUrl + '/login';
|
|
static const String directs = _baseUserUrl + '/direct';
|
|
static const String userInfo = _baseUserUrl + '/info';
|
|
static const String updateUserProfile = _baseUserUrl + '/profile/photo';
|
|
static const String checkUsername = _baseUserUrl + '/CheckUsername';
|
|
static const String updateProfile = _baseUserUrl + '/profile/edit';
|
|
static String bookmarks({String? type}) =>
|
|
_baseUserUrl + '/marked/${type ?? ''}';
|
|
|
|
static const String directTypes = baseUrl + '/direct/types';
|
|
static String direct(int id) => _baseUserUrl + '/direct/$id';
|
|
|
|
static String markRadar(int id) => _baseRadarUrl + '/$id/mark';
|
|
static String radarComments(int id) => _baseRadarUrl + '/$id/comments';
|
|
static String addRadarComment(int id) => _baseRadarUrl + '/$id/comments/add';
|
|
static String feedbackRadarComment(int radarId, int id) =>
|
|
_baseRadarUrl + '/$radarId/comments/$id/feedback';
|
|
static String radarDetails(int id, RadarRequestArgs args) =>
|
|
_baseRadarUrl +
|
|
'/$id' +
|
|
_urlConcatGenerator([
|
|
MapEntry('page', args.page.toString()),
|
|
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.toString()),
|
|
MapEntry('start', args.startDate),
|
|
MapEntry('end', args.endDate),
|
|
MapEntry('search', args.search),
|
|
MapEntry('categories', _urlListConcatGenerator(args.categories)),
|
|
]);
|
|
|
|
static String markNews(int id) => _baseNewsUrl + '/$id/mark';
|
|
static String newsComments(int id) => _baseNewsUrl + '/$id/comments';
|
|
static String addNewsComment(int id) => _baseNewsUrl + '/$id/comments/add';
|
|
static String feedbackNewsComment(int radarId, int id) =>
|
|
_baseNewsUrl + '/$radarId/comments/$id/feedback';
|
|
static String newsDetails(int id, NewsRequestArgs args) =>
|
|
_baseNewsUrl +
|
|
'/$id' +
|
|
_urlConcatGenerator([
|
|
MapEntry('page', args.page.toString()),
|
|
MapEntry('start', args.startDate),
|
|
MapEntry('end', args.endDate),
|
|
MapEntry('search', args.search),
|
|
]);
|
|
static String newsOverviews({required NewsRequestArgs args}) =>
|
|
_baseNewsUrl +
|
|
_urlConcatGenerator([
|
|
MapEntry('page', args.page.toString()),
|
|
MapEntry('start', args.startDate),
|
|
MapEntry('end', args.endDate),
|
|
MapEntry('search', args.search),
|
|
]);
|
|
|
|
static String _urlConcatGenerator(List<MapEntry<String, String?>> additions) {
|
|
String result = '';
|
|
additions.removeWhere((element) => element.value == null);
|
|
if (additions.isNotEmpty) {
|
|
result += '?';
|
|
for (var i = 0; i < additions.length; i++) {
|
|
result += (additions[i].key + '=' + additions[i].value!);
|
|
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;
|
|
}
|
|
}
|
|
}
|