mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-10 07:11:27 +00:00
Implement basic filters and LBP2 CrossController fixes (#758)
* implement basic filters and lbp2cc fixes * lbp3 hide lbp2cc slots * hide lbp2cc levels from hearted and most played categories in lbp3 and basic filters for lbp3 --------- Co-authored-by: jackcaver <jackcaver@users.noreply.github.com> Co-authored-by: koko <koko@drones.gay>
This commit is contained in:
parent
ab353c502f
commit
9deff7ce63
14 changed files with 233 additions and 67 deletions
|
@ -8,6 +8,7 @@ using LBPUnion.ProjectLighthouse.Types.Serialization;
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots;
|
||||
|
||||
|
@ -24,15 +25,32 @@ public class SearchController : ControllerBase
|
|||
}
|
||||
|
||||
[HttpGet("searchLBP3")]
|
||||
public Task<IActionResult> SearchSlotsLBP3([FromQuery] int pageSize, [FromQuery] int pageStart, [FromQuery] string textFilter)
|
||||
=> this.SearchSlots(textFilter, pageSize, pageStart, "results");
|
||||
public Task<IActionResult> SearchSlotsLBP3([FromQuery] int pageSize, [FromQuery] int pageStart, [FromQuery] string textFilter,
|
||||
[FromQuery] int? players = 0,
|
||||
[FromQuery] string? labelFilter0 = null,
|
||||
[FromQuery] string? labelFilter1 = null,
|
||||
[FromQuery] string? labelFilter2 = null,
|
||||
[FromQuery] string? labelFilter3 = null,
|
||||
[FromQuery] string? labelFilter4 = null,
|
||||
[FromQuery] string? move = null,
|
||||
[FromQuery] string? adventure = null)
|
||||
=> this.SearchSlots(textFilter, pageSize, pageStart, "results", false, players+1, labelFilter0, labelFilter1, labelFilter2, labelFilter3, labelFilter4, move, adventure);
|
||||
|
||||
[HttpGet("search")]
|
||||
public async Task<IActionResult> SearchSlots(
|
||||
[FromQuery] string query,
|
||||
[FromQuery] int pageSize,
|
||||
[FromQuery] int pageStart,
|
||||
string? keyName = "slots"
|
||||
string? keyName = "slots",
|
||||
bool crosscontrol = false,
|
||||
[FromQuery] int? players = null,
|
||||
[FromQuery] string? labelFilter0 = null,
|
||||
[FromQuery] string? labelFilter1 = null,
|
||||
[FromQuery] string? labelFilter2 = null,
|
||||
[FromQuery] string? labelFilter3 = null,
|
||||
[FromQuery] string? labelFilter4 = null,
|
||||
[FromQuery] string? move = null,
|
||||
[FromQuery] string? adventure = null
|
||||
)
|
||||
{
|
||||
GameTokenEntity token = this.GetToken();
|
||||
|
@ -46,7 +64,7 @@ public class SearchController : ControllerBase
|
|||
string[] keywords = query.Split(" ");
|
||||
|
||||
IQueryable<SlotEntity> dbQuery = this.database.Slots.ByGameVersion(token.GameVersion, false, true)
|
||||
.Where(s => s.Type == SlotType.User)
|
||||
.Where(s => s.Type == SlotType.User && s.CrossControllerRequired == crosscontrol)
|
||||
.OrderBy(s => !s.TeamPick)
|
||||
.ThenByDescending(s => s.FirstUploaded)
|
||||
.Where(s => s.SlotId >= 0); // dumb query to conv into IQueryable
|
||||
|
@ -61,14 +79,48 @@ public class SearchController : ControllerBase
|
|||
s.SlotId.ToString().Equals(keyword)
|
||||
);
|
||||
|
||||
List<SlotBase> slots = (await dbQuery.Skip(Math.Max(0, pageStart - 1))
|
||||
List<SlotEntity> slots = (await dbQuery.Skip(Math.Max(0, pageStart - 1))
|
||||
.Take(Math.Min(pageSize, 30))
|
||||
.ToListAsync())
|
||||
.ToSerializableList(s => SlotBase.CreateFromEntity(s, token));
|
||||
.ToListAsync());
|
||||
|
||||
return this.Ok(new GenericSlotResponse(keyName, slots, await dbQuery.CountAsync(), 0));
|
||||
slots = filterSlots(slots, players, labelFilter0, labelFilter1, labelFilter2, labelFilter3, labelFilter4, move, adventure);
|
||||
|
||||
return this.Ok(new GenericSlotResponse(keyName, slots.ToSerializableList(s => SlotBase.CreateFromEntity(s, token)), await dbQuery.CountAsync(), 0));
|
||||
}
|
||||
|
||||
|
||||
// /LITTLEBIGPLANETPS3_XML?pageStart=1&pageSize=10&resultTypes[]=slot&resultTypes[]=playlist&resultTypes[]=user&adventure=dontCare&textFilter=qwer
|
||||
|
||||
private List<SlotEntity> filterSlots(List<SlotEntity> slots, int? players = null, string? labelFilter0 = null, string? labelFilter1 = null, string? labelFilter2 = null, string? labelFilter3 = null, string? labelFilter4 = null, string? move = null, string? adventure = null)
|
||||
{
|
||||
if (players != null)
|
||||
slots.RemoveAll(s => s.MinimumPlayers != players);
|
||||
|
||||
if (labelFilter0 != null)
|
||||
slots.RemoveAll(s => !s.AuthorLabels.Split(',').ToList().Contains(labelFilter0));
|
||||
if (labelFilter1 != null)
|
||||
slots.RemoveAll(s => !s.AuthorLabels.Split(',').ToList().Contains(labelFilter1));
|
||||
if (labelFilter2 != null)
|
||||
slots.RemoveAll(s => !s.AuthorLabels.Split(',').ToList().Contains(labelFilter2));
|
||||
if (labelFilter3 != null)
|
||||
slots.RemoveAll(s => !s.AuthorLabels.Split(',').ToList().Contains(labelFilter3));
|
||||
if (labelFilter4 != null)
|
||||
slots.RemoveAll(s => !s.AuthorLabels.Split(',').ToList().Contains(labelFilter4));
|
||||
|
||||
if (move == "false")
|
||||
slots.RemoveAll(s => s.MoveRequired);
|
||||
if (move == "only")
|
||||
slots.RemoveAll(s => !s.MoveRequired);
|
||||
|
||||
if (move == "noneCan")
|
||||
slots.RemoveAll(s => s.MoveRequired);
|
||||
if (move == "allMust")
|
||||
slots.RemoveAll(s => !s.MoveRequired);
|
||||
|
||||
if (adventure == "noneCan")
|
||||
slots.RemoveAll(s => s.IsAdventurePlanet);
|
||||
if (adventure == "allMust")
|
||||
slots.RemoveAll(s => !s.IsAdventurePlanet);
|
||||
|
||||
return slots;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue