From 520115c2b0d09ca92faf684677fb789a5afe8854 Mon Sep 17 00:00:00 2001 From: Plus One <2669051290@qq.com> Date: Mon, 11 Nov 2024 23:07:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=AD=8C=E5=8D=95=E4=B8=AD=E6=89=80=E6=9C=89=E6=AD=8C=E6=9B=B2?= =?UTF-8?q?=E5=92=8C=E8=8E=B7=E5=8F=96=E6=88=91=E7=9A=84=E4=BD=9C=E5=93=81?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/api/api_songlist.dart | 32 ++++++++++++++++++++++-- lib/models/getAllSongs_bean.dart | 43 ++++++++++++++++++++++++++++++++ lib/models/getMyWorks.dart | 0 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 lib/models/getAllSongs_bean.dart create mode 100644 lib/models/getMyWorks.dart diff --git a/lib/api/api_songlist.dart b/lib/api/api_songlist.dart index 387f1b1..78cb797 100644 --- a/lib/api/api_songlist.dart +++ b/lib/api/api_songlist.dart @@ -2,13 +2,41 @@ import 'package:dio/dio.dart'; import 'package:music_player_miao/models/search_bean.dart'; import 'package:music_player_miao/models/songlist_bean.dart'; +import '../models/getAllSongs_bean.dart'; import '../models/universal_bean.dart'; - +import 'package:music_player_miao/models/getMyWorks.dart'; const String _SonglistURL = 'http://flyingpig.fun:10010/songlists'; -///返回歌单 +const String _MyWorksURL = 'http://flyingpig.fun:10010/musics/upload-music'; + + class SonglistApi { final Dio dio = Dio(); + ///获取歌单中所有歌曲 + Future getAllSongs({required int id, required String Authorization}) async { + String urlWithId = 'http://flyingpig.fun:10010/songlist-musics/$id/music-list'; + Response response = await dio.get(urlWithId, + options: Options(headers: { + 'Authorization': Authorization, + 'Content-Type': 'application/json;charset=UTF-8' + })); + print(response.data); + return MyMusicListBean.formMap(response.data); + } + ///获取我的作品 + Future getMyworks({required String Authorization}) async { + Response response = await dio.get(_MyWorksURL, + data: { + 'Authorization': Authorization, + }, + options: Options(headers: { + 'Authorization': Authorization, + 'Content-Type': 'application/json;charset=UTF-8' + })); + print(response.data); + return MyWorks.formMap(response.data); + } + ///返回歌单 Future getSonglist({required String Authorization}) async { Response response = await dio.get(_SonglistURL, data: { diff --git a/lib/models/getAllSongs_bean.dart b/lib/models/getAllSongs_bean.dart new file mode 100644 index 0000000..e4185b8 --- /dev/null +++ b/lib/models/getAllSongs_bean.dart @@ -0,0 +1,43 @@ +class MyMusicListBean { + int? code; + String? msg; + List? data; + + MyMusicListBean.formMap(Map map) { + code = map['code']; + msg = map['msg']; + if (map['data'] is! List) return; + + List dataList = map['data']; + data = dataList.map((item) => DataBean._formMap(item)).toList(); + } +} +class DataBean { + int? songlistId; + List? musicDetail; + + DataBean._formMap(Map map) { + songlistId = map['songlistId']; + List? musicDetailList = map['musicDetail']; + if (musicDetailList == null) return; + + musicDetail = musicDetailList.map((item) => SongDetails._formMap(item)).toList(); + } +} +class SongDetails { + int? id; + String? name; + String? coverPath; + String? musicPath; + String? singerName; + String? uploadUserName; + + SongDetails._formMap(Map map) { + id = map['id']; + name = map['name']; + coverPath = map['coverPath']; + musicPath = map['musicPath']; + singerName = map['singerName']; + uploadUserName = map['uploadUserName']; + } +} \ No newline at end of file diff --git a/lib/models/getMyWorks.dart b/lib/models/getMyWorks.dart new file mode 100644 index 0000000..e69de29