From 45b6ba3f0586af1c5fc9ef56c293a2ea71495674 Mon Sep 17 00:00:00 2001 From: jvyden Date: Wed, 13 Apr 2022 15:22:49 -0400 Subject: [PATCH] Sort by team pick then by first uploaded when searching for slots Closes #250 --- .../GameApi/Slots/SearchController.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/ProjectLighthouse/Controllers/GameApi/Slots/SearchController.cs b/ProjectLighthouse/Controllers/GameApi/Slots/SearchController.cs index b073cd11..7292ff67 100644 --- a/ProjectLighthouse/Controllers/GameApi/Slots/SearchController.cs +++ b/ProjectLighthouse/Controllers/GameApi/Slots/SearchController.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Collections.Generic; using System.Linq; @@ -24,23 +25,20 @@ public class SearchController : ControllerBase [HttpGet("slots/search")] public async Task SearchSlots([FromQuery] string query, [FromQuery] int pageSize, [FromQuery] int pageStart) { - (User, GameToken)? userAndToken = await this.database.UserAndGameTokenFromRequest(this.Request); + GameToken? gameToken = await this.database.GameTokenFromRequest(this.Request); + if (gameToken == null) return this.StatusCode(403, ""); - if (userAndToken == null) return this.StatusCode(403, ""); - - // ReSharper disable once PossibleInvalidOperationException - User user = userAndToken.Value.Item1; - GameToken gameToken = userAndToken.Value.Item2; - - if (query == null) return this.BadRequest(); + if (string.IsNullOrWhiteSpace(query)) return this.BadRequest(); query = query.ToLower(); string[] keywords = query.Split(" "); - IQueryable dbQuery = this.database.Slots - .Include(s => s.Creator) + IQueryable dbQuery = this.database.Slots.Include + (s => s.Creator) .Include(s => s.Location) + .OrderBy(s => !s.TeamPick) + .ThenByDescending(s => s.FirstUploaded) .Where(s => s.SlotId >= 0); // dumb query to conv into IQueryable // ReSharper disable once LoopCanBeConvertedToQuery