Improved UserController validation

This commit is contained in:
Mia Rose Winter 2024-02-09 11:55:32 +01:00
parent ca1533f816
commit 0491678055
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E

View file

@ -1,4 +1,5 @@
using ImageMagick; using System.ComponentModel.DataAnnotations;
using ImageMagick;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OutputCaching; using Microsoft.AspNetCore.OutputCaching;
@ -18,7 +19,7 @@ public class UserController(ImageService imageService, IDbContextFactory<Applica
[OutputCache(Duration = 60*5)] [OutputCache(Duration = 60*5)]
[ResponseCache(Duration = 60*5, Location = ResponseCacheLocation.Any)] [ResponseCache(Duration = 60*5, Location = ResponseCacheLocation.Any)]
[Route("pfp/{userId}")] [Route("pfp/{userId}")]
public async Task<IActionResult> Get(string userId, [FromQuery] int size = 800) { public async Task<IActionResult> Get(string userId, [FromQuery, Range(16, 800)] int size = 800) {
if (size > 800) size = 800; if (size > 800) size = 800;
await using var context = await ContextFactory.CreateDbContextAsync(); await using var context = await ContextFactory.CreateDbContextAsync();
var user = await context.Users.Include(u => u.ProfilePicture).FirstOrDefaultAsync(u => u.Id == userId); var user = await context.Users.Include(u => u.ProfilePicture).FirstOrDefaultAsync(u => u.Id == userId);