♻️ Remove the discovery service in the Sphere.

This commit is contained in:
2026-01-06 22:32:02 +08:00
parent 6b592156c9
commit 0cc6f86f3b
9 changed files with 58 additions and 55 deletions

View 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);
}
}