feat: implement patch method in ApiClient and update recipe update logic in RecipeRepository
This commit is contained in:
@@ -57,17 +57,18 @@ class ApiClient {
|
|||||||
return _decodeOrNull(_guardResponse(response));
|
return _decodeOrNull(_guardResponse(response));
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<dynamic> deleteJson(String path, {String? token}) async {
|
Future<dynamic> patchJson(
|
||||||
final response = await _client.delete(
|
String path, {
|
||||||
Uri.parse('$baseUrl$path'),
|
Object? body,
|
||||||
headers: _headers(token: token),
|
String? token,
|
||||||
);
|
}) async {
|
||||||
return _decodeOrNull(_guardResponse(response));
|
final response = await _client.patch(
|
||||||
}
|
Uri.parse('$baseUrl$path'),
|
||||||
|
headers: _headers(token: token),
|
||||||
http.Response _guardResponse(http.Response response) {
|
body: body == null ? null : jsonEncode(body),
|
||||||
if (response.statusCode < 400) {
|
);
|
||||||
return response;
|
return _decodeOrNull(_guardResponse(response));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final parsedBody = _decodeOrNull(response);
|
final parsedBody = _decodeOrNull(response);
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class RecipeRepository {
|
|||||||
{String? token}) async {
|
{String? token}) async {
|
||||||
try {
|
try {
|
||||||
final data =
|
final data =
|
||||||
await _api.putJson('/recipes/$id', body: body, token: token);
|
await _api.patchJson('/recipes/$id', body: body, token: token);
|
||||||
if (data is! Map<String, dynamic>) {
|
if (data is! Map<String, dynamic>) {
|
||||||
throw const ApiException(
|
throw const ApiException(
|
||||||
type: ApiErrorType.unknown, message: 'Ogiltigt svar fran servern.');
|
type: ApiErrorType.unknown, message: 'Ogiltigt svar fran servern.');
|
||||||
|
|||||||
Reference in New Issue
Block a user