Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
feat: update templates to include imports (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
wesbillman authored Nov 10, 2023
1 parent b1beace commit 360cee3
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 12 deletions.
6 changes: 5 additions & 1 deletion frontend/mobile/lib/api/ad.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: unused_import
library ad;

import 'dart:convert';
Expand Down Expand Up @@ -52,18 +53,21 @@ class Ad {
}

class AdResponse {
String name;
List<Ad> ads;

AdResponse({ required this.ads, });
AdResponse({ required this.name, required this.ads, });

Map<String, dynamic> toMap() {
return {
'name': ((dynamic v) =>v)(name),
'ads': ((dynamic v) =>v.map((v) => Ad.fromMap(v)).cast<Ad>().toList())(ads),
};
}

factory AdResponse.fromMap(Map<String, dynamic> map) {
return AdResponse(
name: ((dynamic v) => v)(map['name']),
ads: ((dynamic v) => v.map((v) => Ad.fromMap(v)).cast<Ad>().toList())(map['ads']),
);
}
Expand Down
3 changes: 2 additions & 1 deletion frontend/mobile/lib/api/cart.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
library ad;
// ignore_for_file: unused_import
library cart;

import 'dart:convert';
import 'ftl_client.dart';
Expand Down
8 changes: 7 additions & 1 deletion frontend/mobile/lib/api/checkout.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
library ad;
// ignore_for_file: unused_import
library checkout;

import 'dart:convert';
import 'ftl_client.dart';
import 'productcatalog.dart' as productcatalog;
import 'currency.dart' as currency;
import 'shipping.dart' as shipping;
import 'payment.dart' as payment;
import 'cart.dart' as cart;


class Address {
Expand Down
3 changes: 2 additions & 1 deletion frontend/mobile/lib/api/currency.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
library ad;
// ignore_for_file: unused_import
library currency;

import 'dart:convert';
import 'ftl_client.dart';
Expand Down
3 changes: 2 additions & 1 deletion frontend/mobile/lib/api/payment.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
library ad;
// ignore_for_file: unused_import
library payment;

import 'dart:convert';
import 'ftl_client.dart';
Expand Down
3 changes: 2 additions & 1 deletion frontend/mobile/lib/api/productcatalog.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
library ad;
// ignore_for_file: unused_import
library productcatalog;

import 'dart:convert';
import 'ftl_client.dart';
Expand Down
4 changes: 3 additions & 1 deletion frontend/mobile/lib/api/recommendation.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
library ad;
// ignore_for_file: unused_import
library recommendation;

import 'dart:convert';
import 'ftl_client.dart';
import 'productcatalog.dart' as productcatalog;


class ListRequest {
Expand Down
3 changes: 2 additions & 1 deletion frontend/mobile/lib/api/shipping.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
library ad;
// ignore_for_file: unused_import
library shipping;

import 'dart:convert';
import 'ftl_client.dart';
Expand Down
15 changes: 11 additions & 4 deletions frontend/mobile/templates/{{ .Name | lower }}.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
library ad;
// ignore_for_file: unused_import
library {{ .Name | lower }};

import 'dart:convert';
import 'ftl_client.dart';
{{- range .Imports}}
import '{{. | lower }}.dart' as {{. | lower}};
{{- end}}

{{- define "darttype" -}}
{{- $type := (. | typename ) -}}
{{- if eq $type "Array" }}List<{{ template "darttype" .Element }}>
{{- else if eq $type "Map" }}Map<{{ template "darttype" .Key }}, {{ template "darttype" .Value }}>
{{- else if eq $type "DataRef" }}{{ . }}
{{- else if eq $type "Int" }}int
{{- else if eq $type "Bool" }}bool
{{- else if eq $type "Float" }}double
{{- else if eq $type "Time" }}DateTime
{{- else -}}{{ . | typename }}{{- end -}}
{{- end }}

Expand All @@ -17,9 +24,9 @@ import 'ftl_client.dart';
{{- if eq $type "Array" -}}
v.map((v) => {{ template "deserialize" .Element }}).cast<{{ template "darttype" .Element }}>().toList()
{{- else if eq $type "Map" -}}
v.map((k, v) => MapEntry(k, {{ template "deserialize" .Value }})),
v.map((k, v) => MapEntry(k, {{ template "deserialize" .Value }})).cast<{{ template "darttype" .Key }}, {{ template "darttype" .Value }}>()
{{- else if eq $type "DataRef" -}}
{{ .Name }}.fromMap(v)
{{ . }}.fromMap(v)
{{- else -}}
v
{{- end }}
Expand All @@ -30,7 +37,7 @@ v
{{- if eq $type "Array" -}}
v.map((v) => {{ template "deserialize" .Element }}).cast<{{ template "darttype" .Element }}>().toList()
{{- else if eq $type "Map" -}}
v.map((k, v) => MapEntry(k, {{ template "deserialize" .Value }})),
v.map((k, v) => MapEntry(k, {{ template "deserialize" .Value }})).cast<{{ template "darttype" .Key }}, {{ template "darttype" .Value }}>()
{{- else if eq $type "DataRef" -}}
v.toMap()
{{- else -}}
Expand Down

0 comments on commit 360cee3

Please sign in to comment.