feat: refactor API paths for authentication, inventory, and recipes; add contract tests for repositories

This commit is contained in:
Nils-Johan Gynther
2026-04-22 10:21:07 +02:00
parent 655adf66ae
commit c163821bad
8 changed files with 246 additions and 19 deletions
@@ -1,5 +1,6 @@
import '../../../core/api/api_client.dart';
import '../../../core/api/api_exception.dart';
import '../../../core/api/api_paths.dart';
import '../domain/parsed_recipe.dart';
import '../domain/recipe.dart';
@@ -10,7 +11,7 @@ class RecipeRepository {
Future<List<Recipe>> fetchRecipes({String? token}) async {
try {
final data = await _api.getJson('/recipes', token: token);
final data = await _api.getJson(RecipeApiPaths.list, token: token);
if (data is! List) {
throw const ApiException(
type: ApiErrorType.unknown, message: 'Ogiltigt svar fran servern.');
@@ -28,7 +29,7 @@ class RecipeRepository {
Future<Recipe> fetchRecipeDetail(int id, {String? token}) async {
try {
final data = await _api.getJson('/recipes/$id', token: token);
final data = await _api.getJson(RecipeApiPaths.detail(id), token: token);
if (data is! Map<String, dynamic>) {
throw const ApiException(
type: ApiErrorType.unknown, message: 'Ogiltigt svar fran servern.');
@@ -45,8 +46,8 @@ class RecipeRepository {
Future<Recipe> createRecipe(Map<String, dynamic> body,
{String? token}) async {
try {
final data =
await _api.postJson('/recipes', body: body, token: token);
final data =
await _api.postJson(RecipeApiPaths.list, body: body, token: token);
if (data is! Map<String, dynamic>) {
throw const ApiException(
type: ApiErrorType.unknown, message: 'Ogiltigt svar fran servern.');
@@ -63,8 +64,11 @@ class RecipeRepository {
Future<Recipe> updateRecipe(int id, Map<String, dynamic> body,
{String? token}) async {
try {
final data =
await _api.patchJson('/recipes/$id', body: body, token: token);
final data = await _api.patchJson(
RecipeApiPaths.update(id),
body: body,
token: token,
);
if (data is! Map<String, dynamic>) {
throw const ApiException(
type: ApiErrorType.unknown, message: 'Ogiltigt svar fran servern.');
@@ -80,7 +84,7 @@ class RecipeRepository {
Future<void> deleteRecipe(int id, {String? token}) async {
try {
await _api.deleteJson('/recipes/$id', token: token);
await _api.deleteJson(RecipeApiPaths.remove(id), token: token);
} on ApiException {
rethrow;
} catch (_) {
@@ -93,7 +97,7 @@ class RecipeRepository {
{String? token}) async {
try {
final data = await _api.postJson(
'/recipes/parse-markdown',
RecipeApiPaths.parseMarkdown,
body: {'markdown': markdown},
token: token,
);