Skip to content

Commit

Permalink
Fix query parameter artistId and tagId on song search page #119
Browse files Browse the repository at this point in the history
  • Loading branch information
up2code committed Jul 4, 2021
1 parent 106f66a commit c652ca1
Show file tree
Hide file tree
Showing 17 changed files with 347 additions and 21 deletions.
14 changes: 9 additions & 5 deletions lib/src/controllers/song_search_controller.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:vocadb_app/controllers.dart';
import 'package:vocadb_app/models.dart';
Expand All @@ -20,7 +19,12 @@ class SongSearchController extends SearchPageController<SongModel> {

final SongRepository songRepository;

SongSearchController({this.songRepository});
final SharedPreferenceService sharedPreferenceService;

SongSearchController(
{this.songRepository, SharedPreferenceService sharedPreferenceService})
: sharedPreferenceService =
sharedPreferenceService ?? Get.find<SharedPreferenceService>();

@override
void onInit() {
Expand All @@ -33,11 +37,11 @@ class SongSearchController extends SearchPageController<SongModel> {
Future<List<SongModel>> fetchApi({int start}) => songRepository
.findSongs(
start: (start == null) ? 0 : start,
lang: SharedPreferenceService.lang,
lang: sharedPreferenceService.getContentLang,
query: query.string,
songType: songType.string,
sort: sort.string,
artistIds: artists.toList().map((e) => e.id).join(','),
tagIds: tags.toList().map((e) => e.id).join(','))
artistIds: artists.map((e) => e.id.toString()).toList(),
tagIds: tags.map((e) => e.id.toString()).toList())
.catchError(super.onError);
}
7 changes: 6 additions & 1 deletion lib/src/models/base_model.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
class BaseModel {
import 'package:equatable/equatable.dart';

class BaseModel extends Equatable {
BaseModel();

BaseModel.fromJson(Map<String, dynamic> json);

Map<String, dynamic> toJson() {
return {};
}

@override
List<Object> get props => throw UnimplementedError();
}
6 changes: 6 additions & 0 deletions lib/src/models/entry_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class EntryModel extends BaseModel {
List<TagGroupModel> tagGroups;
List<WebLinkModel> webLinks;

@override
List<Object> get props => [
id,
name,
];

EntryModel(
{this.id,
this.entryType,
Expand Down
7 changes: 6 additions & 1 deletion lib/src/models/main_picture_model.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
class MainPictureModel {
import 'package:equatable/equatable.dart';

class MainPictureModel extends Equatable {
String meme;
String urlSmallThumb;
String urlThumb;
String urlTinyThumb;

@override
List<Object> get props => [meme, urlSmallThumb, urlThumb, urlTinyThumb];

MainPictureModel({this.urlThumb});

MainPictureModel.fromJson(Map<String, dynamic> json)
Expand Down
7 changes: 6 additions & 1 deletion lib/src/models/pv_model.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
class PVModel {
import 'package:equatable/equatable.dart';

class PVModel extends Equatable {
int id;
String name;
String service;
String url;
String pvType;
int length;

@override
List<Object> get props => [id, name, service, url, pvType, length];

PVModel(
{this.id, this.name, this.service, this.url, this.pvType, this.length});

Expand Down
6 changes: 5 additions & 1 deletion lib/src/models/tag_group_model.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import 'package:equatable/equatable.dart';
import 'package:vocadb_app/models.dart';

class TagGroupModel {
class TagGroupModel extends Equatable {
int count;
TagModel tag;

@override
List<Object> get props => [count, tag];

TagGroupModel.fromJson(Map<String, dynamic> json)
: count = json['count'],
tag = json.containsKey('tag') ? TagModel.fromJson(json['tag']) : null;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/repositories/base_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class RestApiRepository {

RestApiRepository({this.httpService});

Future<dynamic> getList(String endpoint, Map<String, String> params) async {
Future<dynamic> getList(String endpoint, Map<String, dynamic> params) async {
return httpService.get('$endpoint', params).then((v) => (v is Iterable)
? v
: (v.containsKey('items'))
Expand Down
16 changes: 8 additions & 8 deletions lib/src/repositories/song_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ class SongRepository extends RestApiRepository {
String query,
String songType,
String sort,
String artistIds,
String tagIds,
Iterable<String> artistIds,
Iterable<String> tagIds,
int start = 0,
int maxResults = 50,
String nameMatchMode = 'Auto'}) async {
final String endpoint = '/api/songs';
final Map<String, String> params = Map();
final Map<String, dynamic> params = Map();
params['query'] = query;
params['fields'] = 'ThumbUrl,PVs,MainPicture';
params['songType'] = songType;
params['sort'] = sort;
params['artistId'] = artistIds;
params['tagId'] = tagIds;
params['artistId[]'] = artistIds;
params['tagId[]'] = tagIds;
params['languagePreference'] = lang;
params['maxResults'] = maxResults.toString();
params['start'] = start.toString();
Expand Down Expand Up @@ -117,14 +117,14 @@ class SongRepository extends RestApiRepository {

Future<List<SongModel>> getLatestSongsByTagId(int tagId,
{String lang = 'Default'}) async {
return this
.findSongs(lang: lang, tagIds: tagId.toString(), sort: 'AdditionDate');
return this.findSongs(
lang: lang, tagIds: [tagId.toString()], sort: 'AdditionDate');
}

Future<List<SongModel>> getTopSongsByTagId(int tagId,
{String lang = 'Default'}) async {
return this
.findSongs(lang: lang, tagIds: tagId.toString(), sort: 'RatingScore');
.findSongs(lang: lang, tagIds: [tagId.toString()], sort: 'RatingScore');
}

Future<dynamic> rating(int songId, String rating) {
Expand Down
5 changes: 3 additions & 2 deletions lib/src/services/http_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ class HttpService extends GetxService {
return this;
}

Future<dynamic> get(String endpoint, Map<String, String> params) async {
params?.removeWhere((key, value) => value == null || value == '');
Future<dynamic> get(String endpoint, Map<String, dynamic> params) async {
params?.removeWhere(
(key, value) => value == null || (value is String && value.isEmpty));
String url = Uri.https(authority, endpoint, params).toString();
print('GET $url | $params');
final response = await _dio.get(url);
Expand Down
3 changes: 3 additions & 0 deletions lib/src/services/shared_preference_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class SharedPreferenceService extends GetxService {
static String get lang =>
Get.find<SharedPreferenceService>().contentLang.string;

String get getContentLang =>
Get.find<SharedPreferenceService>().contentLang.string;

static bool get autoPlayValue =>
Get.find<SharedPreferenceService>().autoPlay.value;

Expand Down
Loading

0 comments on commit c652ca1

Please sign in to comment.