class RequestHelper { static const String baseUrl = 'https://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 const String directTypes = baseUrl + '/direct/types'; static const String addComment = baseUrl + '/comment/add'; static String feedbackComment(int id) => baseUrl + '/comment/$id/feedback'; static String direct(int id) => _baseUserUrl + '/direct/$id'; static String markRadar(int id) => _baseRadarUrl + '/$id/mark'; static String radarDetails(int id) => _baseRadarUrl + '/$id'; static String radarComments(int id) => _baseRadarUrl + '/$id/comments'; static String markNews(int id) => _baseNewsUrl + '/$id/mark'; static String newsDetails(int id) => _baseNewsUrl + '/$id'; static String newsComments(int id) => _baseNewsUrl + '/$id/comments'; static String radarOverviews({ required int page, List categories = const [], String? startDate, String? endDate, String? search, }) { String? cats; if (categories.isNotEmpty) { cats = ''; for (var i = 0; i < categories.length; i++) { cats = cats! + categories[i].toString(); if (i != categories.length - 1) { cats += ','; } } } return _baseRadarUrl + _urlConcatGenerator([ MapEntry('page', page.toString()), MapEntry('start', startDate), MapEntry('end', endDate), MapEntry('search', search), MapEntry('categories', cats), ]); } static String newsOverviews({ required int page, String? startDate, String? endDate, String? search, }) { String? cats; return _baseNewsUrl + _urlConcatGenerator([ MapEntry('page', page.toString()), MapEntry('start', startDate), MapEntry('end', endDate), MapEntry('search', search), MapEntry('categories', cats), ]); } static String _urlConcatGenerator(List> 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; } }