mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-30 08:48:39 +00:00
Sort by team pick then by first uploaded when searching for slots
Closes #250
This commit is contained in:
parent
131add7df5
commit
45b6ba3f05
1 changed files with 8 additions and 10 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
#nullable enable
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -24,23 +25,20 @@ public class SearchController : ControllerBase
|
||||||
[HttpGet("slots/search")]
|
[HttpGet("slots/search")]
|
||||||
public async Task<IActionResult> SearchSlots([FromQuery] string query, [FromQuery] int pageSize, [FromQuery] int pageStart)
|
public async Task<IActionResult> 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, "");
|
if (string.IsNullOrWhiteSpace(query)) return this.BadRequest();
|
||||||
|
|
||||||
// ReSharper disable once PossibleInvalidOperationException
|
|
||||||
User user = userAndToken.Value.Item1;
|
|
||||||
GameToken gameToken = userAndToken.Value.Item2;
|
|
||||||
|
|
||||||
if (query == null) return this.BadRequest();
|
|
||||||
|
|
||||||
query = query.ToLower();
|
query = query.ToLower();
|
||||||
|
|
||||||
string[] keywords = query.Split(" ");
|
string[] keywords = query.Split(" ");
|
||||||
|
|
||||||
IQueryable<Slot> dbQuery = this.database.Slots
|
IQueryable<Slot> dbQuery = this.database.Slots.Include
|
||||||
.Include(s => s.Creator)
|
(s => s.Creator)
|
||||||
.Include(s => s.Location)
|
.Include(s => s.Location)
|
||||||
|
.OrderBy(s => !s.TeamPick)
|
||||||
|
.ThenByDescending(s => s.FirstUploaded)
|
||||||
.Where(s => s.SlotId >= 0); // dumb query to conv into IQueryable
|
.Where(s => s.SlotId >= 0); // dumb query to conv into IQueryable
|
||||||
|
|
||||||
// ReSharper disable once LoopCanBeConvertedToQuery
|
// ReSharper disable once LoopCanBeConvertedToQuery
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue