[backend/masto-client] Reformat AccountController

This commit is contained in:
Laura Hausmann 2025-01-21 21:30:53 +01:00
parent ac2527aa75
commit f32cd81ada
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -172,7 +172,9 @@ public class AccountController(
[HttpGet] [HttpGet]
[ProducesResults(HttpStatusCode.OK)] [ProducesResults(HttpStatusCode.OK)]
[ProducesErrors(HttpStatusCode.Forbidden)] [ProducesErrors(HttpStatusCode.Forbidden)]
public async Task<IEnumerable<AccountEntity>> GetManyUsers([FromQuery(Name = "id")] [MaxLength(40)] HashSet<string> ids) public async Task<IEnumerable<AccountEntity>> GetManyUsers(
[FromQuery(Name = "id")] [MaxLength(40)] HashSet<string> ids
)
{ {
var localUser = HttpContext.GetUser(); var localUser = HttpContext.GetUser();
if (config.Value.PublicPreview == Enums.PublicPreview.Lockdown && localUser == null) if (config.Value.PublicPreview == Enums.PublicPreview.Lockdown && localUser == null)
@ -195,8 +197,8 @@ public class AccountController(
if (config.Value.PublicPreview == Enums.PublicPreview.Lockdown && localUser == null) if (config.Value.PublicPreview == Enums.PublicPreview.Lockdown && localUser == null)
throw GracefulException.Forbidden("Public preview is disabled on this instance"); throw GracefulException.Forbidden("Public preview is disabled on this instance");
var user = await db.Users.IncludeCommonProperties().FirstOrDefaultAsync(p => p.Id == id) ?? var user = await db.Users.IncludeCommonProperties().FirstOrDefaultAsync(p => p.Id == id)
throw GracefulException.RecordNotFound(); ?? throw GracefulException.RecordNotFound();
if (config.Value.PublicPreview <= Enums.PublicPreview.Restricted && user.IsRemoteUser && localUser == null) if (config.Value.PublicPreview <= Enums.PublicPreview.Restricted && user.IsRemoteUser && localUser == null)
throw GracefulException.Forbidden("Public preview is disabled on this instance"); throw GracefulException.Forbidden("Public preview is disabled on this instance");
@ -218,8 +220,8 @@ public class AccountController(
var followee = await db.Users.IncludeCommonProperties() var followee = await db.Users.IncludeCommonProperties()
.Where(p => p.Id == id) .Where(p => p.Id == id)
.PrecomputeRelationshipData(user) .PrecomputeRelationshipData(user)
.FirstOrDefaultAsync() ?? .FirstOrDefaultAsync()
throw GracefulException.RecordNotFound(); ?? throw GracefulException.RecordNotFound();
if ((followee.PrecomputedIsBlockedBy ?? true) || (followee.PrecomputedIsBlocking ?? true)) if ((followee.PrecomputedIsBlockedBy ?? true) || (followee.PrecomputedIsBlocking ?? true))
throw GracefulException.Forbidden("This action is not allowed"); throw GracefulException.Forbidden("This action is not allowed");
@ -251,8 +253,8 @@ public class AccountController(
.Where(p => p.Id == id) .Where(p => p.Id == id)
.IncludeCommonProperties() .IncludeCommonProperties()
.PrecomputeRelationshipData(user) .PrecomputeRelationshipData(user)
.FirstOrDefaultAsync() ?? .FirstOrDefaultAsync()
throw GracefulException.RecordNotFound(); ?? throw GracefulException.RecordNotFound();
await userSvc.UnfollowUserAsync(user, followee); await userSvc.UnfollowUserAsync(user, followee);
return RenderRelationship(followee); return RenderRelationship(followee);
@ -272,8 +274,8 @@ public class AccountController(
.Where(p => p.FolloweeId == user.Id && p.FollowerId == id) .Where(p => p.FolloweeId == user.Id && p.FollowerId == id)
.Select(p => p.Follower) .Select(p => p.Follower)
.PrecomputeRelationshipData(user) .PrecomputeRelationshipData(user)
.FirstOrDefaultAsync() ?? .FirstOrDefaultAsync()
throw GracefulException.RecordNotFound(); ?? throw GracefulException.RecordNotFound();
await userSvc.RemoveFromFollowersAsync(user, follower); await userSvc.RemoveFromFollowersAsync(user, follower);
return RenderRelationship(follower); return RenderRelationship(follower);
@ -293,8 +295,8 @@ public class AccountController(
.Where(p => p.Id == id) .Where(p => p.Id == id)
.IncludeCommonProperties() .IncludeCommonProperties()
.PrecomputeRelationshipData(user) .PrecomputeRelationshipData(user)
.FirstOrDefaultAsync() ?? .FirstOrDefaultAsync()
throw GracefulException.RecordNotFound(); ?? throw GracefulException.RecordNotFound();
//TODO: handle notifications parameter //TODO: handle notifications parameter
DateTime? expiration = request.Duration == 0 ? null : DateTime.UtcNow + TimeSpan.FromSeconds(request.Duration); DateTime? expiration = request.Duration == 0 ? null : DateTime.UtcNow + TimeSpan.FromSeconds(request.Duration);
@ -316,8 +318,8 @@ public class AccountController(
.Where(p => p.Id == id) .Where(p => p.Id == id)
.IncludeCommonProperties() .IncludeCommonProperties()
.PrecomputeRelationshipData(user) .PrecomputeRelationshipData(user)
.FirstOrDefaultAsync() ?? .FirstOrDefaultAsync()
throw GracefulException.RecordNotFound(); ?? throw GracefulException.RecordNotFound();
await userSvc.UnmuteUserAsync(user, mutee); await userSvc.UnmuteUserAsync(user, mutee);
return RenderRelationship(mutee); return RenderRelationship(mutee);
@ -337,8 +339,8 @@ public class AccountController(
.Where(p => p.Id == id) .Where(p => p.Id == id)
.IncludeCommonProperties() .IncludeCommonProperties()
.PrecomputeRelationshipData(user) .PrecomputeRelationshipData(user)
.FirstOrDefaultAsync() ?? .FirstOrDefaultAsync()
throw GracefulException.RecordNotFound(); ?? throw GracefulException.RecordNotFound();
await userSvc.BlockUserAsync(user, blockee); await userSvc.BlockUserAsync(user, blockee);
return RenderRelationship(blockee); return RenderRelationship(blockee);
@ -358,8 +360,8 @@ public class AccountController(
.Where(p => p.Id == id) .Where(p => p.Id == id)
.IncludeCommonProperties() .IncludeCommonProperties()
.PrecomputeRelationshipData(user) .PrecomputeRelationshipData(user)
.FirstOrDefaultAsync() ?? .FirstOrDefaultAsync()
throw GracefulException.RecordNotFound(); ?? throw GracefulException.RecordNotFound();
await userSvc.UnblockUserAsync(user, blockee); await userSvc.UnblockUserAsync(user, blockee);
return RenderRelationship(blockee); return RenderRelationship(blockee);
@ -417,8 +419,8 @@ public class AccountController(
var account = await db.Users var account = await db.Users
.Include(p => p.UserProfile) .Include(p => p.UserProfile)
.FirstOrDefaultAsync(p => p.Id == id) ?? .FirstOrDefaultAsync(p => p.Id == id)
throw GracefulException.RecordNotFound(); ?? throw GracefulException.RecordNotFound();
if (config.Value.PublicPreview <= Enums.PublicPreview.Restricted && account.IsRemoteUser && user == null) if (config.Value.PublicPreview <= Enums.PublicPreview.Restricted && account.IsRemoteUser && user == null)
throw GracefulException.Forbidden("Public preview is disabled on this instance"); throw GracefulException.Forbidden("Public preview is disabled on this instance");
@ -453,8 +455,8 @@ public class AccountController(
var account = await db.Users var account = await db.Users
.Include(p => p.UserProfile) .Include(p => p.UserProfile)
.FirstOrDefaultAsync(p => p.Id == id) ?? .FirstOrDefaultAsync(p => p.Id == id)
throw GracefulException.RecordNotFound(); ?? throw GracefulException.RecordNotFound();
if (config.Value.PublicPreview <= Enums.PublicPreview.Restricted && account.IsRemoteUser && user == null) if (config.Value.PublicPreview <= Enums.PublicPreview.Restricted && account.IsRemoteUser && user == null)
throw GracefulException.Forbidden("Public preview is disabled on this instance"); throw GracefulException.Forbidden("Public preview is disabled on this instance");
@ -483,8 +485,8 @@ public class AccountController(
{ {
_ = await db.Users _ = await db.Users
.Include(p => p.UserProfile) .Include(p => p.UserProfile)
.FirstOrDefaultAsync(p => p.Id == id) ?? .FirstOrDefaultAsync(p => p.Id == id)
throw GracefulException.RecordNotFound(); ?? throw GracefulException.RecordNotFound();
return []; return [];
} }
@ -608,8 +610,8 @@ public class AccountController(
.IncludeCommonProperties() .IncludeCommonProperties()
.PrecomputeRelationshipData(user) .PrecomputeRelationshipData(user)
.Select(u => RenderRelationship(u)) .Select(u => RenderRelationship(u))
.FirstOrDefaultAsync() ?? .FirstOrDefaultAsync()
throw GracefulException.RecordNotFound(); ?? throw GracefulException.RecordNotFound();
} }
[HttpPost("/api/v1/follow_requests/{id}/reject")] [HttpPost("/api/v1/follow_requests/{id}/reject")]
@ -631,8 +633,8 @@ public class AccountController(
.IncludeCommonProperties() .IncludeCommonProperties()
.PrecomputeRelationshipData(user) .PrecomputeRelationshipData(user)
.Select(u => RenderRelationship(u)) .Select(u => RenderRelationship(u))
.FirstOrDefaultAsync() ?? .FirstOrDefaultAsync()
throw GracefulException.RecordNotFound(); ?? throw GracefulException.RecordNotFound();
} }
[HttpGet("lookup")] [HttpGet("lookup")]