-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
78 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import 'package:running_on_dart/src/web_app/utils.dart'; | ||
|
||
JsonApiResponse createPaginationResponse( | ||
{required List<JsonApiResponse> data, required int total, required int perPage, required int page}) { | ||
return { | ||
'perPage': perPage, | ||
'page': page, | ||
'total': total, | ||
'data': data, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,33 @@ | ||
import 'package:injector/injector.dart'; | ||
import 'package:nyxx/nyxx.dart'; | ||
import 'package:running_on_dart/src/models/tag.dart'; | ||
import 'package:running_on_dart/src/modules/tag.dart'; | ||
import 'package:running_on_dart/src/web_app/mapper/pagination_mapper.dart'; | ||
import 'package:running_on_dart/src/web_app/utils.dart'; | ||
|
||
Stream<JsonApiResponse> mapGuildTagsToData(Snowflake guildId, int tagsLimit, | ||
{String? searchQuery, int page = 1}) async* { | ||
JsonApiResponse _mapGuildTag(Tag tag) { | ||
return { | ||
'id': tag.id, | ||
'name': tag.name, | ||
'content': tag.content, | ||
'enabled': tag.enabled, | ||
'authorId': tag.authorId.toString(), | ||
}; | ||
} | ||
|
||
Future<JsonApiResponse> mapGuildTagsToData(Snowflake guildId, int tagsLimit, | ||
{String? searchQuery, int page = 1}) async { | ||
final tagsModule = Injector.appInstance.get<TagModule>(); | ||
|
||
var tags = tagsModule.getGuildTags(guildId); | ||
if (searchQuery != null) { | ||
tags = tags.where((tag) => tag.name.contains(searchQuery)); | ||
} | ||
|
||
for (final tag in tags.skip(tagsLimit * (page - 1)).take(tagsLimit)) { | ||
yield { | ||
'id': tag.id, | ||
'name': tag.name, | ||
'content': tag.content, | ||
'enabled': tag.enabled, | ||
'authorId': tag.authorId.toString(), | ||
}; | ||
} | ||
return createPaginationResponse( | ||
data: tags.skip(tagsLimit * (page - 1)).take(tagsLimit).map(_mapGuildTag).toList(), | ||
total: tags.length, | ||
perPage: tagsLimit, | ||
page: page, | ||
); | ||
} |