mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-06-05 23:50:14 +08:00
feat(album): add cover picture functionality to albums and enhance album management API
This commit is contained in:
12
Services/Mapping/IMappingService.cs
Normal file
12
Services/Mapping/IMappingService.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
70
Services/Mapping/MappingService.cs
Normal file
70
Services/Mapping/MappingService.cs
Normal 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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user