-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add models for organizations and organization api responses. (#…
- Loading branch information
1 parent
469912d
commit 20f2641
Showing
25 changed files
with
616 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...bird_code_push_protocol/lib/src/messages/get_organization_apps/get_organization_apps.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export 'get_organization_apps_response.dart'; |
27 changes: 27 additions & 0 deletions
27
..._push_protocol/lib/src/messages/get_organization_apps/get_organization_apps_response.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; | ||
|
||
part 'get_organization_apps_response.g.dart'; | ||
|
||
/// {@template get_organization_apps_request} | ||
/// A list of apps that belong to an organization. | ||
/// | ||
/// Body of GET /api/v1/organizations/:organizationId/apps | ||
/// {@endtemplate} | ||
@JsonSerializable() | ||
class GetOrganizationAppsResponse { | ||
/// {@macro get_organization_apps_request} | ||
GetOrganizationAppsResponse({ | ||
required this.apps, | ||
}); | ||
|
||
/// Deserializes the [GetOrganizationAppsResponse] from a JSON map. | ||
factory GetOrganizationAppsResponse.fromJson(Map<String, dynamic> json) => | ||
_$GetOrganizationAppsResponseFromJson(json); | ||
|
||
/// Converts this [GetOrganizationAppsResponse] to a JSON map. | ||
Map<String, dynamic> toJson() => _$GetOrganizationAppsResponseToJson(this); | ||
|
||
/// The apps that belong to the organization. | ||
final List<AppMetadata> apps; | ||
} |
32 changes: 32 additions & 0 deletions
32
...ush_protocol/lib/src/messages/get_organization_apps/get_organization_apps_response.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...rd_code_push_protocol/lib/src/messages/get_organization_users/get_organization_users.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export 'get_organization_users_response.dart'; |
29 changes: 29 additions & 0 deletions
29
...ush_protocol/lib/src/messages/get_organization_users/get_organization_users_response.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
import 'package:shorebird_code_push_protocol/src/models/models.dart'; | ||
|
||
part 'get_organization_users_response.g.dart'; | ||
|
||
/// {@template get_organization_users_request} | ||
/// A list of users that belong to an organization, as well as their roles in | ||
/// the organization. | ||
/// | ||
/// The body of GET /api/v1/organizations/:organizationId/users | ||
/// {@endtemplate} | ||
@JsonSerializable() | ||
class GetOrganizationUsersResponse { | ||
/// {@macro get_organization_users_request} | ||
GetOrganizationUsersResponse({ | ||
required this.users, | ||
}); | ||
|
||
/// Deserializes the [GetOrganizationUsersResponse] from a JSON map. | ||
factory GetOrganizationUsersResponse.fromJson(Map<String, dynamic> json) => | ||
_$GetOrganizationUsersResponseFromJson(json); | ||
|
||
/// Converts this [GetOrganizationUsersResponse] to a JSON map. | ||
Map<String, dynamic> toJson() => _$GetOrganizationUsersResponseToJson(this); | ||
|
||
/// The list of users that belong to the organization, as well as their roles | ||
/// in the organization. | ||
final List<OrganizationUser> users; | ||
} |
33 changes: 33 additions & 0 deletions
33
...h_protocol/lib/src/messages/get_organization_users/get_organization_users_response.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...es/shorebird_code_push_protocol/lib/src/messages/get_organizations/get_organizations.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export 'get_organizations_response.dart'; |
28 changes: 28 additions & 0 deletions
28
...ird_code_push_protocol/lib/src/messages/get_organizations/get_organizations_response.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; | ||
|
||
part 'get_organizations_response.g.dart'; | ||
|
||
/// {@template get_organizations_request} | ||
/// A list of organizations the currently logged in user is a member of. | ||
/// | ||
/// Body of /api/v1/organizations. | ||
/// {@endtemplate} | ||
@JsonSerializable() | ||
class GetOrganizationsResponse { | ||
/// {@macro get_organizations_request} | ||
GetOrganizationsResponse({ | ||
required this.organizations, | ||
}); | ||
|
||
/// Deserializes the [GetOrganizationsResponse] from a JSON map. | ||
factory GetOrganizationsResponse.fromJson(Map<String, dynamic> json) => | ||
_$GetOrganizationsResponseFromJson(json); | ||
|
||
/// Converts this [GetOrganizationsResponse] to a JSON map. | ||
Map<String, dynamic> toJson() => _$GetOrganizationsResponseToJson(this); | ||
|
||
/// Organizations that the user is a member of, as well as this user's role in | ||
/// each organization. | ||
final List<OrganizationMembership> organizations; | ||
} |
33 changes: 33 additions & 0 deletions
33
...d_code_push_protocol/lib/src/messages/get_organizations/get_organizations_response.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
packages/shorebird_code_push_protocol/lib/src/models/organization.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
import 'package:meta/meta.dart'; | ||
|
||
part 'organization.g.dart'; | ||
|
||
/// {@template organization_role} | ||
/// A role that a user can have in an organization. | ||
/// {@endtemplate} | ||
enum OrganizationRole { | ||
/// User that created the organization. | ||
owner, | ||
|
||
/// Users who have permissions to manage the organization. | ||
admin, | ||
|
||
/// Users who are part of the organization but have limited permissions. | ||
member; | ||
} | ||
|
||
/// {@template organization_type} | ||
/// Distinguishes between automatically created organizations that are limited | ||
/// to a single user and organizations that support multiple users. | ||
/// {@endtemplate} | ||
enum OrganizationType { | ||
/// A personal organization is created for every user for their own apps. | ||
personal, | ||
|
||
/// A team organization is created for multiple users to collaborate on apps. | ||
team; | ||
} | ||
|
||
/// {@template organization} | ||
/// An Organization groups users and apps together. Organizations can be | ||
/// personal (single-user) or team (multi-user). An Organization with a | ||
/// [stripeCustomerId] may have a subscription. | ||
/// {@endtemplate} | ||
@JsonSerializable() | ||
class Organization { | ||
/// {@macro organization} | ||
const Organization({ | ||
required this.id, | ||
required this.name, | ||
required this.organizationType, | ||
required this.stripeCustomerId, | ||
required this.createdAt, | ||
required this.updatedAt, | ||
}); | ||
|
||
/// Converts a [Map<String, dynamic>] to an [Organization]. | ||
factory Organization.fromJson(Map<String, dynamic> json) => | ||
_$OrganizationFromJson(json); | ||
|
||
// coverage:ignore-start | ||
/// Constructs an organization with arbitrary default values for testing. | ||
@visibleForTesting | ||
factory Organization.forTest({ | ||
int id = 42, | ||
String name = 'Test Organization', | ||
OrganizationType organizationType = OrganizationType.personal, | ||
String? stripeCustomerId, | ||
DateTime? createdAt, | ||
DateTime? updatedAt, | ||
}) => | ||
Organization( | ||
id: id, | ||
name: name, | ||
organizationType: organizationType, | ||
stripeCustomerId: stripeCustomerId, | ||
createdAt: createdAt ?? DateTime.now(), | ||
updatedAt: updatedAt ?? DateTime.now(), | ||
); | ||
// coverage:ignore-end | ||
|
||
/// Converts this [Organization] to a JSON map | ||
Map<String, dynamic> toJson() => _$OrganizationToJson(this); | ||
|
||
/// The unique identifier for the organization. | ||
final int id; | ||
|
||
/// The name of the organization. | ||
final String name; | ||
|
||
/// The type of organization. | ||
final OrganizationType organizationType; | ||
|
||
/// The Stripe customer ID for the organization, if one exists. | ||
final String? stripeCustomerId; | ||
|
||
/// When this organization was created. | ||
final DateTime createdAt; | ||
|
||
/// When this organization was last updated. | ||
final DateTime updatedAt; | ||
} |
52 changes: 52 additions & 0 deletions
52
packages/shorebird_code_push_protocol/lib/src/models/organization.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
packages/shorebird_code_push_protocol/lib/src/models/organization_membership.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
import 'package:shorebird_code_push_protocol/src/models/organization.dart'; | ||
|
||
part 'organization_membership.g.dart'; | ||
|
||
/// {@template organization_membership} | ||
/// An organization and the current user's role in that organization. | ||
/// {@endtemplate} | ||
@JsonSerializable() | ||
class OrganizationMembership { | ||
/// {@macro organization_membership} | ||
OrganizationMembership({ | ||
required this.organization, | ||
required this.role, | ||
}); | ||
|
||
/// Deserializes the [OrganizationMembership] from aJSON map. | ||
factory OrganizationMembership.fromJson(Map<String, dynamic> json) => | ||
_$OrganizationMembershipFromJson(json); | ||
|
||
/// Serializes the [OrganizationMembership] to a JSON map. | ||
Map<String, dynamic> toJson() => _$OrganizationMembershipToJson(this); | ||
|
||
/// The organization. | ||
final Organization organization; | ||
|
||
/// The user's role in the organization. | ||
final OrganizationRole role; | ||
} |
Oops, something went wrong.