Update quick links integration to use new /dashboard/quick-links API:
- Change API path from /front-hall/quick-links to /dashboard/quick-links
- Update field mappings: name→title, icon_name→icon, sort_order→position, is_active→is_visible
- Change ID type from String to int with conversion in provider
- Parse new response format {"links": [...], "total": N}
- Update reorder endpoint from PUT to POST with link_ids
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
76 lines
2.2 KiB
Dart
76 lines
2.2 KiB
Dart
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
import 'package:tatlock_ui/features/front_hall/domain/entities/quick_link.dart';
|
|
|
|
part 'quick_link_model.freezed.dart';
|
|
part 'quick_link_model.g.dart';
|
|
|
|
/// Quick link data model for API serialization.
|
|
///
|
|
/// Maps to Core API dashboard/quick-links endpoint:
|
|
/// - title (API) ↔ name (Flutter entity)
|
|
/// - icon (API) ↔ iconName (Flutter entity)
|
|
/// - position (API) ↔ sortOrder (Flutter entity)
|
|
/// - is_visible (API) ↔ isActive (Flutter entity)
|
|
@freezed
|
|
sealed class QuickLinkModel with _$QuickLinkModel {
|
|
const factory QuickLinkModel({
|
|
required int id,
|
|
required String title,
|
|
required String url,
|
|
String? icon,
|
|
String? description,
|
|
String? category,
|
|
@Default(0) int position,
|
|
@JsonKey(name: 'is_visible') @Default(true) bool isVisible,
|
|
String? color,
|
|
@JsonKey(name: 'background_color') String? backgroundColor,
|
|
}) = _QuickLinkModel;
|
|
|
|
const QuickLinkModel._();
|
|
|
|
factory QuickLinkModel.fromJson(Map<String, dynamic> json) =>
|
|
_$QuickLinkModelFromJson(json);
|
|
|
|
/// Converts to domain entity.
|
|
QuickLink toEntity() {
|
|
return QuickLink(
|
|
id: id.toString(),
|
|
name: title,
|
|
url: url,
|
|
iconName: icon ?? 'link',
|
|
category: category,
|
|
type: QuickLinkType.iframe,
|
|
sortOrder: position,
|
|
isActive: isVisible,
|
|
);
|
|
}
|
|
|
|
/// Creates model from domain entity.
|
|
factory QuickLinkModel.fromEntity(QuickLink entity) {
|
|
return QuickLinkModel(
|
|
id: int.tryParse(entity.id) ?? 0,
|
|
title: entity.name,
|
|
url: entity.url,
|
|
icon: entity.iconName,
|
|
category: entity.category,
|
|
position: entity.sortOrder,
|
|
isVisible: entity.isActive,
|
|
);
|
|
}
|
|
|
|
/// Creates a JSON map for creating a new quick link (without id).
|
|
Map<String, dynamic> toCreateJson() {
|
|
return {
|
|
'title': title,
|
|
'url': url,
|
|
if (icon != null) 'icon': icon,
|
|
if (description != null) 'description': description,
|
|
if (category != null) 'category': category,
|
|
'position': position,
|
|
'is_visible': isVisible,
|
|
if (color != null) 'color': color,
|
|
if (backgroundColor != null) 'background_color': backgroundColor,
|
|
};
|
|
}
|
|
}
|