♻️ Remove the discovery service in the Sphere.
This commit is contained in:
37
DysonNetwork.Pass/Realm/RealmDiscoveryController.cs
Normal file
37
DysonNetwork.Pass/Realm/RealmDiscoveryController.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using DysonNetwork.Shared.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace DysonNetwork.Pass.Realm;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/realms/discovery")]
|
||||
public class RealmDiscoveryController(AppDatabase db) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<List<SnRealm>>> GetRealmDiscovery(
|
||||
[FromQuery] string? query,
|
||||
[FromQuery] int take = 10,
|
||||
[FromQuery] int offset = 0
|
||||
)
|
||||
{
|
||||
var realmsQuery = db.Realms
|
||||
.Where(r => r.IsCommunity)
|
||||
.OrderByDescending(r => r.Members.Count)
|
||||
.AsQueryable();
|
||||
if (!string.IsNullOrWhiteSpace(query))
|
||||
realmsQuery = realmsQuery.Where(r =>
|
||||
EF.Functions.ILike(r.Name, $"%{query}%") ||
|
||||
EF.Functions.ILike(r.Description, $"%{query}%")
|
||||
);
|
||||
|
||||
var totalCount = await realmsQuery.CountAsync();
|
||||
Response.Headers["X-Total"] = totalCount.ToString();
|
||||
|
||||
var realms = await realmsQuery
|
||||
.Take(take)
|
||||
.Skip(offset)
|
||||
.ToListAsync();
|
||||
return Ok(realms);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user