From 2821beb1b750f5b494199f5de672d245a5e9d909 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 14 Jun 2025 12:24:49 +0800 Subject: [PATCH] :bug: Bug fixes on relationship API --- .../Account/RelationshipController.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/DysonNetwork.Sphere/Account/RelationshipController.cs b/DysonNetwork.Sphere/Account/RelationshipController.cs index 28a9e17..2368b7e 100644 --- a/DysonNetwork.Sphere/Account/RelationshipController.cs +++ b/DysonNetwork.Sphere/Account/RelationshipController.cs @@ -2,6 +2,7 @@ using System.ComponentModel.DataAnnotations; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using NodaTime; namespace DysonNetwork.Sphere.Account; @@ -114,10 +115,18 @@ public class RelationshipController(AppDatabase db, RelationshipService rels) : { if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized(); - var relationship = await rels.GetRelationship(currentUser.Id, userId); + var now = Instant.FromDateTimeUtc(DateTime.UtcNow); + var queries = db.AccountRelationships.AsQueryable() + .Where(r => r.AccountId == currentUser.Id && r.RelatedId == userId) + .Where(r => r.ExpiredAt == null || r.ExpiredAt > now); + var relationship = await queries + .Include(r => r.Related) + .Include(r => r.Related.Profile) + .FirstOrDefaultAsync(); if (relationship is null) return NotFound(); - return relationship; + relationship.Account = currentUser; + return Ok(relationship); } [HttpPost("{userId:guid}/friends")]