Achieves 100% XML doc coverage on non-trivial types with CS1591 enforcement via Directory.Build.props. Coverage by project: - Butter: from 6.5% to 100% (DTOs, enums, MIME types) - Lactose: from ~28% to 100% (controllers, services, repos, jobs, models) - MilkStream.Client: from ~29% to 100% (all frontend services) Uses <inheritdoc /> on repository implementations (interfaces already documented) and full <summary>/<param>/<returns> tags elsewhere. Enums include member-level docs.
67 lines
2.2 KiB
C#
67 lines
2.2 KiB
C#
using Butter.Dtos;
|
|
using Lactose.Context;
|
|
using Lactose.Models;
|
|
|
|
namespace Lactose.Repositories;
|
|
|
|
/// <inheritdoc />
|
|
public class MediaRepository(LactoseDbContext context) : IMediaRepository {
|
|
/// <summary>
|
|
/// Trys to get the asset with the given ID, and checks if it is shared with the given user or public.
|
|
/// </summary>
|
|
/// <param name="id">Asset ID</param>
|
|
/// <param name="userId">UserID we are trying to get this as</param>
|
|
/// <returns></returns>
|
|
Asset? GetAssetAsUserId(Guid id, Guid? userId) {
|
|
// Should be equivalent to:
|
|
// media.IsPubliclyShared && media.SharedWith.Any(user => user.Id == userId)
|
|
return context.Assets.Include(asset => asset.SharedWith)
|
|
.FirstOrDefault(asset => asset.Id == id && (
|
|
asset.IsPubliclyShared ||
|
|
asset.SharedWith!.Any(user => user.Id == userId)
|
|
));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public MediaDto? GetOriginalData(Guid id, Guid? userId) {
|
|
|
|
var media = GetAssetAsUserId(id, userId);
|
|
|
|
if (media == null) return null;
|
|
|
|
return new MediaDto {
|
|
MimeType = media.MimeType,
|
|
Path = media.OriginalPath
|
|
};
|
|
}
|
|
|
|
//TODO: for Thumbnails the MimeType should be the correct one (depending on which format is used for thumbnails)
|
|
/// <inheritdoc />
|
|
public MediaDto? GetThumbData(Guid id, Guid? userId) {
|
|
var media = GetAssetAsUserId(id, userId);
|
|
|
|
if(media == null) return null;
|
|
|
|
if (media.ThumbnailPath == String.Empty) return null;
|
|
|
|
return new MediaDto {
|
|
MimeType = media.MimeType,
|
|
Path = media.ThumbnailPath
|
|
};
|
|
}
|
|
|
|
//TODO: for Previews the MimeType should be the correct one (depending on which format is used for previews and if the asset is a video)
|
|
/// <inheritdoc />
|
|
public MediaDto? GetPreviewData(Guid id, Guid? userId) {
|
|
var media = GetAssetAsUserId(id, userId);
|
|
|
|
if(media == null) return null;
|
|
|
|
if (media.PreviewPath == String.Empty) return null;
|
|
|
|
return new MediaDto {
|
|
MimeType = media.MimeType,
|
|
Path = media.PreviewPath
|
|
};
|
|
}
|
|
} |