From 1e8083645dd75a922561af1a543d11d794709131 Mon Sep 17 00:00:00 2001 From: yosemiteyss Date: Mon, 9 Sep 2024 10:00:58 +0800 Subject: [PATCH] fix TorrentSort params use snake case #23 --- .../torrents/dto/torrent_list_options.g.dart | 60 ++++---- lib/src/v2/torrents/dto/torrent_sort.dart | 141 ++++++++++++------ .../dto/torrent_list_options_test.dart | 12 ++ 3 files changed, 134 insertions(+), 79 deletions(-) create mode 100644 test/v2/torrents/dto/torrent_list_options_test.dart diff --git a/lib/src/v2/torrents/dto/torrent_list_options.g.dart b/lib/src/v2/torrents/dto/torrent_list_options.g.dart index 0906fd8..3d2d28d 100644 --- a/lib/src/v2/torrents/dto/torrent_list_options.g.dart +++ b/lib/src/v2/torrents/dto/torrent_list_options.g.dart @@ -60,51 +60,51 @@ const _$TorrentFilterEnumMap = { }; const _$TorrentSortEnumMap = { - TorrentSort.addedOn: 'addedOn', - TorrentSort.amountLeft: 'amountLeft', - TorrentSort.autoTmm: 'autoTmm', + TorrentSort.addedOn: 'added_on', + TorrentSort.amountLeft: 'amount_left', + TorrentSort.autoTmm: 'auto_tmm', TorrentSort.availability: 'availability', TorrentSort.category: 'category', TorrentSort.completed: 'completed', - TorrentSort.completionOn: 'completionOn', - TorrentSort.contentPath: 'contentPath', - TorrentSort.dlLimit: 'dlLimit', - TorrentSort.dlSpeed: 'dlSpeed', + TorrentSort.completionOn: 'completion_on', + TorrentSort.contentPath: 'content_path', + TorrentSort.dlLimit: 'dl_limit', + TorrentSort.dlSpeed: 'dlspeed', TorrentSort.downloaded: 'downloaded', - TorrentSort.downloadedSession: 'downloadedSession', + TorrentSort.downloadedSession: 'downloaded_session', TorrentSort.eta: 'eta', - TorrentSort.fLPiecePrio: 'fLPiecePrio', - TorrentSort.forceStart: 'forceStart', + TorrentSort.fLPiecePrio: 'f_l_piece_prio', + TorrentSort.forceStart: 'force_start', TorrentSort.hash: 'hash', - TorrentSort.lastActivity: 'lastActivity', - TorrentSort.magnetUri: 'magnetUri', - TorrentSort.maxRatio: 'maxRatio', - TorrentSort.maxSeedingTime: 'maxSeedingTime', + TorrentSort.lastActivity: 'last_activity', + TorrentSort.magnetUri: 'magnet_uri', + TorrentSort.maxRatio: 'max_ratio', + TorrentSort.maxSeedingTime: 'max_seeding_time', TorrentSort.name: 'name', - TorrentSort.numComplete: 'numComplete', - TorrentSort.numIncomplete: 'numIncomplete', - TorrentSort.numLeechs: 'numLeechs', - TorrentSort.numSeeds: 'numSeeds', + TorrentSort.numComplete: 'num_complete', + TorrentSort.numIncomplete: 'num_incomplete', + TorrentSort.numLeechs: 'num_leechs', + TorrentSort.numSeeds: 'num_seeds', TorrentSort.priority: 'priority', TorrentSort.progress: 'progress', TorrentSort.ratio: 'ratio', - TorrentSort.ratioLimit: 'ratioLimit', - TorrentSort.savePath: 'savePath', - TorrentSort.seedingTime: 'seedingTime', - TorrentSort.seedingTimeLimit: 'seedingTimeLimit', - TorrentSort.seenComplete: 'seenComplete', - TorrentSort.seqDl: 'seqDl', + TorrentSort.ratioLimit: 'ratio_limit', + TorrentSort.savePath: 'save_path', + TorrentSort.seedingTime: 'seeding_time', + TorrentSort.seedingTimeLimit: 'seeding_time_limit', + TorrentSort.seenComplete: 'seen_complete', + TorrentSort.seqDl: 'seq_dl', TorrentSort.size: 'size', TorrentSort.state: 'state', - TorrentSort.superSeeding: 'superSeeding', + TorrentSort.superSeeding: 'super_seeding', TorrentSort.tags: 'tags', - TorrentSort.timeActive: 'timeActive', - TorrentSort.totalSize: 'totalSize', + TorrentSort.timeActive: 'time_active', + TorrentSort.totalSize: 'total_size', TorrentSort.tracker: 'tracker', - TorrentSort.upLimit: 'upLimit', + TorrentSort.upLimit: 'up_limit', TorrentSort.uploaded: 'uploaded', - TorrentSort.uploadedSession: 'uploadedSession', - TorrentSort.upSpeed: 'upSpeed', + TorrentSort.uploadedSession: 'uploaded_session', + TorrentSort.upSpeed: 'upspeed', }; Value? _$JsonConverterFromJson( diff --git a/lib/src/v2/torrents/dto/torrent_sort.dart b/lib/src/v2/torrents/dto/torrent_sort.dart index 4d4c8a3..e871eee 100644 --- a/lib/src/v2/torrents/dto/torrent_sort.dart +++ b/lib/src/v2/torrents/dto/torrent_sort.dart @@ -1,51 +1,94 @@ -enum TorrentSort { - addedOn('added_on'), - amountLeft('amount_left'), - autoTmm('auto_tmm'), - availability('availability'), - category('category'), - completed('completed'), - completionOn('completion_on'), - contentPath('content_path'), - dlLimit('dl_limit'), - dlSpeed('dlspeed'), - downloaded('downloaded'), - downloadedSession('downloaded_session'), - eta('eta'), - fLPiecePrio('f_l_piece_prio'), - forceStart('force_start'), - hash('hash'), - lastActivity('last_activity'), - magnetUri('magnet_uri'), - maxRatio('max_ratio'), - maxSeedingTime('max_seeding_time'), - name('name'), - numComplete('num_complete'), - numIncomplete('num_incomplete'), - numLeechs('num_leechs'), - numSeeds('num_seeds'), - priority('priority'), - progress('progress'), - ratio('ratio'), - ratioLimit('ratio_limit'), - savePath('save_path'), - seedingTime('seeding_time'), - seedingTimeLimit('seeding_time_limit'), - seenComplete('seen_complete'), - seqDl('seq_dl'), - size('size'), - state('state'), - superSeeding('super_seeding'), - tags('tags'), - timeActive('time_active'), - totalSize('total_size'), - tracker('tracker'), - upLimit('up_limit'), - uploaded('uploaded'), - uploadedSession('uploaded_session'), - upSpeed('upspeed'); - - const TorrentSort(this.value); +import 'package:json_annotation/json_annotation.dart'; - final String value; +enum TorrentSort { + @JsonValue('added_on') + addedOn, + @JsonValue('amount_left') + amountLeft, + @JsonValue('auto_tmm') + autoTmm, + @JsonValue('availability') + availability, + @JsonValue('category') + category, + @JsonValue('completed') + completed, + @JsonValue('completion_on') + completionOn, + @JsonValue('content_path') + contentPath, + @JsonValue('dl_limit') + dlLimit, + @JsonValue('dlspeed') + dlSpeed, + @JsonValue('downloaded') + downloaded, + @JsonValue('downloaded_session') + downloadedSession, + @JsonValue('eta') + eta, + @JsonValue('f_l_piece_prio') + fLPiecePrio, + @JsonValue('force_start') + forceStart, + @JsonValue('hash') + hash, + @JsonValue('last_activity') + lastActivity, + @JsonValue('magnet_uri') + magnetUri, + @JsonValue('max_ratio') + maxRatio, + @JsonValue('max_seeding_time') + maxSeedingTime, + @JsonValue('name') + name, + @JsonValue('num_complete') + numComplete, + @JsonValue('num_incomplete') + numIncomplete, + @JsonValue('num_leechs') + numLeechs, + @JsonValue('num_seeds') + numSeeds, + @JsonValue('priority') + priority, + @JsonValue('progress') + progress, + @JsonValue('ratio') + ratio, + @JsonValue('ratio_limit') + ratioLimit, + @JsonValue('save_path') + savePath, + @JsonValue('seeding_time') + seedingTime, + @JsonValue('seeding_time_limit') + seedingTimeLimit, + @JsonValue('seen_complete') + seenComplete, + @JsonValue('seq_dl') + seqDl, + @JsonValue('size') + size, + @JsonValue('state') + state, + @JsonValue('super_seeding') + superSeeding, + @JsonValue('tags') + tags, + @JsonValue('time_active') + timeActive, + @JsonValue('total_size') + totalSize, + @JsonValue('tracker') + tracker, + @JsonValue('up_limit') + upLimit, + @JsonValue('uploaded') + uploaded, + @JsonValue('uploaded_session') + uploadedSession, + @JsonValue('upspeed') + upSpeed } diff --git a/test/v2/torrents/dto/torrent_list_options_test.dart b/test/v2/torrents/dto/torrent_list_options_test.dart new file mode 100644 index 0000000..52447a1 --- /dev/null +++ b/test/v2/torrents/dto/torrent_list_options_test.dart @@ -0,0 +1,12 @@ +import 'package:qbittorrent_api/qbittorrent_api.dart'; +import 'package:test/test.dart'; + +void main() { + group('test TorrentSort', () { + test('should TorrentSort request parameters converted to snake case', () { + const listOptions = TorrentListOptions(sort: TorrentSort.addedOn); + final json = listOptions.toJson(); + expect(json['sort'], 'added_on'); + }); + }); +}