Skip to content

Instantly share code, notes, and snippets.

@thuycom205
Created November 24, 2022 04:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thuycom205/2b0ab47f7be92f25c66a0ff8e01887f2 to your computer and use it in GitHub Desktop.
Save thuycom205/2b0ab47f7be92f25c66a0ff8e01887f2 to your computer and use it in GitHub Desktop.
acfc
import 'dart:convert';
import 'package:magenest_store/services/web_service.dart';
import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart';
import '../../service_locator.dart';
import '../shared_service.dart';
class ReviewService extends WebService {
String urlWriteReview = "V1/mobileapi/product/review";
Map<String, String> _defaultHeaders = {'Content-Type': 'application/json'};
ShareService shareService = locator.get<ShareService>();
Future<bool> writeReviewProduct(int? productId, String? title, String? nickname,
String? detail, String? priceRating, String? qtyRating) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
var token = await shareService.retrieveCustomerToken();
int? customerId = await shareService.retrieveCustomerId();
String url = WebService.getInstance().apiEndpoint + urlWriteReview;
// get from sing
var requestHeaders = Map<String, String>.from(_defaultHeaders);
var authBody;
if (token != null) {
requestHeaders.addAll({'Authorization': 'Bearer $token'});
authBody = jsonEncode({
"productId": productId,
"review": {
"title": "$title",
"nickname": "$nickname",
"detail": "$detail",
// "price_rating": "5.0",
"quality_rating": "$qtyRating"
},
"customerId": customerId
});
} else {
authBody = jsonEncode({
"productId": productId,
"review": {
"title": "$title",
"nickname": "$nickname",
"detail": "$detail",
// "price_rating": "5.0",
"quality_rating": "$qtyRating"
}
});
}
await http.post(Uri.parse(url), headers: requestHeaders, body: authBody);
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment