feat(frontend): add username editing

This commit is contained in:
sam 2024-10-01 16:06:02 +02:00
parent 5a8b7aae80
commit 2a66e3e25e
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
10 changed files with 164 additions and 23 deletions

View file

@ -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);
}

View file

@ -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