From 2710c7f5b623b321ef4a9ac38243ffbe364344d0 Mon Sep 17 00:00:00 2001 From: Rob Becker Date: Fri, 7 Jan 2022 08:44:35 -0600 Subject: [PATCH 1/3] Fix getting gists --- lib/src/common/model/gists.dart | 18 ++++---- lib/src/common/model/gists.g.dart | 50 +++++++++++++++++++++-- lib/src/common/model/misc.dart | 3 +- lib/src/common/model/misc.g.dart | 6 +++ lib/src/common/model/notifications.dart | 6 ++- lib/src/common/model/notifications.g.dart | 22 ++++++++++ lib/src/common/model/orgs.dart | 9 ++-- lib/src/common/model/orgs.g.dart | 26 ++++++++++++ lib/src/common/model/repos.dart | 10 ++--- lib/src/common/model/repos.g.dart | 17 ++++++++ lib/src/common/model/search.dart | 10 +++-- lib/src/common/model/search.g.dart | 18 ++++++++ lib/src/common/model/users.dart | 5 +-- lib/src/common/model/users.g.dart | 10 +++++ 14 files changed, 179 insertions(+), 31 deletions(-) diff --git a/lib/src/common/model/gists.dart b/lib/src/common/model/gists.dart index dc225eb4..cd89deac 100644 --- a/lib/src/common/model/gists.dart +++ b/lib/src/common/model/gists.dart @@ -5,7 +5,7 @@ import 'package:json_annotation/json_annotation.dart'; part 'gists.g.dart'; /// Model class for gists. -@JsonSerializable(createToJson: false) +@JsonSerializable() class Gist { Gist({ this.id, @@ -26,7 +26,7 @@ class Gist { bool? public; User? owner; User? user; - List? files; + Map? files; @JsonKey(name: 'html_url') String? htmlUrl; @@ -50,10 +50,10 @@ class Gist { } /// Model class for a gist file. -@JsonSerializable(createToJson: false) +@JsonSerializable() class GistFile { GistFile({ - this.name, + this.filename, this.size, this.rawUrl, this.type, @@ -61,10 +61,9 @@ class GistFile { this.truncated, this.content, }); - String? name; - int? size; - @JsonKey(name: 'raw_url') + String? filename; + int? size; String? rawUrl; String? type; String? language; @@ -73,10 +72,11 @@ class GistFile { factory GistFile.fromJson(Map input) => _$GistFileFromJson(input); + Map toJson() => _$GistFileToJson(this); } /// Model class for a gist fork. -@JsonSerializable(createToJson: false) +@JsonSerializable() class GistFork { GistFork({this.user, this.id, this.createdAt, this.updatedAt}); User? user; @@ -93,7 +93,7 @@ class GistFork { } /// Model class for a gits history entry. -@JsonSerializable(createToJson: false) +@JsonSerializable() class GistHistoryEntry { GistHistoryEntry({ this.version, diff --git a/lib/src/common/model/gists.g.dart b/lib/src/common/model/gists.g.dart index 15f648b0..e1d6db23 100644 --- a/lib/src/common/model/gists.g.dart +++ b/lib/src/common/model/gists.g.dart @@ -16,9 +16,9 @@ Gist _$GistFromJson(Map json) => Gist( user: json['user'] == null ? null : User.fromJson(json['user'] as Map), - files: (json['files'] as List?) - ?.map((e) => GistFile.fromJson(e as Map)) - .toList(), + files: (json['files'] as Map?)?.map( + (k, e) => MapEntry(k, GistFile.fromJson(e as Map)), + ), htmlUrl: json['html_url'] as String?, commentsCount: json['comments'] as int?, gitPullUrl: json['git_pull_url'] as String?, @@ -31,8 +31,23 @@ Gist _$GistFromJson(Map json) => Gist( : DateTime.parse(json['updated_at'] as String), ); +Map _$GistToJson(Gist instance) => { + 'id': instance.id, + 'description': instance.description, + 'public': instance.public, + 'owner': instance.owner, + 'user': instance.user, + 'files': instance.files, + 'html_url': instance.htmlUrl, + 'comments': instance.commentsCount, + 'git_pull_url': instance.gitPullUrl, + 'git_push_url': instance.gitPushUrl, + 'created_at': instance.createdAt?.toIso8601String(), + 'updated_at': instance.updatedAt?.toIso8601String(), + }; + GistFile _$GistFileFromJson(Map json) => GistFile( - name: json['name'] as String?, + filename: json['filename'] as String?, size: json['size'] as int?, rawUrl: json['raw_url'] as String?, type: json['type'] as String?, @@ -41,6 +56,16 @@ GistFile _$GistFileFromJson(Map json) => GistFile( content: json['content'] as String?, ); +Map _$GistFileToJson(GistFile instance) => { + 'filename': instance.filename, + 'size': instance.size, + 'raw_url': instance.rawUrl, + 'type': instance.type, + 'language': instance.language, + 'truncated': instance.truncated, + 'content': instance.content, + }; + GistFork _$GistForkFromJson(Map json) => GistFork( user: json['user'] == null ? null @@ -54,6 +79,13 @@ GistFork _$GistForkFromJson(Map json) => GistFork( : DateTime.parse(json['updated_at'] as String), ); +Map _$GistForkToJson(GistFork instance) => { + 'user': instance.user, + 'id': instance.id, + 'created_at': instance.createdAt?.toIso8601String(), + 'updated_at': instance.updatedAt?.toIso8601String(), + }; + GistHistoryEntry _$GistHistoryEntryFromJson(Map json) => GistHistoryEntry( version: json['version'] as String?, @@ -68,6 +100,16 @@ GistHistoryEntry _$GistHistoryEntryFromJson(Map json) => : DateTime.parse(json['committed_at'] as String), ); +Map _$GistHistoryEntryToJson(GistHistoryEntry instance) => + { + 'version': instance.version, + 'user': instance.user, + 'change_status/deletions': instance.deletions, + 'change_status/additions': instance.additions, + 'change_status/total': instance.totalChanges, + 'committed_at': instance.committedAt?.toIso8601String(), + }; + GistComment _$GistCommentFromJson(Map json) => GistComment( id: json['id'] as int?, user: json['user'] == null diff --git a/lib/src/common/model/misc.dart b/lib/src/common/model/misc.dart index 4f3166a9..ad693d34 100644 --- a/lib/src/common/model/misc.dart +++ b/lib/src/common/model/misc.dart @@ -3,7 +3,7 @@ import 'package:json_annotation/json_annotation.dart'; part 'misc.g.dart'; /// Model class for a Gitignore Template. -@JsonSerializable(createToJson: false) +@JsonSerializable() class GitignoreTemplate { GitignoreTemplate({this.name, this.source}); @@ -15,6 +15,7 @@ class GitignoreTemplate { factory GitignoreTemplate.fromJson(Map input) => _$GitignoreTemplateFromJson(input); + Map toJson() => _$GitignoreTemplateToJson(this); } /// Model class for GitHub Rate Limit Information. diff --git a/lib/src/common/model/misc.g.dart b/lib/src/common/model/misc.g.dart index fc40fa65..34362c50 100644 --- a/lib/src/common/model/misc.g.dart +++ b/lib/src/common/model/misc.g.dart @@ -12,6 +12,12 @@ GitignoreTemplate _$GitignoreTemplateFromJson(Map json) => source: json['source'] as String?, ); +Map _$GitignoreTemplateToJson(GitignoreTemplate instance) => + { + 'name': instance.name, + 'source': instance.source, + }; + RateLimit _$RateLimitFromJson(Map json) => RateLimit( json['limit'] as int?, json['remaining'] as int?, diff --git a/lib/src/common/model/notifications.dart b/lib/src/common/model/notifications.dart index 6032549b..0fd0477a 100644 --- a/lib/src/common/model/notifications.dart +++ b/lib/src/common/model/notifications.dart @@ -4,7 +4,7 @@ import 'package:json_annotation/json_annotation.dart'; part 'notifications.g.dart'; /// Model class for notifications. -@JsonSerializable(createToJson: false) +@JsonSerializable() class Notification { Notification({ this.id, @@ -36,10 +36,11 @@ class Notification { factory Notification.fromJson(Map input) => _$NotificationFromJson(input); + Map toJson() => _$NotificationToJson(this); } /// Model class for a notification subject. -@JsonSerializable(createToJson: false) +@JsonSerializable() class NotificationSubject { NotificationSubject({this.title, this.type, this.url, this.latestCommentUrl}); final String? title; @@ -51,4 +52,5 @@ class NotificationSubject { factory NotificationSubject.fromJson(Map input) => _$NotificationSubjectFromJson(input); + Map toJson() => _$NotificationSubjectToJson(this); } diff --git a/lib/src/common/model/notifications.g.dart b/lib/src/common/model/notifications.g.dart index 82c74573..70dfde07 100644 --- a/lib/src/common/model/notifications.g.dart +++ b/lib/src/common/model/notifications.g.dart @@ -27,6 +27,19 @@ Notification _$NotificationFromJson(Map json) => Notification( subscriptionUrl: json['subscription_url'] as String?, ); +Map _$NotificationToJson(Notification instance) => + { + 'id': instance.id, + 'repository': instance.repository, + 'subject': instance.subject, + 'reason': instance.reason, + 'unread': instance.unread, + 'updated_at': instance.updatedAt?.toIso8601String(), + 'last_read_at': instance.lastReadAt?.toIso8601String(), + 'url': instance.url, + 'subscription_url': instance.subscriptionUrl, + }; + NotificationSubject _$NotificationSubjectFromJson(Map json) => NotificationSubject( title: json['title'] as String?, @@ -34,3 +47,12 @@ NotificationSubject _$NotificationSubjectFromJson(Map json) => url: json['url'] as String?, latestCommentUrl: json['latest_comment_url'] as String?, ); + +Map _$NotificationSubjectToJson( + NotificationSubject instance) => + { + 'title': instance.title, + 'type': instance.type, + 'url': instance.url, + 'latest_comment_url': instance.latestCommentUrl, + }; diff --git a/lib/src/common/model/orgs.dart b/lib/src/common/model/orgs.dart index 0a28ea42..21f7b417 100644 --- a/lib/src/common/model/orgs.dart +++ b/lib/src/common/model/orgs.dart @@ -82,7 +82,7 @@ class Organization { } /// Model class for organization membership. -@JsonSerializable(createToJson: false) +@JsonSerializable() class OrganizationMembership { OrganizationMembership({ this.state, @@ -94,10 +94,11 @@ class OrganizationMembership { factory OrganizationMembership.fromJson(Map input) { return _$OrganizationMembershipFromJson(input); } + Map toJson() => _$OrganizationMembershipToJson(this); } /// Model class for a GitHub team. -@JsonSerializable(createToJson: false) +@JsonSerializable() class Team { Team({ this.name, @@ -131,6 +132,7 @@ class Team { factory Team.fromJson(Map input) { return _$TeamFromJson(input); } + Map toJson() => _$TeamToJson(this); } /// Model class for the team membership state. @@ -145,7 +147,7 @@ class TeamMembershipState { } /// Model class for a team member. -@JsonSerializable(createToJson: false) +@JsonSerializable() class TeamMember { TeamMember( {this.login, @@ -179,4 +181,5 @@ class TeamMember { factory TeamMember.fromJson(Map input) { return _$TeamMemberFromJson(input); } + Map toJson() => _$TeamMemberToJson(this); } diff --git a/lib/src/common/model/orgs.g.dart b/lib/src/common/model/orgs.g.dart index 52ffea0d..0e19f2cf 100644 --- a/lib/src/common/model/orgs.g.dart +++ b/lib/src/common/model/orgs.g.dart @@ -56,6 +56,13 @@ OrganizationMembership _$OrganizationMembershipFromJson( : Organization.fromJson(json['organization'] as Map), ); +Map _$OrganizationMembershipToJson( + OrganizationMembership instance) => + { + 'state': instance.state, + 'organization': instance.organization, + }; + Team _$TeamFromJson(Map json) => Team( name: json['name'] as String?, id: json['id'] as int?, @@ -67,6 +74,15 @@ Team _$TeamFromJson(Map json) => Team( : Organization.fromJson(json['organization'] as Map), ); +Map _$TeamToJson(Team instance) => { + 'name': instance.name, + 'id': instance.id, + 'permission': instance.permission, + 'members_count': instance.membersCount, + 'repos_count': instance.reposCount, + 'organization': instance.organization, + }; + TeamMember _$TeamMemberFromJson(Map json) => TeamMember( login: json['login'] as String?, id: json['id'] as int?, @@ -75,3 +91,13 @@ TeamMember _$TeamMemberFromJson(Map json) => TeamMember( siteAdmin: json['site_admin'] as bool?, htmlUrl: json['html_url'] as String?, ); + +Map _$TeamMemberToJson(TeamMember instance) => + { + 'login': instance.login, + 'id': instance.id, + 'avatar_url': instance.avatarUrl, + 'type': instance.type, + 'site_admin': instance.siteAdmin, + 'html_url': instance.htmlUrl, + }; diff --git a/lib/src/common/model/repos.dart b/lib/src/common/model/repos.dart index f7140e13..4a3c65e3 100644 --- a/lib/src/common/model/repos.dart +++ b/lib/src/common/model/repos.dart @@ -3,9 +3,7 @@ import 'package:json_annotation/json_annotation.dart'; part 'repos.g.dart'; -@JsonSerializable( - createToJson: false, -) +@JsonSerializable() class GitHubComparison { final String? url; final String? status; @@ -19,6 +17,7 @@ class GitHubComparison { factory GitHubComparison.fromJson(Map json) => _$GitHubComparisonFromJson(json); + Map toJson() => _$GitHubComparisonToJson(this); @override String toString() { @@ -201,7 +200,7 @@ class RepositoryPermissions { Map toJson() => _$RepositoryPermissionsToJson(this); } -@JsonSerializable(createToJson: false) +@JsonSerializable() class Tag { final String name; final CommitInfo commit; @@ -213,7 +212,8 @@ class Tag { Tag(this.name, this.commit, this.zipUrl, this.tarUrl); factory Tag.fromJson(Map input) => _$TagFromJson(input); - + Map toJson() => _$TagToJson(this); + @override String toString() => 'Tag: $name'; } diff --git a/lib/src/common/model/repos.g.dart b/lib/src/common/model/repos.g.dart index c3f9cec8..78184d6f 100644 --- a/lib/src/common/model/repos.g.dart +++ b/lib/src/common/model/repos.g.dart @@ -18,6 +18,16 @@ GitHubComparison _$GitHubComparisonFromJson(Map json) => .toList(), ); +Map _$GitHubComparisonToJson(GitHubComparison instance) => + { + 'url': instance.url, + 'status': instance.status, + 'ahead_by': instance.aheadBy, + 'behind_by': instance.behindBy, + 'total_commits': instance.totalCommits, + 'files': instance.files, + }; + Repository _$RepositoryFromJson(Map json) => Repository( name: json['name'] as String? ?? '', id: json['id'] as int? ?? 0, @@ -127,6 +137,13 @@ Tag _$TagFromJson(Map json) => Tag( json['tarball_url'] as String, ); +Map _$TagToJson(Tag instance) => { + 'name': instance.name, + 'commit': instance.commit, + 'zipball_url': instance.zipUrl, + 'tarball_url': instance.tarUrl, + }; + CommitData _$CommitDataFromJson(Map json) => CommitData( json['sha'] as String?, json['commit'] == null diff --git a/lib/src/common/model/search.dart b/lib/src/common/model/search.dart index 1735a465..532551f6 100644 --- a/lib/src/common/model/search.dart +++ b/lib/src/common/model/search.dart @@ -9,7 +9,7 @@ abstract class SearchResults { List? items; } -@JsonSerializable(createToJson: false) +@JsonSerializable() class CodeSearchResults implements SearchResults { @JsonKey(name: 'total_count') @override @@ -25,9 +25,10 @@ class CodeSearchResults implements SearchResults { static CodeSearchResults fromJson(Map input) => _$CodeSearchResultsFromJson(input); + Map toJson() => _$CodeSearchResultsToJson(this); } -@JsonSerializable(createToJson: false) +@JsonSerializable() class CodeSearchItem { String? name; String? path; @@ -57,11 +58,12 @@ class CodeSearchItem { } return result; } + Map toJson() => _$CodeSearchItemToJson(this); } // TODO: Issue Search -// @JsonSerializable(createToJson: false) +// @JsonSerializable() // class IssueSearchResults extends SearchResults {} -// @JsonSerializable(createToJson: false) +// @JsonSerializable() // class IssueSearchItem {} diff --git a/lib/src/common/model/search.g.dart b/lib/src/common/model/search.g.dart index e50161a6..d24fa9cb 100644 --- a/lib/src/common/model/search.g.dart +++ b/lib/src/common/model/search.g.dart @@ -12,6 +12,13 @@ CodeSearchResults _$CodeSearchResultsFromJson(Map json) => ..incompleteResults = json['incomplete_results'] as bool? ..items = CodeSearchItem.fromJsonList(json['items'] as List); +Map _$CodeSearchResultsToJson(CodeSearchResults instance) => + { + 'total_count': instance.totalCount, + 'incomplete_results': instance.incompleteResults, + 'items': instance.items, + }; + CodeSearchItem _$CodeSearchItemFromJson(Map json) => CodeSearchItem() ..name = json['name'] as String? @@ -23,3 +30,14 @@ CodeSearchItem _$CodeSearchItemFromJson(Map json) => ..repository = json['repository'] == null ? null : Repository.fromJson(json['repository'] as Map); + +Map _$CodeSearchItemToJson(CodeSearchItem instance) => + { + 'name': instance.name, + 'path': instance.path, + 'sha': instance.sha, + 'url': instance.url?.toString(), + 'git_url': instance.gitUrl?.toString(), + 'html_url': instance.htmlUrl?.toString(), + 'repository': instance.repository, + }; diff --git a/lib/src/common/model/users.dart b/lib/src/common/model/users.dart index 4c3245a4..766f6185 100644 --- a/lib/src/common/model/users.dart +++ b/lib/src/common/model/users.dart @@ -96,9 +96,7 @@ class User { /// The response from listing collaborators on a repo. // https://developer.github.com/v3/repos/collaborators/#response -@JsonSerializable( - createToJson: false, -) +@JsonSerializable() class Collaborator { final String? login; final int? id; @@ -118,6 +116,7 @@ class Collaborator { factory Collaborator.fromJson(Map json) => _$CollaboratorFromJson(json); + Map toJson() => _$CollaboratorToJson(this); } /// The response from listing contributors on a repo. diff --git a/lib/src/common/model/users.g.dart b/lib/src/common/model/users.g.dart index fde0c3cf..2713125a 100644 --- a/lib/src/common/model/users.g.dart +++ b/lib/src/common/model/users.g.dart @@ -64,6 +64,16 @@ Collaborator _$CollaboratorFromJson(Map json) => Collaborator( ), ); +Map _$CollaboratorToJson(Collaborator instance) => + { + 'login': instance.login, + 'id': instance.id, + 'html_url': instance.htmlUrl, + 'type': instance.type, + 'site_admin': instance.siteAdmin, + 'permissions': instance.permissions, + }; + Contributor _$ContributorFromJson(Map json) => Contributor( id: json['id'] as int?, login: json['login'] as String?, From 027ca8e03ca7ce8e1f45580278131c41daeb02fe Mon Sep 17 00:00:00 2001 From: Rob Becker Date: Sat, 8 Jan 2022 16:35:29 -0700 Subject: [PATCH 2/3] format --- lib/src/common/model/repos.dart | 2 +- lib/src/common/model/search.dart | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/common/model/repos.dart b/lib/src/common/model/repos.dart index 4a3c65e3..0a00f26a 100644 --- a/lib/src/common/model/repos.dart +++ b/lib/src/common/model/repos.dart @@ -213,7 +213,7 @@ class Tag { factory Tag.fromJson(Map input) => _$TagFromJson(input); Map toJson() => _$TagToJson(this); - + @override String toString() => 'Tag: $name'; } diff --git a/lib/src/common/model/search.dart b/lib/src/common/model/search.dart index 532551f6..c61f39e5 100644 --- a/lib/src/common/model/search.dart +++ b/lib/src/common/model/search.dart @@ -58,6 +58,7 @@ class CodeSearchItem { } return result; } + Map toJson() => _$CodeSearchItemToJson(this); } From 5f4a2212b485149fe1e63a03d8ed3ea1bf7dabaf Mon Sep 17 00:00:00 2001 From: Rob Becker Date: Sat, 8 Jan 2022 17:24:37 -0700 Subject: [PATCH 3/3] add a few more toJson methods --- lib/src/common/model/gists.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/src/common/model/gists.dart b/lib/src/common/model/gists.dart index cd89deac..e5360d70 100644 --- a/lib/src/common/model/gists.dart +++ b/lib/src/common/model/gists.dart @@ -47,6 +47,7 @@ class Gist { DateTime? updatedAt; factory Gist.fromJson(Map input) => _$GistFromJson(input); + Map toJson() => _$GistToJson(this); } /// Model class for a gist file. @@ -90,6 +91,7 @@ class GistFork { factory GistFork.fromJson(Map input) => _$GistForkFromJson(input); + Map toJson() => _$GistForkToJson(this); } /// Model class for a gits history entry. @@ -121,6 +123,7 @@ class GistHistoryEntry { factory GistHistoryEntry.fromJson(Map input) => _$GistHistoryEntryFromJson(input); + Map toJson() => _$GistHistoryEntryToJson(this); } /// Model class for gist comments.