Skip to content

Commit 0e03ac5

Browse files
author
serverpod_cloud
committed
feat: 4ec261630407a36f52aee3db88beb783d1baa02d
1 parent 42f704b commit 0e03ac5

14 files changed

Lines changed: 513 additions & 118 deletions

File tree

ground_control_client/lib/src/protocol/features/project/models/project.dart

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

1212
// ignore_for_file: no_leading_underscores_for_library_prefixes
1313
import 'package:serverpod_client/serverpod_client.dart' as _i1;
14-
import '../../../domains/billing/models/subscription.dart' as _i2;
15-
import '../../../features/project/models/role.dart' as _i3;
16-
import '../../../domains/capsules/models/capsule.dart' as _i4;
14+
import '../../../domains/billing/models/owner.dart' as _i2;
15+
import '../../../domains/billing/models/subscription.dart' as _i3;
16+
import '../../../features/project/models/role.dart' as _i4;
17+
import '../../../domains/capsules/models/capsule.dart' as _i5;
1718

1819
/// Represents a project of a tenant.
1920
/// Typically a serverpod project.
@@ -24,6 +25,8 @@ abstract class Project implements _i1.SerializableModel {
2425
DateTime? updatedAt,
2526
this.archivedAt,
2627
required this.cloudProjectId,
28+
required this.ownerId,
29+
this.owner,
2730
this.subscription,
2831
this.roles,
2932
this.capsules,
@@ -36,9 +39,11 @@ abstract class Project implements _i1.SerializableModel {
3639
DateTime? updatedAt,
3740
DateTime? archivedAt,
3841
required String cloudProjectId,
39-
_i2.Subscription? subscription,
40-
List<_i3.Role>? roles,
41-
List<_i4.Capsule>? capsules,
42+
required _i1.UuidValue ownerId,
43+
_i2.Owner? owner,
44+
_i3.Subscription? subscription,
45+
List<_i4.Role>? roles,
46+
List<_i5.Capsule>? capsules,
4247
}) = _ProjectImpl;
4348

4449
factory Project.fromJson(Map<String, dynamic> jsonSerialization) {
@@ -52,15 +57,21 @@ abstract class Project implements _i1.SerializableModel {
5257
? null
5358
: _i1.DateTimeJsonExtension.fromJson(jsonSerialization['archivedAt']),
5459
cloudProjectId: jsonSerialization['cloudProjectId'] as String,
60+
ownerId:
61+
_i1.UuidValueJsonExtension.fromJson(jsonSerialization['ownerId']),
62+
owner: jsonSerialization['owner'] == null
63+
? null
64+
: _i2.Owner.fromJson(
65+
(jsonSerialization['owner'] as Map<String, dynamic>)),
5566
subscription: jsonSerialization['subscription'] == null
5667
? null
57-
: _i2.Subscription.fromJson(
68+
: _i3.Subscription.fromJson(
5869
(jsonSerialization['subscription'] as Map<String, dynamic>)),
5970
roles: (jsonSerialization['roles'] as List?)
60-
?.map((e) => _i3.Role.fromJson((e as Map<String, dynamic>)))
71+
?.map((e) => _i4.Role.fromJson((e as Map<String, dynamic>)))
6172
.toList(),
6273
capsules: (jsonSerialization['capsules'] as List?)
63-
?.map((e) => _i4.Capsule.fromJson((e as Map<String, dynamic>)))
74+
?.map((e) => _i5.Capsule.fromJson((e as Map<String, dynamic>)))
6475
.toList(),
6576
);
6677
}
@@ -81,14 +92,20 @@ abstract class Project implements _i1.SerializableModel {
8192
/// This is the default production name of the project.
8293
String cloudProjectId;
8394

95+
/// The id of the owner of the project.
96+
_i1.UuidValue ownerId;
97+
98+
/// The owner of the project.
99+
_i2.Owner? owner;
100+
84101
/// The subscription for this project.
85-
_i2.Subscription? subscription;
102+
_i3.Subscription? subscription;
86103

87104
/// The roles for this project.
88-
List<_i3.Role>? roles;
105+
List<_i4.Role>? roles;
89106

90107
/// The capsules belonging to this project.
91-
List<_i4.Capsule>? capsules;
108+
List<_i5.Capsule>? capsules;
92109

93110
/// Returns a shallow copy of this [Project]
94111
/// with some or all fields replaced by the given arguments.
@@ -99,9 +116,11 @@ abstract class Project implements _i1.SerializableModel {
99116
DateTime? updatedAt,
100117
DateTime? archivedAt,
101118
String? cloudProjectId,
102-
_i2.Subscription? subscription,
103-
List<_i3.Role>? roles,
104-
List<_i4.Capsule>? capsules,
119+
_i1.UuidValue? ownerId,
120+
_i2.Owner? owner,
121+
_i3.Subscription? subscription,
122+
List<_i4.Role>? roles,
123+
List<_i5.Capsule>? capsules,
105124
});
106125
@override
107126
Map<String, dynamic> toJson() {
@@ -111,6 +130,8 @@ abstract class Project implements _i1.SerializableModel {
111130
'updatedAt': updatedAt.toJson(),
112131
if (archivedAt != null) 'archivedAt': archivedAt?.toJson(),
113132
'cloudProjectId': cloudProjectId,
133+
'ownerId': ownerId.toJson(),
134+
if (owner != null) 'owner': owner?.toJson(),
114135
if (subscription != null) 'subscription': subscription?.toJson(),
115136
if (roles != null) 'roles': roles?.toJson(valueToJson: (v) => v.toJson()),
116137
if (capsules != null)
@@ -133,15 +154,19 @@ class _ProjectImpl extends Project {
133154
DateTime? updatedAt,
134155
DateTime? archivedAt,
135156
required String cloudProjectId,
136-
_i2.Subscription? subscription,
137-
List<_i3.Role>? roles,
138-
List<_i4.Capsule>? capsules,
157+
required _i1.UuidValue ownerId,
158+
_i2.Owner? owner,
159+
_i3.Subscription? subscription,
160+
List<_i4.Role>? roles,
161+
List<_i5.Capsule>? capsules,
139162
}) : super._(
140163
id: id,
141164
createdAt: createdAt,
142165
updatedAt: updatedAt,
143166
archivedAt: archivedAt,
144167
cloudProjectId: cloudProjectId,
168+
ownerId: ownerId,
169+
owner: owner,
145170
subscription: subscription,
146171
roles: roles,
147172
capsules: capsules,
@@ -157,6 +182,8 @@ class _ProjectImpl extends Project {
157182
DateTime? updatedAt,
158183
Object? archivedAt = _Undefined,
159184
String? cloudProjectId,
185+
_i1.UuidValue? ownerId,
186+
Object? owner = _Undefined,
160187
Object? subscription = _Undefined,
161188
Object? roles = _Undefined,
162189
Object? capsules = _Undefined,
@@ -167,13 +194,15 @@ class _ProjectImpl extends Project {
167194
updatedAt: updatedAt ?? this.updatedAt,
168195
archivedAt: archivedAt is DateTime? ? archivedAt : this.archivedAt,
169196
cloudProjectId: cloudProjectId ?? this.cloudProjectId,
170-
subscription: subscription is _i2.Subscription?
197+
ownerId: ownerId ?? this.ownerId,
198+
owner: owner is _i2.Owner? ? owner : this.owner?.copyWith(),
199+
subscription: subscription is _i3.Subscription?
171200
? subscription
172201
: this.subscription?.copyWith(),
173-
roles: roles is List<_i3.Role>?
202+
roles: roles is List<_i4.Role>?
174203
? roles
175204
: this.roles?.map((e0) => e0.copyWith()).toList(),
176-
capsules: capsules is List<_i4.Capsule>?
205+
capsules: capsules is List<_i5.Capsule>?
177206
? capsules
178207
: this.capsules?.map((e0) => e0.copyWith()).toList(),
179208
);

ground_control_client/lib/src/test_tools/builders/billing/owner_builder.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:ground_control_client/ground_control_client.dart';
2+
import 'package:ground_control_client/ground_control_client_test_tools.dart';
23

34
class OwnerBuilder {
45
UuidValue? _id;
@@ -7,14 +8,16 @@ class OwnerBuilder {
78
List<String> _billingEmails;
89
BillingInfo? _billingInfo;
910
List<Project>? _projects;
11+
User? _user;
1012

1113
OwnerBuilder()
1214
: _id = Uuid().v4obj(),
1315
_externalBillingId = 'default-external-billing-id',
1416
_billingPortalUrl = Uri.parse('https://billing.example.com'),
1517
_billingEmails = [],
1618
_projects = [],
17-
_billingInfo = null;
19+
_billingInfo = null,
20+
_user = UserBuilder().build();
1821

1922
OwnerBuilder withId(UuidValue id) {
2023
_id = id;
@@ -62,13 +65,19 @@ class OwnerBuilder {
6265
return this;
6366
}
6467

68+
OwnerBuilder withUser(User user) {
69+
_user = user;
70+
return this;
71+
}
72+
6573
Owner build() {
6674
return Owner(
6775
id: _id,
6876
externalBillingId: _externalBillingId,
6977
billingPortalUrl: _billingPortalUrl,
7078
billingEmails: _billingEmails,
7179
billingInfo: _billingInfo,
80+
user: _user,
7281
projects: _projects,
7382
);
7483
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
export 'billing/owner_builder.dart';
22
export 'billing/billing_info_builder.dart';
3+
export 'role_builder.dart';
4+
export 'project_builder.dart';
5+
export 'user_builder.dart';
6+
export 'user_role_membership_builder.dart';
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import 'package:ground_control_client/ground_control_client.dart';
2+
import 'package:ground_control_client/ground_control_client_test_tools.dart';
3+
4+
class ProjectBuilder {
5+
int _id;
6+
DateTime _createdAt;
7+
DateTime? _updatedAt;
8+
DateTime? _archivedAt;
9+
String _cloudProjectId;
10+
Owner? _owner;
11+
Subscription? _subscription;
12+
List<Role>? _roles;
13+
List<Capsule>? _capsules;
14+
15+
ProjectBuilder()
16+
: _id = 1,
17+
_createdAt = DateTime.now(),
18+
_updatedAt = DateTime.now(),
19+
_archivedAt = null,
20+
_cloudProjectId = 'test-project',
21+
_subscription = null,
22+
_roles = [],
23+
_capsules = [] {
24+
withUserOwner(UserBuilder().build());
25+
}
26+
27+
/// Creates a project with a user as owner and admin role.
28+
/// Calling this method resets the roles in the builder.
29+
ProjectBuilder withUserOwner(final User user) {
30+
_owner = OwnerBuilder().withUser(user).build();
31+
_roles = [
32+
RoleBuilder.admin().withUser(user).build(),
33+
];
34+
return this;
35+
}
36+
37+
ProjectBuilder withDeveloperUser(final User user) {
38+
_roles ??= [];
39+
_roles?.add(
40+
RoleBuilder().withName('Developer').withUser(user).build(),
41+
);
42+
return this;
43+
}
44+
45+
ProjectBuilder withId(final int id) {
46+
_id = id;
47+
return this;
48+
}
49+
50+
ProjectBuilder withCreatedAt(final DateTime createdAt) {
51+
_createdAt = createdAt;
52+
return this;
53+
}
54+
55+
ProjectBuilder withUpdatedAt(final DateTime? updatedAt) {
56+
_updatedAt = updatedAt;
57+
return this;
58+
}
59+
60+
ProjectBuilder withArchivedAt(final DateTime? archivedAt) {
61+
_archivedAt = archivedAt;
62+
return this;
63+
}
64+
65+
ProjectBuilder withCloudProjectId(final String cloudProjectId) {
66+
_cloudProjectId = cloudProjectId;
67+
return this;
68+
}
69+
70+
ProjectBuilder withOwner(final Owner? owner) {
71+
_owner = owner;
72+
return this;
73+
}
74+
75+
ProjectBuilder withSubscription(final Subscription? subscription) {
76+
_subscription = subscription;
77+
return this;
78+
}
79+
80+
ProjectBuilder withRoles(final List<Role>? roles) {
81+
_roles = roles;
82+
return this;
83+
}
84+
85+
ProjectBuilder withCapsules(final List<Capsule>? capsules) {
86+
_capsules = capsules;
87+
return this;
88+
}
89+
90+
Project build() {
91+
return Project(
92+
id: _id,
93+
createdAt: _createdAt,
94+
updatedAt: _updatedAt,
95+
archivedAt: _archivedAt,
96+
cloudProjectId: _cloudProjectId,
97+
owner: _owner,
98+
ownerId: _owner?.id ?? Uuid().v4obj(),
99+
subscription: _subscription,
100+
roles: _roles,
101+
capsules: _capsules,
102+
);
103+
}
104+
}

0 commit comments

Comments
 (0)