[backend/api] Simplify GetAvatar and GetBanner database queries
This commit is contained in:
parent
b9cb72475d
commit
f40c0e2499
2 changed files with 5 additions and 13 deletions
|
@ -127,11 +127,8 @@ public class ProfileController(
|
|||
{
|
||||
var user = HttpContext.GetUserOrFail();
|
||||
|
||||
var file = await db.Users
|
||||
.IncludeCommonProperties()
|
||||
.Where(p => p.Id == user.Id)
|
||||
.Select(p => p.Avatar)
|
||||
.FirstOrDefaultAsync()
|
||||
var file = await db.DriveFiles
|
||||
.FirstOrDefaultAsync(p => p.UserId == user.Id && p.UserAvatar != null)
|
||||
?? throw GracefulException.RecordNotFound();
|
||||
|
||||
return new DriveFileResponse
|
||||
|
@ -200,11 +197,8 @@ public class ProfileController(
|
|||
{
|
||||
var user = HttpContext.GetUserOrFail();
|
||||
|
||||
var file = await db.Users
|
||||
.IncludeCommonProperties()
|
||||
.Where(p => p.Id == user.Id)
|
||||
.Select(p => p.Banner)
|
||||
.FirstOrDefaultAsync()
|
||||
var file = await db.DriveFiles
|
||||
.FirstOrDefaultAsync(p => p.UserId == user.Id && p.UserBanner != null)
|
||||
?? throw GracefulException.RecordNotFound();
|
||||
|
||||
return new DriveFileResponse
|
||||
|
|
|
@ -714,9 +714,7 @@ public static class QueryableExtensions
|
|||
|
||||
public static IQueryable<User> IncludeCommonProperties(this IQueryable<User> query)
|
||||
{
|
||||
return query.Include(p => p.UserProfile)
|
||||
.Include(p => p.Avatar)
|
||||
.Include(p => p.Banner);
|
||||
return query.Include(p => p.UserProfile);
|
||||
}
|
||||
|
||||
public static IQueryable<Bite> IncludeCommonProperties(this IQueryable<Bite> query)
|
||||
|
|
Loading…
Add table
Reference in a new issue