feat: implement patch method in ApiClient and update recipe update logic in RecipeRepository

This commit is contained in:
Nils-Johan Gynther
2026-04-22 07:58:42 +02:00
parent ed4e18dc31
commit e50781dccf
2 changed files with 13 additions and 12 deletions
+7 -6
View File
@@ -57,17 +57,18 @@ class ApiClient {
return _decodeOrNull(_guardResponse(response));
}
Future<dynamic> deleteJson(String path, {String? token}) async {
final response = await _client.delete(
Future<dynamic> 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));
}
http.Response _guardResponse(http.Response response) {
if (response.statusCode < 400) {
return response;
}
final parsedBody = _decodeOrNull(response);
@@ -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<String, dynamic>) {
throw const ApiException(
type: ApiErrorType.unknown, message: 'Ogiltigt svar fran servern.');