diff --git a/lib/services/network/request.dart b/lib/services/network/request.dart index 346dcb2..63d5035 100644 --- a/lib/services/network/request.dart +++ b/lib/services/network/request.dart @@ -2,11 +2,10 @@ import 'dart:convert'; import 'dart:developer'; import 'dart:io'; import 'package:http/http.dart' as http; +import 'package:http_parser/http_parser.dart' as parser; class RequestService { - static late String _token; - - static set token(String value) => _token = value; + static late String token; Map get result => _body['result'] ?? const {}; Map get errors => _body['errors'] ?? const {}; @@ -32,7 +31,7 @@ class RequestService { }) { if (body != null) _requestBody = body; if (requestHeaders != null) _headers.addAll(requestHeaders); - if (useAutherization) _headers.addAll({'Authorization': 'Bearer $_token'}); + if (useAutherization) _headers.addAll({'Authorization': 'Bearer $token'}); if (body != null) _requestBody = body; } @@ -99,15 +98,16 @@ class RequestService { Future multipart(File file) async { try { - final request = http.MultipartRequest('POST', Uri.parse(url)); + final request = http.MultipartRequest('PUT', Uri.parse(url)); _headers.update('Content-Type', (_) => 'multipart/form-data'); request.headers.addAll(_headers); request.files.add( http.MultipartFile( - 'file', + 'photo', file.readAsBytes().asStream(), file.lengthSync(), - filename: 'desc', + filename: 'profile-photo', + contentType: parser.MediaType('image', 'jpg'), ), ); final streamedResponse = await request diff --git a/lib/services/network/request_helper.dart b/lib/services/network/request_helper.dart index a14df9c..8817b8b 100644 --- a/lib/services/network/request_helper.dart +++ b/lib/services/network/request_helper.dart @@ -1,18 +1,30 @@ class RequestHelper { - static const String _baseUrl = 'https://didvan-greatsam.fandogh.cloud'; - static const String _baseUserUrl = _baseUrl + '/user'; + static const String baseUrl = 'https://didvan-greatsam.fandogh.cloud'; + 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 updateUsername = _baseUserUrl + '/setUsername'; + static const String checkUsername = _baseUserUrl + '/CheckUsername'; + static const String updateProfile = _baseUserUrl + '/profile/edit'; - static const String radarCategories = _baseUrl + '/category'; + 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 getRadarOverviews({ + + static String markRadar(int id) => _baseRadarUrl + '/mark/$id'; + static String radarDetails(int id) => _baseRadarUrl + '/$id'; + static String radarComments(int id) => _baseRadarUrl + '/$id/comments'; + static String markNews(int id) => _baseNewsUrl + '/mark/$id'; + 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, @@ -29,8 +41,24 @@ class RequestHelper { } } } - return _baseUrl + - '/radar' + + 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),