feat: add AI recommendations flow for tenders

Implement company AI onboarding/recommendation models, services, repository, and tender UI integration with supporting tests.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
AmirReza Jamali
2026-06-16 11:47:52 +03:30
parent 83b32549ce
commit 50e4f43738
34 changed files with 2558 additions and 112 deletions
@@ -0,0 +1,27 @@
// ignore_for_file: invalid_annotation_target
import 'package:freezed_annotation/freezed_annotation.dart';
import '../error/error_model.dart';
import '../recommendation_item/recommendation_item.dart';
part 'recommend_response.freezed.dart';
part 'recommend_response.g.dart';
/// Standard API envelope for `POST /api/v1/recommend`.
///
/// [data] holds the ranked recommendations and may be empty (or null) until
/// the AI service finishes indexing the company.
@freezed
abstract class RecommendResponse with _$RecommendResponse {
@JsonSerializable(explicitToJson: true)
const factory RecommendResponse({
@JsonKey(name: 'data') required List<RecommendationItem>? data,
@JsonKey(name: 'error') required ErrorModel? error,
required String? message,
required bool? success,
}) = _RecommendResponse;
factory RecommendResponse.fromJson(Map<String, dynamic> json) =>
_$RecommendResponseFromJson(json);
}
@@ -0,0 +1,318 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// coverage:ignore-file
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'recommend_response.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$RecommendResponse {
@JsonKey(name: 'data') List<RecommendationItem>? get data;@JsonKey(name: 'error') ErrorModel? get error; String? get message; bool? get success;
/// Create a copy of RecommendResponse
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$RecommendResponseCopyWith<RecommendResponse> get copyWith => _$RecommendResponseCopyWithImpl<RecommendResponse>(this as RecommendResponse, _$identity);
/// Serializes this RecommendResponse to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is RecommendResponse&&const DeepCollectionEquality().equals(other.data, data)&&(identical(other.error, error) || other.error == error)&&(identical(other.message, message) || other.message == message)&&(identical(other.success, success) || other.success == success));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(data),error,message,success);
@override
String toString() {
return 'RecommendResponse(data: $data, error: $error, message: $message, success: $success)';
}
}
/// @nodoc
abstract mixin class $RecommendResponseCopyWith<$Res> {
factory $RecommendResponseCopyWith(RecommendResponse value, $Res Function(RecommendResponse) _then) = _$RecommendResponseCopyWithImpl;
@useResult
$Res call({
@JsonKey(name: 'data') List<RecommendationItem>? data,@JsonKey(name: 'error') ErrorModel? error, String? message, bool? success
});
$ErrorModelCopyWith<$Res>? get error;
}
/// @nodoc
class _$RecommendResponseCopyWithImpl<$Res>
implements $RecommendResponseCopyWith<$Res> {
_$RecommendResponseCopyWithImpl(this._self, this._then);
final RecommendResponse _self;
final $Res Function(RecommendResponse) _then;
/// Create a copy of RecommendResponse
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? data = freezed,Object? error = freezed,Object? message = freezed,Object? success = freezed,}) {
return _then(_self.copyWith(
data: freezed == data ? _self.data : data // ignore: cast_nullable_to_non_nullable
as List<RecommendationItem>?,error: freezed == error ? _self.error : error // ignore: cast_nullable_to_non_nullable
as ErrorModel?,message: freezed == message ? _self.message : message // ignore: cast_nullable_to_non_nullable
as String?,success: freezed == success ? _self.success : success // ignore: cast_nullable_to_non_nullable
as bool?,
));
}
/// Create a copy of RecommendResponse
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$ErrorModelCopyWith<$Res>? get error {
if (_self.error == null) {
return null;
}
return $ErrorModelCopyWith<$Res>(_self.error!, (value) {
return _then(_self.copyWith(error: value));
});
}
}
/// Adds pattern-matching-related methods to [RecommendResponse].
extension RecommendResponsePatterns on RecommendResponse {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _RecommendResponse value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _RecommendResponse() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _RecommendResponse value) $default,){
final _that = this;
switch (_that) {
case _RecommendResponse():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _RecommendResponse value)? $default,){
final _that = this;
switch (_that) {
case _RecommendResponse() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function(@JsonKey(name: 'data') List<RecommendationItem>? data, @JsonKey(name: 'error') ErrorModel? error, String? message, bool? success)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _RecommendResponse() when $default != null:
return $default(_that.data,_that.error,_that.message,_that.success);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function(@JsonKey(name: 'data') List<RecommendationItem>? data, @JsonKey(name: 'error') ErrorModel? error, String? message, bool? success) $default,) {final _that = this;
switch (_that) {
case _RecommendResponse():
return $default(_that.data,_that.error,_that.message,_that.success);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function(@JsonKey(name: 'data') List<RecommendationItem>? data, @JsonKey(name: 'error') ErrorModel? error, String? message, bool? success)? $default,) {final _that = this;
switch (_that) {
case _RecommendResponse() when $default != null:
return $default(_that.data,_that.error,_that.message,_that.success);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable(explicitToJson: true)
class _RecommendResponse implements RecommendResponse {
const _RecommendResponse({@JsonKey(name: 'data') required final List<RecommendationItem>? data, @JsonKey(name: 'error') required this.error, required this.message, required this.success}): _data = data;
factory _RecommendResponse.fromJson(Map<String, dynamic> json) => _$RecommendResponseFromJson(json);
final List<RecommendationItem>? _data;
@override@JsonKey(name: 'data') List<RecommendationItem>? get data {
final value = _data;
if (value == null) return null;
if (_data is EqualUnmodifiableListView) return _data;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(value);
}
@override@JsonKey(name: 'error') final ErrorModel? error;
@override final String? message;
@override final bool? success;
/// Create a copy of RecommendResponse
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$RecommendResponseCopyWith<_RecommendResponse> get copyWith => __$RecommendResponseCopyWithImpl<_RecommendResponse>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$RecommendResponseToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _RecommendResponse&&const DeepCollectionEquality().equals(other._data, _data)&&(identical(other.error, error) || other.error == error)&&(identical(other.message, message) || other.message == message)&&(identical(other.success, success) || other.success == success));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(_data),error,message,success);
@override
String toString() {
return 'RecommendResponse(data: $data, error: $error, message: $message, success: $success)';
}
}
/// @nodoc
abstract mixin class _$RecommendResponseCopyWith<$Res> implements $RecommendResponseCopyWith<$Res> {
factory _$RecommendResponseCopyWith(_RecommendResponse value, $Res Function(_RecommendResponse) _then) = __$RecommendResponseCopyWithImpl;
@override @useResult
$Res call({
@JsonKey(name: 'data') List<RecommendationItem>? data,@JsonKey(name: 'error') ErrorModel? error, String? message, bool? success
});
@override $ErrorModelCopyWith<$Res>? get error;
}
/// @nodoc
class __$RecommendResponseCopyWithImpl<$Res>
implements _$RecommendResponseCopyWith<$Res> {
__$RecommendResponseCopyWithImpl(this._self, this._then);
final _RecommendResponse _self;
final $Res Function(_RecommendResponse) _then;
/// Create a copy of RecommendResponse
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? data = freezed,Object? error = freezed,Object? message = freezed,Object? success = freezed,}) {
return _then(_RecommendResponse(
data: freezed == data ? _self._data : data // ignore: cast_nullable_to_non_nullable
as List<RecommendationItem>?,error: freezed == error ? _self.error : error // ignore: cast_nullable_to_non_nullable
as ErrorModel?,message: freezed == message ? _self.message : message // ignore: cast_nullable_to_non_nullable
as String?,success: freezed == success ? _self.success : success // ignore: cast_nullable_to_non_nullable
as bool?,
));
}
/// Create a copy of RecommendResponse
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$ErrorModelCopyWith<$Res>? get error {
if (_self.error == null) {
return null;
}
return $ErrorModelCopyWith<$Res>(_self.error!, (value) {
return _then(_self.copyWith(error: value));
});
}
}
// dart format on
@@ -0,0 +1,31 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'recommend_response.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_RecommendResponse _$RecommendResponseFromJson(Map<String, dynamic> json) =>
_RecommendResponse(
data:
(json['data'] as List<dynamic>?)
?.map(
(e) => RecommendationItem.fromJson(e as Map<String, dynamic>),
)
.toList(),
error:
json['error'] == null
? null
: ErrorModel.fromJson(json['error'] as Map<String, dynamic>),
message: json['message'] as String?,
success: json['success'] as bool?,
);
Map<String, dynamic> _$RecommendResponseToJson(_RecommendResponse instance) =>
<String, dynamic>{
'data': instance.data?.map((e) => e.toJson()).toList(),
'error': instance.error?.toJson(),
'message': instance.message,
'success': instance.success,
};