MyBookmark/Modules.Library.Domain/Interactors/MediaInfoInteractor.cs
2024-09-04 23:08:56 +03:00

40 lines
1.8 KiB
C#

using Modules.Library.Domain.Entities;
using Modules.Library.Domain.Entities.MediaContent;
//using Modules.Library.Domain.Exceptions.MediaContent;
using Modules.Library.Domain.Gateways;
namespace Modules.Library.Domain.Interactors;
public class MediaInfoInteractor(IMediaInfoGateway gateway)
{
public async Task<Guid> Create(string url, MediaInfoType type)
{
//if (!user.CanAddMediaInfo()) throw new Exception("AccessDenied");
if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(url);
//if (await gateway.GetFirstOrDefaultWhere(q => q.Name == name) != null) throw new MediaInfoIsAlreadyExistException();
var newMediaInfo = new MediaInfo(url, type);
return await gateway.AddAsync(newMediaInfo);
}
public async Task Edit(Guid mediaInfoId, string url, MediaInfoType type)
{
//if (!user.CanEditMediaInfo()) throw new Exception("AccessDenied");
if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(url);
var mediaInfo = await gateway.GetByIdAsync(mediaInfoId);
//if (await gateway.GetFirstOrDefaultWhere(q => q.Name == name) != null) throw new MediaInfoWithSameUrlIsAlreadyExistException();
mediaInfo.SetUrl(url);
mediaInfo.SetType(type);
if (!await gateway.UpdateAsync(mediaInfo)) throw new Exception("Save unsuccessfull");
}
public async Task Delete(Guid mediaInfoId)
{
//if (!user.CanRemoveMediaInfo()) throw new Exception("AccessDenied");
var mediaInfo = await gateway.GetByIdAsync(mediaInfoId);
//await gateway.DeleteAsync(genre);
if (mediaInfo.Deleted) throw new Exception("AlreadyDeleted");
mediaInfo.SetDeleted();
if (!await gateway.UpdateAsync(mediaInfo)) throw new Exception("Save unsuccessfull");
}
}