feat(album): add cover picture functionality to albums and enhance album management API

This commit is contained in:
shiyu
2025-06-09 15:12:50 +08:00
parent 9d9393f9ce
commit e55f311c04
24 changed files with 1496 additions and 251 deletions

View File

@@ -0,0 +1,12 @@
using Foxel.Models.DataBase;
using Foxel.Models.Response.Album;
using Foxel.Models.Response.Picture;
namespace Foxel.Services.Mapping
{
public interface IMappingService
{
AlbumResponse MapAlbumToResponse(Album album);
PictureResponse MapPictureToResponse(Picture picture);
}
}

View File

@@ -0,0 +1,70 @@
using Foxel.Models.DataBase;
using Foxel.Models.Response.Album;
using Foxel.Models.Response.Picture;
using Foxel.Services.Storage;
namespace Foxel.Services.Mapping
{
public class MappingService(IStorageService storageService)
: IMappingService
{
public AlbumResponse MapAlbumToResponse(Album album)
{
string? coverPath = null;
string? coverThumbnailPath = null;
if (album.CoverPicture != null)
{
coverPath = storageService.ExecuteAsync(album.CoverPicture.StorageModeId,
provider => Task.FromResult(provider.GetUrl(album.CoverPicture.Id, album.CoverPicture.Path)))
.Result; // Consider making this async if possible in the future
if (!string.IsNullOrEmpty(album.CoverPicture.ThumbnailPath))
{
coverThumbnailPath = storageService.ExecuteAsync(album.CoverPicture.StorageModeId,
provider => Task.FromResult(provider.GetUrl(album.CoverPicture.Id,
album.CoverPicture.ThumbnailPath))).Result; // Consider async
}
}
return new AlbumResponse
{
Id = album.Id,
Name = album.Name,
Description = album.Description,
UserId = album.UserId,
Username = album.User.UserName,
CreatedAt = album.CreatedAt,
UpdatedAt = album.UpdatedAt,
CoverPicturePath = coverPath,
CoverPictureThumbnailPath = coverThumbnailPath,
PictureCount = album.Pictures?.Count ?? 0
};
}
public PictureResponse MapPictureToResponse(Picture picture)
{
return new PictureResponse
{
Id = picture.Id,
Name = picture.Name,
Path = storageService.ExecuteAsync(picture.StorageModeId, provider =>
Task.FromResult(provider.GetUrl(picture.Id, picture.Path))).Result,
ThumbnailPath = storageService.ExecuteAsync(picture.StorageModeId, provider =>
Task.FromResult(provider.GetUrl(picture.Id, picture.ThumbnailPath ?? string.Empty)))
.Result,
Description = picture.Description,
CreatedAt = picture.CreatedAt,
TakenAt = picture.TakenAt,
ExifInfo = picture.ExifInfo,
UserId = picture.UserId,
Username = picture.User?.UserName,
Tags = picture.Tags?.Select(t => t.Name).ToList(),
AlbumId = picture.AlbumId,
AlbumName = picture.Album?.Name,
Permission = picture.Permission,
FavoriteCount = picture.Favorites?.Count ?? 0,
StorageModeName = picture.StorageMode?.Name
};
}
}
}