Skip to content

Commit

Permalink
feat(server): Allow ordering by multiple features
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustl22 committed Jan 16, 2024
1 parent 28c5a81 commit 91712f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ abstract class EntityController<T extends DataObject> {
List<String>? conditions,
Conjunction conjunction = Conjunction.and,
Map<String, dynamic>? substitutionValues,
String? orderBy,
List<String> orderBy = const [],
}) async {
return Future.wait((await getManyRaw(
conditions: conditions, conjunction: conjunction, substitutionValues: substitutionValues, orderBy: orderBy))
Expand All @@ -207,13 +207,14 @@ abstract class EntityController<T extends DataObject> {
.toList());
}

Future<List<Map<String, dynamic>>> getManyRaw(
{List<String>? conditions,
Conjunction conjunction = Conjunction.and,
Map<String, dynamic>? substitutionValues,
String? orderBy}) async {
Future<List<Map<String, dynamic>>> getManyRaw({
List<String>? conditions,
Conjunction conjunction = Conjunction.and,
Map<String, dynamic>? substitutionValues,
List<String> orderBy = const [],
}) async {
return getManyRawFromQuery(
'SELECT * FROM $tableName ${conditions == null ? '' : 'WHERE ${conditions.join(' ${conjunction == Conjunction.and ? 'AND' : 'OR'} ')}'} ${orderBy == null ? '' : 'ORDER BY $orderBy'};',
'SELECT * FROM $tableName ${conditions == null ? '' : 'WHERE ${conditions.join(' ${conjunction == Conjunction.and ? 'AND' : 'OR'} ')}'} ${orderBy.isEmpty ? '' : 'ORDER BY ${orderBy.join(',')}'};',
substitutionValues: substitutionValues);
}

Expand Down Expand Up @@ -284,7 +285,7 @@ abstract class EntityController<T extends DataObject> {
List<String>? conditions,
Conjunction conjunction = Conjunction.and,
Map<String, dynamic>? substitutionValues,
String? orderBy,
List<String> orderBy = const [],
}) async {
if (isRaw) {
final many = await controller.getManyRaw(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class LeagueController extends EntityController<League> {

Future<Response> requestLeagueWeightClasses(Request request, String id) async {
return EntityController.handleRequestManyOfController(LeagueWeightClassController(),
isRaw: isRaw(request), conditions: ['league_id = @id'], substitutionValues: {'id': id}, orderBy: 'pos');
isRaw: isRaw(request), conditions: ['league_id = @id'], substitutionValues: {'id': id}, orderBy: ['pos']);
}

Future<Response> requestLeagueTeamParticipations(Request request, String id) async {
Expand Down

0 comments on commit 91712f7

Please sign in to comment.