diff --git a/flutter/lib/core/api/api_client.dart b/flutter/lib/core/api/api_client.dart index 3eb5ccdc..718de24c 100644 --- a/flutter/lib/core/api/api_client.dart +++ b/flutter/lib/core/api/api_client.dart @@ -57,17 +57,18 @@ class ApiClient { return _decodeOrNull(_guardResponse(response)); } - Future deleteJson(String path, {String? token}) async { - final response = await _client.delete( - Uri.parse('$baseUrl$path'), - headers: _headers(token: token), - ); - return _decodeOrNull(_guardResponse(response)); - } - - http.Response _guardResponse(http.Response response) { - if (response.statusCode < 400) { - return response; + Future patchJson( + String path, { + Object? body, + String? token, + }) async { + final response = await _client.patch( + Uri.parse('$baseUrl$path'), + headers: _headers(token: token), + body: body == null ? null : jsonEncode(body), + ); + return _decodeOrNull(_guardResponse(response)); + } } final parsedBody = _decodeOrNull(response); diff --git a/flutter/lib/features/recipes/data/recipe_repository.dart b/flutter/lib/features/recipes/data/recipe_repository.dart index 8b086406..8d4b81fe 100644 --- a/flutter/lib/features/recipes/data/recipe_repository.dart +++ b/flutter/lib/features/recipes/data/recipe_repository.dart @@ -64,7 +64,7 @@ class RecipeRepository { {String? token}) async { try { final data = - await _api.putJson('/recipes/$id', body: body, token: token); + await _api.patchJson('/recipes/$id', body: body, token: token); if (data is! Map) { throw const ApiException( type: ApiErrorType.unknown, message: 'Ogiltigt svar fran servern.');