feat(frontend): add username editing
This commit is contained in:
parent
5a8b7aae80
commit
2a66e3e25e
10 changed files with 164 additions and 23 deletions
|
@ -22,19 +22,27 @@ public class MetaController : ApiControllerBase
|
|||
),
|
||||
new Limits(
|
||||
MemberCount: MembersController.MaxMemberCount,
|
||||
BioLength: ValidationUtils.MaxBioLength))
|
||||
BioLength: ValidationUtils.MaxBioLength,
|
||||
CustomPreferences: UsersController.MaxCustomPreferences))
|
||||
);
|
||||
}
|
||||
|
||||
[HttpGet("/api/v2/coffee")]
|
||||
public IActionResult BrewCoffee() => Problem("Sorry, I'm a teapot!", statusCode: StatusCodes.Status418ImATeapot);
|
||||
|
||||
private record MetaResponse(string Repository, string Version, string Hash, int Members, UserInfo Users, Limits Limits);
|
||||
private record MetaResponse(
|
||||
string Repository,
|
||||
string Version,
|
||||
string Hash,
|
||||
int Members,
|
||||
UserInfo Users,
|
||||
Limits Limits);
|
||||
|
||||
private record UserInfo(int Total, int ActiveMonth, int ActiveWeek, int ActiveDay);
|
||||
|
||||
// All limits that the frontend should know about (for UI purposes)
|
||||
private record Limits(
|
||||
int MemberCount,
|
||||
int BioLength);
|
||||
int BioLength,
|
||||
int CustomPreferences);
|
||||
}
|
|
@ -177,14 +177,16 @@ public class UsersController(
|
|||
public bool Favourite { get; set; }
|
||||
}
|
||||
|
||||
public const int MaxCustomPreferences = 25;
|
||||
|
||||
private static List<(string, ValidationError?)> ValidateCustomPreferences(
|
||||
List<CustomPreferencesUpdateRequest> preferences)
|
||||
{
|
||||
var errors = new List<(string, ValidationError?)>();
|
||||
|
||||
if (preferences.Count > 25)
|
||||
if (preferences.Count > MaxCustomPreferences)
|
||||
errors.Add(("custom_preferences",
|
||||
ValidationError.LengthError("Too many custom preferences", 0, 25, preferences.Count)));
|
||||
ValidationError.LengthError("Too many custom preferences", 0, MaxCustomPreferences, preferences.Count)));
|
||||
if (preferences.Count > 50) return errors;
|
||||
|
||||
// TODO: validate individual preferences
|
||||
|
|
|
@ -43,6 +43,7 @@ public class UserRendererService(DatabaseContext db, MemberRendererService membe
|
|||
user.Links,
|
||||
user.Names, user.Pronouns, user.Fields, user.CustomPreferences,
|
||||
flags.Select(f => RenderPrideFlag(f.PrideFlag)),
|
||||
user.Role,
|
||||
renderMembers ? members.Select(m => memberRenderer.RenderPartialMember(m, tokenHidden)) : null,
|
||||
renderAuthMethods
|
||||
? authMethods.Select(a => new AuthenticationMethodResponse(
|
||||
|
@ -78,6 +79,8 @@ public class UserRendererService(DatabaseContext db, MemberRendererService membe
|
|||
IEnumerable<Field> Fields,
|
||||
Dictionary<Snowflake, User.CustomPreference> CustomPreferences,
|
||||
IEnumerable<PrideFlagResponse> Flags,
|
||||
[property: JsonConverter(typeof(ScreamingSnakeCaseEnumConverter))]
|
||||
UserRole Role,
|
||||
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
IEnumerable<MemberRendererService.PartialMember>? Members,
|
||||
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue