new app server and database + added hub and controller of user profile

This commit is contained in:
Artemy
2025-11-04 11:41:06 +07:00
parent 1d442d037c
commit a5a5fc4758
62 changed files with 1760 additions and 2543 deletions
@@ -35,7 +35,9 @@ public class MediaService : IMediaService
DateCreated = file.UploadedOn,
MediaType = file.Type,
MineType = file.MimeType,
Url = url
Url = url,
OwnerType = file.OwnerType,
OwnerId = file.OwnerId,
});
await _dbContext.SaveChangesAsync();
@@ -87,7 +89,9 @@ public class MediaService : IMediaService
contentBytes,
mediaFile.MediaType,
mediaFile.MineType,
string.Empty
string.Empty,
mediaFile.OwnerType,
mediaFile.OwnerId
);
}
catch (FileNotFoundException ex)
@@ -96,4 +100,24 @@ public class MediaService : IMediaService
throw;
}
}
public async Task AttachToMessageAsync(Guid mediaId, Guid messageId)
{
var mediaFile = await _dbContext.MediaFiles
.FirstOrDefaultAsync(x => x.Id == mediaId)
?? throw new KeyNotFoundException($"No media found by given id {mediaId}");
if (mediaFile.OwnerType != MediaOwnerType.Message)
{
_logger.LogWarning("Attempt to attach already owned media {MediaId}", mediaId);
throw new InvalidOperationException($"Media {mediaId} is already attached to {mediaFile.OwnerType}");
}
mediaFile.OwnerType = MediaOwnerType.Message;
mediaFile.OwnerId = messageId;
_dbContext.MediaFiles.Update(mediaFile);
await _dbContext.SaveChangesAsync();
_logger.LogInformation("Media {MediaId} successfully attached to message {MessageId}", mediaId, messageId);
}
}