[backend/api] Move newAvatarAlt and newBannerAlt into UserProfileEntity

This commit is contained in:
pancakes 2024-12-20 17:17:53 +10:00 committed by Laura Hausmann
parent 811c5d7a46
commit 58d10228e9
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 7 additions and 7 deletions

View file

@ -53,9 +53,7 @@ public class ProfileController(
[HttpPut] [HttpPut]
[Consumes(MediaTypeNames.Application.Json)] [Consumes(MediaTypeNames.Application.Json)]
[ProducesResults(HttpStatusCode.OK)] [ProducesResults(HttpStatusCode.OK)]
public async Task UpdateProfile( public async Task UpdateProfile(UserProfileEntity newProfile)
UserProfileEntity newProfile, [FromQuery] string? newAvatarAlt, [FromQuery] string? newBannerAlt
)
{ {
var user = HttpContext.GetUserOrFail(); var user = HttpContext.GetUserOrFail();
var profile = user.UserProfile ?? throw new Exception("Local user must have profile"); var profile = user.UserProfile ?? throw new Exception("Local user must have profile");
@ -87,7 +85,7 @@ public class ProfileController(
user.IsCat = newProfile.IsCat; user.IsCat = newProfile.IsCat;
user.SpeakAsCat = newProfile is { SpeakAsCat: true, IsCat: true }; user.SpeakAsCat = newProfile is { SpeakAsCat: true, IsCat: true };
if (newAvatarAlt != null) if (newProfile.AvatarAlt != null)
{ {
var avatar = await db.DriveFiles var avatar = await db.DriveFiles
.FirstOrDefaultAsync(p => p.UserId == user.Id && p.UserAvatar != null); .FirstOrDefaultAsync(p => p.UserId == user.Id && p.UserAvatar != null);
@ -95,10 +93,10 @@ public class ProfileController(
if (avatar != null) if (avatar != null)
{ {
user.Avatar = avatar; user.Avatar = avatar;
user.Avatar.Comment = string.IsNullOrWhiteSpace(newAvatarAlt) ? null : newAvatarAlt.Trim(); user.Avatar.Comment = string.IsNullOrWhiteSpace(newProfile.AvatarAlt) ? null : newProfile.AvatarAlt.Trim();
} }
} }
if (newBannerAlt != null) if (newProfile.BannerAlt != null)
{ {
var banner = await db.DriveFiles var banner = await db.DriveFiles
.FirstOrDefaultAsync(p => p.UserId == user.Id && p.UserBanner != null); .FirstOrDefaultAsync(p => p.UserId == user.Id && p.UserBanner != null);
@ -106,7 +104,7 @@ public class ProfileController(
if (banner != null) if (banner != null)
{ {
user.Banner = banner; user.Banner = banner;
user.Banner.Comment = string.IsNullOrWhiteSpace(newBannerAlt) ? null : newBannerAlt.Trim(); user.Banner.Comment = string.IsNullOrWhiteSpace(newProfile.BannerAlt) ? null : newProfile.BannerAlt.Trim();
} }
} }
var prevAvatarId = user.AvatarId; var prevAvatarId = user.AvatarId;

View file

@ -18,6 +18,8 @@ public class UserProfileEntity
public required List<Field> Fields { get; set; } public required List<Field> Fields { get; set; }
public required FFVisibilityEnum FFVisibility { get; set; } public required FFVisibilityEnum FFVisibility { get; set; }
public required string DisplayName { get; set; } public required string DisplayName { get; set; }
public string? AvatarAlt { get; set; }
public string? BannerAlt { get; set; }
public required bool IsBot { get; set; } public required bool IsBot { get; set; }
public required bool IsCat { get; set; } public required bool IsCat { get; set; }