feat(backend): ability to set profile flags, return profile flags in get user endpoint
This commit is contained in:
parent
6a4aa8064a
commit
a3cbdc1a08
4 changed files with 62 additions and 15 deletions
|
@ -24,17 +24,17 @@ public class FlagsController(
|
|||
|
||||
[HttpGet]
|
||||
[Authorize("identify")]
|
||||
[ProducesResponseType<IEnumerable<PrideFlagResponse>>(statusCode: StatusCodes.Status200OK)]
|
||||
[ProducesResponseType<IEnumerable<UserRendererService.PrideFlagResponse>>(statusCode: StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetFlagsAsync(CancellationToken ct = default)
|
||||
{
|
||||
var flags = await db.PrideFlags.Where(f => f.UserId == CurrentUser!.Id).ToListAsync(ct);
|
||||
|
||||
return Ok(flags.Select(ToResponse));
|
||||
return Ok(flags.Select(userRenderer.RenderPrideFlag));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize("user.update")]
|
||||
[ProducesResponseType<PrideFlagResponse>(statusCode: StatusCodes.Status202Accepted)]
|
||||
[ProducesResponseType<UserRendererService.PrideFlagResponse>(statusCode: StatusCodes.Status202Accepted)]
|
||||
public IActionResult CreateFlag([FromBody] CreateFlagRequest req)
|
||||
{
|
||||
ValidationUtils.Validate(ValidateFlag(req.Name, req.Description, req.Image));
|
||||
|
@ -68,7 +68,7 @@ public class FlagsController(
|
|||
db.Update(flag);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return Ok(ToResponse(flag));
|
||||
return Ok(userRenderer.RenderPrideFlag(flag));
|
||||
}
|
||||
|
||||
public class UpdateFlagRequest : PatchRequest
|
||||
|
@ -111,15 +111,6 @@ public class FlagsController(
|
|||
return NoContent();
|
||||
}
|
||||
|
||||
private PrideFlagResponse ToResponse(PrideFlag flag) =>
|
||||
new(flag.Id, userRenderer.ImageUrlFor(flag), flag.Name, flag.Description);
|
||||
|
||||
private record PrideFlagResponse(
|
||||
Snowflake Id,
|
||||
string ImageUrl,
|
||||
string Name,
|
||||
string? Description);
|
||||
|
||||
private static List<(string, ValidationError?)> ValidateFlag(string? name, string? description, string? imageData)
|
||||
{
|
||||
var errors = new List<(string, ValidationError?)>();
|
||||
|
|
|
@ -86,6 +86,12 @@ public class UsersController(
|
|||
user.Fields = req.Fields.ToList();
|
||||
}
|
||||
|
||||
if (req.Flags != null)
|
||||
{
|
||||
var flagError = await db.SetUserFlagsAsync(CurrentUser!.Id, req.Flags);
|
||||
if (flagError != null) errors.Add(("flags", flagError));
|
||||
}
|
||||
|
||||
if (req.HasProperty(nameof(req.Avatar)))
|
||||
errors.Add(("avatar", ValidationUtils.ValidateAvatar(req.Avatar)));
|
||||
|
||||
|
@ -182,6 +188,7 @@ public class UsersController(
|
|||
public FieldEntry[]? Names { get; init; }
|
||||
public Pronoun[]? Pronouns { get; init; }
|
||||
public Field[]? Fields { get; init; }
|
||||
public Snowflake[]? Flags { get; init; }
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue