feat: add updateCategoryMine endpoint to manage product category updates
Test Suite / test (24.15.0) (push) Has been cancelled

- Implemented a new PATCH endpoint in ProductsController to update the category of a user's product.
- Added corresponding service method in ProductsService to handle business logic and validation.
- Created UpdateCategoryMineDto for request validation.
- Enhanced error handling for forbidden actions and not found resources.
- Updated API error mapping in Flutter to handle specific forbidden messages.
- Modified ProductPickerField to allow product creation directly from the picker.
- Added tests for the new endpoint and service method to ensure proper functionality and error handling.
This commit is contained in:
Nils-Johan Gynther
2026-05-11 21:41:42 +02:00
parent 8e0166c68a
commit f19c157e8f
15 changed files with 756 additions and 31 deletions
+8 -1
View File
@@ -4,6 +4,11 @@ import 'package:flutter/services.dart';
import '../l10n/l10n.dart';
import 'api_exception.dart';
const _safeForbiddenMessages = {
'Du kan inte omkategorisera, ta bort eller ändra produkter som är globala.',
'Du kan bara omkategorisera dina egna produkter',
};
String mapErrorToUserMessage(Object error, BuildContext context) {
final l10n = context.l10n;
if (error is ApiException) {
@@ -11,7 +16,9 @@ String mapErrorToUserMessage(Object error, BuildContext context) {
case ApiErrorType.unauthorized:
return l10n.sessionExpiredError;
case ApiErrorType.forbidden:
return l10n.forbiddenError;
return _safeForbiddenMessages.contains(error.message)
? error.message
: l10n.forbiddenError;
case ApiErrorType.server:
return l10n.serverError;
case ApiErrorType.network:
+1
View File
@@ -13,6 +13,7 @@ class ProductApiPaths {
static const deleted = '/products/deleted';
static const merge = '/products/merge';
static const mergePrivate = '/products/private/merge';
static String updateMineCategory(int id) => '/products/mine/$id/category';
static String mergePreview(int sourceProductId, int targetProductId) =>
'/products/merge-preview?sourceProductId=$sourceProductId&targetProductId=$targetProductId';
static String setStatus(int id) => '/products/$id/status';