fix: update fallback behavior to return empty responses when backend is unavailable

This commit is contained in:
masoodafar-web
2025-12-25 17:57:39 +03:30
parent cb6102191e
commit 45a291b529
6 changed files with 44 additions and 210 deletions
@@ -36,8 +36,13 @@ public class NetworkMembershipService
}
catch
{
// Fallback to mock data if backend is unavailable
return CreateMockTree();
// Return empty tree if backend is unavailable
return new NetworkTreeDto
{
CurrentDepth = 0,
TotalMembers = 0,
RootNode = null
};
}
}
@@ -102,21 +107,15 @@ public class NetworkMembershipService
}
catch
{
// Fallback to mock data if backend is unavailable
// Return empty statistics if backend is unavailable
return new NetworkStatisticsDto
{
LeftLegCount = 15,
RightLegCount = 12,
TotalMembers = 27,
TreeDepth = 4,
WeakerLeg = "Right",
LastMember = new LastMemberDto
{
UserId = 28,
FullName = "محمد رضایی",
Position = "Left",
JoinedAt = DateTime.Now.AddHours(-2)
}
LeftLegCount = 0,
RightLegCount = 0,
TotalMembers = 0,
TreeDepth = 0,
WeakerLeg = string.Empty,
LastMember = null
};
}
}
@@ -144,76 +143,5 @@ public class NetworkMembershipService
};
}
private static NetworkTreeDto CreateMockTree()
{
return new NetworkTreeDto
{
CurrentDepth = 3,
TotalMembers = 7,
RootNode = new NetworkNodeDto
{
UserId = 1,
FullName = "شما",
Mobile = "09121234567",
Position = "Root",
Level = 0,
IsActive = true,
IsClubActive = true,
LeftChild = new NetworkNodeDto
{
UserId = 2,
FullName = "علی محمدی",
Mobile = "09121234568",
Position = "Left",
Level = 1,
IsActive = true,
IsClubActive = true,
JoinedAt = DateTime.Now.AddDays(-30),
LeftChild = new NetworkNodeDto
{
UserId = 4,
FullName = "رضا کریمی",
Mobile = "09121234570",
Position = "Left",
Level = 2,
IsActive = true,
JoinedAt = DateTime.Now.AddDays(-15)
},
RightChild = new NetworkNodeDto
{
UserId = 5,
FullName = "زهرا احمدی",
Mobile = "09121234571",
Position = "Right",
Level = 2,
IsActive = false,
JoinedAt = DateTime.Now.AddDays(-10)
}
},
RightChild = new NetworkNodeDto
{
UserId = 3,
FullName = "فاطمه حسینی",
Mobile = "09121234569",
Position = "Right",
Level = 1,
IsActive = true,
JoinedAt = DateTime.Now.AddDays(-25),
LeftChild = new NetworkNodeDto
{
UserId = 6,
FullName = "محمد نوری",
Mobile = "09121234572",
Position = "Left",
Level = 2,
IsActive = true,
IsClubActive = true,
JoinedAt = DateTime.Now.AddDays(-5)
}
}
}
};
}
#endregion
}