chore: add csharpier to husky, format backend with csharpier
This commit is contained in:
parent
5fab66444f
commit
7f971e8549
73 changed files with 2098 additions and 1048 deletions
|
|
@ -5,23 +5,30 @@ namespace Foxnouns.Backend.Database;
|
|||
|
||||
public static class FlagQueryExtensions
|
||||
{
|
||||
private static async Task<List<PrideFlag>> GetFlagsAsync(this DatabaseContext db, Snowflake userId) =>
|
||||
await db.PrideFlags.Where(f => f.UserId == userId).OrderBy(f => f.Id).ToListAsync();
|
||||
private static async Task<List<PrideFlag>> GetFlagsAsync(
|
||||
this DatabaseContext db,
|
||||
Snowflake userId
|
||||
) => await db.PrideFlags.Where(f => f.UserId == userId).OrderBy(f => f.Id).ToListAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Sets the user's profile flags to the given IDs. Returns a validation error if any of the flag IDs are unknown
|
||||
/// or if too many IDs are given. Duplicates are allowed.
|
||||
/// </summary>
|
||||
public static async Task<ValidationError?> SetUserFlagsAsync(this DatabaseContext db, Snowflake userId,
|
||||
Snowflake[] flagIds)
|
||||
public static async Task<ValidationError?> SetUserFlagsAsync(
|
||||
this DatabaseContext db,
|
||||
Snowflake userId,
|
||||
Snowflake[] flagIds
|
||||
)
|
||||
{
|
||||
var currentFlags = await db.UserFlags.Where(f => f.UserId == userId).ToListAsync();
|
||||
foreach (var flag in currentFlags)
|
||||
db.UserFlags.Remove(flag);
|
||||
|
||||
// If there's no new flags to set, we're done
|
||||
if (flagIds.Length == 0) return null;
|
||||
if (flagIds.Length > 100) return ValidationError.LengthError("Too many profile flags", 0, 100, flagIds.Length);
|
||||
if (flagIds.Length == 0)
|
||||
return null;
|
||||
if (flagIds.Length > 100)
|
||||
return ValidationError.LengthError("Too many profile flags", 0, 100, flagIds.Length);
|
||||
|
||||
var flags = await db.GetFlagsAsync(userId);
|
||||
var unknownFlagIds = flagIds.Where(id => flags.All(f => f.Id != id)).ToArray();
|
||||
|
|
@ -34,24 +41,34 @@ public static class FlagQueryExtensions
|
|||
return null;
|
||||
}
|
||||
|
||||
public static async Task<ValidationError?> SetMemberFlagsAsync(this DatabaseContext db, Snowflake userId,
|
||||
Snowflake memberId, Snowflake[] flagIds)
|
||||
public static async Task<ValidationError?> SetMemberFlagsAsync(
|
||||
this DatabaseContext db,
|
||||
Snowflake userId,
|
||||
Snowflake memberId,
|
||||
Snowflake[] flagIds
|
||||
)
|
||||
{
|
||||
var currentFlags = await db.MemberFlags.Where(f => f.MemberId == memberId).ToListAsync();
|
||||
foreach (var flag in currentFlags)
|
||||
db.MemberFlags.Remove(flag);
|
||||
|
||||
if (flagIds.Length == 0) return null;
|
||||
if (flagIds.Length > 100) return ValidationError.LengthError("Too many profile flags", 0, 100, flagIds.Length);
|
||||
if (flagIds.Length == 0)
|
||||
return null;
|
||||
if (flagIds.Length > 100)
|
||||
return ValidationError.LengthError("Too many profile flags", 0, 100, flagIds.Length);
|
||||
|
||||
var flags = await db.GetFlagsAsync(userId);
|
||||
var unknownFlagIds = flagIds.Where(id => flags.All(f => f.Id != id)).ToArray();
|
||||
if (unknownFlagIds.Length != 0)
|
||||
return ValidationError.GenericValidationError("Unknown flag IDs", unknownFlagIds);
|
||||
|
||||
var memberFlags = flagIds.Select(id => new MemberFlag { PrideFlagId = id, MemberId = memberId });
|
||||
var memberFlags = flagIds.Select(id => new MemberFlag
|
||||
{
|
||||
PrideFlagId = id,
|
||||
MemberId = memberId,
|
||||
});
|
||||
db.MemberFlags.AddRange(memberFlags);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue