Skip to content

Commit

Permalink
feat: add models for organizations and organization api responses. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanoltman authored Sep 26, 2024
1 parent 469912d commit 20f2641
Show file tree
Hide file tree
Showing 25 changed files with 616 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'get_organization_apps_response.dart';
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;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'get_organization_users_response.dart';
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;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'get_organizations_response.dart';
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;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export 'create_release/create_release.dart';
export 'create_release_artifact/create_release_artifact.dart';
export 'create_user/create_user.dart';
export 'get_apps/get_apps.dart';
export 'get_organization_apps/get_organization_apps.dart';
export 'get_organization_users/get_organization_users.dart';
export 'get_organizations/get_organizations.dart';
export 'get_release_artifacts/get_release_artifacts.dart';
export 'get_release_patches/get_release_patches.dart';
export 'get_releases/get_releases.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export 'app_metadata.dart';
export 'auth_provider.dart';
export 'channel.dart';
export 'error_response.dart';
export 'organization.dart';
export 'organization_membership.dart';
export 'organization_user.dart';
export 'patch.dart';
export 'patch_artifact.dart';
export 'plan.dart';
Expand Down
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;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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;
}
Loading

0 comments on commit 20f2641

Please sign in to comment.