D1APP-22 request service edits
This commit is contained in:
parent
6db9921dfe
commit
900023e43c
|
|
@ -2,11 +2,10 @@ import 'dart:convert';
|
||||||
import 'dart:developer';
|
import 'dart:developer';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:http_parser/http_parser.dart' as parser;
|
||||||
|
|
||||||
class RequestService {
|
class RequestService {
|
||||||
static late String _token;
|
static late String token;
|
||||||
|
|
||||||
static set token(String value) => _token = value;
|
|
||||||
|
|
||||||
Map<String, dynamic> get result => _body['result'] ?? const {};
|
Map<String, dynamic> get result => _body['result'] ?? const {};
|
||||||
Map<String, dynamic> get errors => _body['errors'] ?? const {};
|
Map<String, dynamic> get errors => _body['errors'] ?? const {};
|
||||||
|
|
@ -32,7 +31,7 @@ class RequestService {
|
||||||
}) {
|
}) {
|
||||||
if (body != null) _requestBody = body;
|
if (body != null) _requestBody = body;
|
||||||
if (requestHeaders != null) _headers.addAll(requestHeaders);
|
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;
|
if (body != null) _requestBody = body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,15 +98,16 @@ class RequestService {
|
||||||
|
|
||||||
Future<void> multipart(File file) async {
|
Future<void> multipart(File file) async {
|
||||||
try {
|
try {
|
||||||
final request = http.MultipartRequest('POST', Uri.parse(url));
|
final request = http.MultipartRequest('PUT', Uri.parse(url));
|
||||||
_headers.update('Content-Type', (_) => 'multipart/form-data');
|
_headers.update('Content-Type', (_) => 'multipart/form-data');
|
||||||
request.headers.addAll(_headers);
|
request.headers.addAll(_headers);
|
||||||
request.files.add(
|
request.files.add(
|
||||||
http.MultipartFile(
|
http.MultipartFile(
|
||||||
'file',
|
'photo',
|
||||||
file.readAsBytes().asStream(),
|
file.readAsBytes().asStream(),
|
||||||
file.lengthSync(),
|
file.lengthSync(),
|
||||||
filename: 'desc',
|
filename: 'profile-photo',
|
||||||
|
contentType: parser.MediaType('image', 'jpg'),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
final streamedResponse = await request
|
final streamedResponse = await request
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,30 @@
|
||||||
class RequestHelper {
|
class RequestHelper {
|
||||||
static const String _baseUrl = 'https://didvan-greatsam.fandogh.cloud';
|
static const String baseUrl = 'https://didvan-greatsam.fandogh.cloud';
|
||||||
static const String _baseUserUrl = _baseUrl + '/user';
|
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 confirmUsername = _baseUserUrl + '/confirmUsername';
|
||||||
static const String login = _baseUserUrl + '/login';
|
static const String login = _baseUserUrl + '/login';
|
||||||
static const String directs = _baseUserUrl + '/direct';
|
static const String directs = _baseUserUrl + '/direct';
|
||||||
static const String userInfo = _baseUserUrl + '/info';
|
static const String userInfo = _baseUserUrl + '/info';
|
||||||
static const String updateUserProfile = _baseUserUrl + '/profile/photo';
|
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 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,
|
required int page,
|
||||||
List<int> categories = const [],
|
List<int> categories = const [],
|
||||||
String? startDate,
|
String? startDate,
|
||||||
|
|
@ -29,8 +41,24 @@ class RequestHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return _baseUrl +
|
return _baseRadarUrl +
|
||||||
'/radar' +
|
_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([
|
_urlConcatGenerator([
|
||||||
MapEntry('page', page.toString()),
|
MapEntry('page', page.toString()),
|
||||||
MapEntry('start', startDate),
|
MapEntry('start', startDate),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue