🐛 Fix some relationship issues
This commit is contained in:
@@ -22,25 +22,15 @@ public class RelationshipController(AppDatabase db, RelationshipService rls) : C
|
|||||||
|
|
||||||
var query = db.AccountRelationships.AsQueryable()
|
var query = db.AccountRelationships.AsQueryable()
|
||||||
.OrderByDescending(r => r.CreatedAt)
|
.OrderByDescending(r => r.CreatedAt)
|
||||||
.Where(r => r.RelatedId == accountId);
|
.Where(r => r.AccountId == accountId);
|
||||||
var totalCount = await query.CountAsync();
|
var totalCount = await query.CountAsync();
|
||||||
var relationships = await query
|
var relationships = await query
|
||||||
.Include(r => r.Related)
|
.Include(r => r.Related)
|
||||||
.Include(r => r.Related.Profile)
|
.ThenInclude(a => a.Profile)
|
||||||
.Include(r => r.Account)
|
|
||||||
.Include(r => r.Account.Profile)
|
|
||||||
.Skip(offset)
|
.Skip(offset)
|
||||||
.Take(take)
|
.Take(take)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
var statuses = await db.AccountRelationships
|
|
||||||
.Where(r => r.AccountId == accountId)
|
|
||||||
.ToDictionaryAsync(r => r.RelatedId);
|
|
||||||
foreach (var relationship in relationships)
|
|
||||||
relationship.Status = statuses.TryGetValue(relationship.AccountId, out var status)
|
|
||||||
? status.Status
|
|
||||||
: RelationshipStatus.Pending;
|
|
||||||
|
|
||||||
Response.Headers["X-Total"] = totalCount.ToString();
|
Response.Headers["X-Total"] = totalCount.ToString();
|
||||||
|
|
||||||
return relationships;
|
return relationships;
|
||||||
@@ -55,9 +45,7 @@ public class RelationshipController(AppDatabase db, RelationshipService rls) : C
|
|||||||
var relationships = await db.AccountRelationships
|
var relationships = await db.AccountRelationships
|
||||||
.Where(r => r.AccountId == currentUser.Id && r.Status == RelationshipStatus.Pending)
|
.Where(r => r.AccountId == currentUser.Id && r.Status == RelationshipStatus.Pending)
|
||||||
.Include(r => r.Related)
|
.Include(r => r.Related)
|
||||||
.Include(r => r.Related.Profile)
|
.ThenInclude(a => a.Profile)
|
||||||
.Include(r => r.Account)
|
|
||||||
.Include(r => r.Account.Profile)
|
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
return relationships;
|
return relationships;
|
||||||
|
|||||||
Reference in New Issue
Block a user