Skip to content

Commit 7bdb952

Browse files
committed
API Call Action #1
- Add api call action.
1 parent 5a27446 commit 7bdb952

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+140
-7
lines changed

lib/src/api/models/action/action.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ enum ActionType {
2626
setVariant,
2727

2828
/// Call a custom function.
29-
callFunction;
29+
callFunction,
30+
31+
/// Call an API.
32+
callApi;
3033

3134
/// Displayable string representation of the [ActionType].
3235
String get prettify {
@@ -43,6 +46,8 @@ enum ActionType {
4346
return 'Set Variant';
4447
case ActionType.callFunction:
4548
return 'Call Function';
49+
case ActionType.callApi:
50+
return 'Call API';
4651
}
4752
}
4853
}

lib/src/api/models/action/action.g.dart

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import 'package:equatable/equatable.dart';
2+
import 'package:json_annotation/json_annotation.dart';
3+
4+
import '../../mixins.dart';
5+
import 'action.dart';
6+
7+
part 'api_call_action.g.dart';
8+
9+
/// Holds information about an API call action to perform on a user interaction.
10+
@JsonSerializable()
11+
class ApiCallAction extends ActionModel with EquatableMixin, SerializableMixin {
12+
/// ID of the API to call.
13+
final String? apiId;
14+
15+
/// Parameters to pass to the API.
16+
final Map<String, String> parameters;
17+
18+
/// Creates an [ApiCallAction] with the given data.
19+
ApiCallAction({
20+
this.apiId,
21+
Map<String, String>? parameters,
22+
}) : parameters = parameters ?? {},
23+
super(type: ActionType.callApi);
24+
25+
@override
26+
List<Object?> get props => [apiId, parameters];
27+
28+
/// Creates a copy of this [ApiCallAction] but with the given fields replaced
29+
/// with the new values.
30+
ApiCallAction copyWith({
31+
String? apiId,
32+
Map<String, String>? parameters,
33+
}) =>
34+
ApiCallAction(
35+
apiId: apiId ?? this.apiId,
36+
parameters: parameters ?? this.parameters,
37+
);
38+
39+
/// Creates a new [ApiCallAction] from a JSON object.
40+
factory ApiCallAction.fromJson(Map json) => _$ApiCallActionFromJson(json);
41+
42+
@override
43+
Map toJson() => _$ApiCallActionToJson(this);
44+
}

lib/src/api/models/action/api_call_action.g.dart

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/api/models/action/call_function_action.g.dart

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/api/models/action/link_action.g.dart

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/api/models/action/navigation_action.g.dart

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/api/models/action/set_value_action.g.dart

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/api/models/action/set_variant_action.g.dart

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/api/models/action/submit_action.g.dart

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)