From 59887f98635b8c57ba6516d2eb2ddf1be74d29b6 Mon Sep 17 00:00:00 2001 From: Denis Prokhorchik Date: Sun, 12 Jun 2022 17:57:43 +0300 Subject: [PATCH 1/2] feat(issue-385): add loader for cloudinary --- .../O2NextGen.Sdk.NetCore.Models.csproj | 4 + .../media-basket/MediaViewModel.cs | 18 +- .../Controllers/MediaController.cs | 31 +- .../O2NextGen.MediaBasket.Api/Dockerfile | 4 +- .../Helpers/AccountCloudStorage.cs | 16 + .../Helpers/CloudinarySettings.cs | 9 + .../Helpers/FileExt.cs | 10 + .../Helpers/MimeTypes.cs | 597 ++++++++++++++++++ .../Helpers/Singleton.cs | 38 ++ .../Helpers/TypeTable.cs | 10 + .../IoC/ServiceCollectionExtensions.cs | 4 +- .../Mappings/MediaMappings.cs | 22 + .../O2NextGen.MediaBasket.Api.csproj | 1 + .../Services/AzureStorageService.cs | 18 + .../Services/CloudStorage.cs | 26 + .../Services/CloudinaryStorageService.cs | 77 +++ .../O2NextGen.MediaBasket.Api/Startup.cs | 27 + .../Models/Media.cs | 13 + .../O2NextGen.MediaBasket.Business.csproj | 4 + .../Services/ICloudStorageManager.cs | 13 + .../Services/IMediaService.cs | 4 +- .../Entities/MediaEntity.cs | 1 + .../Mappings/MediaMappings.cs | 14 +- .../O2NextGen.MediaBasket.Impl.csproj | 3 + .../Services/InMemoryMediaService.cs | 10 +- .../Services/MediaService.cs | 9 +- .../Helpers/ServiceCollectionExtensions.cs | 1 - src/docker-compose.override.yml | 12 + src/docker-compose.yml | 6 + 29 files changed, 979 insertions(+), 23 deletions(-) create mode 100644 src/Services/media-basket/O2NextGen.MediaBasket.Api/Helpers/AccountCloudStorage.cs create mode 100644 src/Services/media-basket/O2NextGen.MediaBasket.Api/Helpers/CloudinarySettings.cs create mode 100644 src/Services/media-basket/O2NextGen.MediaBasket.Api/Helpers/FileExt.cs create mode 100644 src/Services/media-basket/O2NextGen.MediaBasket.Api/Helpers/MimeTypes.cs create mode 100644 src/Services/media-basket/O2NextGen.MediaBasket.Api/Helpers/Singleton.cs create mode 100644 src/Services/media-basket/O2NextGen.MediaBasket.Api/Helpers/TypeTable.cs create mode 100644 src/Services/media-basket/O2NextGen.MediaBasket.Api/Services/AzureStorageService.cs create mode 100644 src/Services/media-basket/O2NextGen.MediaBasket.Api/Services/CloudStorage.cs create mode 100644 src/Services/media-basket/O2NextGen.MediaBasket.Api/Services/CloudinaryStorageService.cs create mode 100644 src/Services/media-basket/O2NextGen.MediaBasket.Business/Services/ICloudStorageManager.cs diff --git a/src/SDKs/O2NG.Sdk.NetCore/O2NG.Sdk.NetCore.Models/O2NextGen.Sdk.NetCore.Models.csproj b/src/SDKs/O2NG.Sdk.NetCore/O2NG.Sdk.NetCore.Models/O2NextGen.Sdk.NetCore.Models.csproj index 2bd48b21..84a4445b 100644 --- a/src/SDKs/O2NG.Sdk.NetCore/O2NG.Sdk.NetCore.Models/O2NextGen.Sdk.NetCore.Models.csproj +++ b/src/SDKs/O2NG.Sdk.NetCore/O2NG.Sdk.NetCore.Models/O2NextGen.Sdk.NetCore.Models.csproj @@ -4,4 +4,8 @@ netcoreapp2.2 + + + + diff --git a/src/SDKs/O2NG.Sdk.NetCore/O2NG.Sdk.NetCore.Models/media-basket/MediaViewModel.cs b/src/SDKs/O2NG.Sdk.NetCore/O2NG.Sdk.NetCore.Models/media-basket/MediaViewModel.cs index e0f99e19..98c83840 100644 --- a/src/SDKs/O2NG.Sdk.NetCore/O2NG.Sdk.NetCore.Models/media-basket/MediaViewModel.cs +++ b/src/SDKs/O2NG.Sdk.NetCore/O2NG.Sdk.NetCore.Models/media-basket/MediaViewModel.cs @@ -1,8 +1,24 @@ -namespace O2NextGen.Sdk.NetCore.Models.media_basket +using System; +using Microsoft.AspNetCore.Http; + +namespace O2NextGen.Sdk.NetCore.Models.media_basket { public class MediaViewModel { public long Id { get; set; } public string Name { get; set; } + public string Url { get; set; } + public string Description { get; set; } + public DateTime? DateAdded { get; set; } + public string PublicId { get; set; } + public string AccountId { get; set; } + public IFormFile File { get; set; } + public string PreviewUrl { get; set; } + public int? Height { get; set; } + public int? Width { get; set; } + public string ExtType { get; set; } + public string ContentType { get; set; } + public string MediaType { get; set; } + public string OriginalName { get; set; } } } diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Api/Controllers/MediaController.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Controllers/MediaController.cs index 72a84523..a586807f 100644 --- a/src/Services/media-basket/O2NextGen.MediaBasket.Api/Controllers/MediaController.cs +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Controllers/MediaController.cs @@ -1,6 +1,8 @@ +using System; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; using O2NextGen.MediaBasket.Api.Mappings; using O2NextGen.MediaBasket.Api.Setup; using O2NextGen.MediaBasket.Business.Services; @@ -15,16 +17,18 @@ public class MediaController : ControllerBase private readonly IMediaService _mediaService; private readonly UrlsConfig _config; + private readonly ILogger _logger; #endregion #region Ctors - public MediaController(IMediaService mediaService, UrlsConfig config) + public MediaController(IMediaService mediaService, UrlsConfig config,ILogger logger) { - _mediaService = mediaService; - _config = config; + _mediaService = mediaService ?? throw new ArgumentException(nameof(mediaService)); + _config = config ?? throw new ArgumentException(nameof(config)); + _logger = logger; } #endregion @@ -36,6 +40,7 @@ public MediaController(IMediaService mediaService, UrlsConfig config) [Route("")] public async Task GetAllAsync() { + _logger.LogInformation($"Execute method - {nameof(GetAllAsync)}"); var url = _config.Auth; var models = await _mediaService.GetAllAsync(CancellationToken.None); return Ok(models.ToViewModel()); @@ -45,27 +50,30 @@ public async Task GetAllAsync() [Route("{id}")] public async Task GetByIdAsync(long id, CancellationToken ct) { - var certificate = await _mediaService.GetByIdAsync(id, ct); - if (certificate == null) + _logger.LogInformation($"Execute method - {nameof(GetByIdAsync)}"); + var media = await _mediaService.GetByIdAsync(id, ct); + if (media == null) return NotFound(); - return Ok(certificate.ToViewModel()); + return Ok(media.ToViewModel()); } [HttpPut] [Route("id")] public async Task UpdateAsync(long id, MediaViewModel model, CancellationToken ct) { - var certificate = await _mediaService.UpdateAsync(model.ToModel(), ct); - return Ok(certificate.ToViewModel()); + _logger.LogInformation($"Execute method - {nameof(UpdateAsync)}"); + var media = await _mediaService.UpdateAsync(model.ToModel(), ct); + return Ok(media.ToViewModel()); } [HttpPost] [HttpPut] [Route("")] - public async Task AddAsync(MediaViewModel model, CancellationToken ct) + public async Task AddAsync([FromForm]MediaViewModel model, CancellationToken ct) { - var certificate = await _mediaService.AddAsync(model.ToModel(), ct); - return CreatedAtAction(nameof(GetByIdAsync), new {id = certificate.Id}, certificate); + _logger.LogInformation($"Execute method - {nameof(AddAsync)}"); + var media = await _mediaService.AddAsync(model.ToModel(), model.File, ct); + return CreatedAtAction(nameof(GetByIdAsync), new {id = media.Id}, media); } #endregion @@ -74,6 +82,7 @@ public async Task AddAsync(MediaViewModel model, CancellationToke [Route("id")] public async Task RemoveAsync(long id,CancellationToken ct) { + _logger.LogInformation($"Execute method - {nameof(RemoveAsync)}"); await _mediaService.RemoveAsync(id, ct); return NoContent(); } diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Api/Dockerfile b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Dockerfile index 9d88b0b7..b25ab4de 100644 --- a/src/Services/media-basket/O2NextGen.MediaBasket.Api/Dockerfile +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Dockerfile @@ -1,11 +1,11 @@ #See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. -FROM mcr.microsoft.com/dotnet/aspnet:2.2 AS base +FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS base WORKDIR /app EXPOSE 80 EXPOSE 443 -FROM mcr.microsoft.com/dotnet/sdk:2.2 AS build +FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build WORKDIR /src COPY ["Services/media-basket/O2NextGen.MediaBasket.Api/O2NextGen.MediaBasket.Api.csproj", "Services/media-basket/O2NextGen.MediaBasket.Api/"] COPY ["Services/media-basket/O2NextGen.MediaBasket.Impl/O2NextGen.MediaBasket.Impl.csproj", "Services/media-basket/O2NextGen.MediaBasket.Impl/"] diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Api/Helpers/AccountCloudStorage.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Helpers/AccountCloudStorage.cs new file mode 100644 index 00000000..ef18fbb0 --- /dev/null +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Helpers/AccountCloudStorage.cs @@ -0,0 +1,16 @@ +namespace O2NextGen.MediaBasket.Api.Helpers +{ + public enum StorageType + { + Cloudinary, + Azure + } + public class AccountCloudStorage + { + public string AccountName { get; set; } + public string Container { get; set; } + public string AccountKey { get; set; } + public TypeTable TypeTable { get; set; } + public StorageType StorageType { get; set; } + } +} \ No newline at end of file diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Api/Helpers/CloudinarySettings.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Helpers/CloudinarySettings.cs new file mode 100644 index 00000000..5919dd49 --- /dev/null +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Helpers/CloudinarySettings.cs @@ -0,0 +1,9 @@ +namespace O2NextGen.MediaBasket.Api.Helpers +{ + public class CloudinarySettings + { + public string CloudName { get; set; } + public string ApiKey { get; set; } + public string ApiSecret { get; set; } + } +} \ No newline at end of file diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Api/Helpers/FileExt.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Helpers/FileExt.cs new file mode 100644 index 00000000..8423ddd2 --- /dev/null +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Helpers/FileExt.cs @@ -0,0 +1,10 @@ +namespace O2NextGen.MediaBasket.Api.Helpers +{ + public static class FileExt + { + public static string GetFileExtension(this string fileName) + { + return System.IO.Path.GetExtension(fileName).ToLower(); + } + } +} \ No newline at end of file diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Api/Helpers/MimeTypes.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Helpers/MimeTypes.cs new file mode 100644 index 00000000..2b23563e --- /dev/null +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Helpers/MimeTypes.cs @@ -0,0 +1,597 @@ +using System; +using System.Collections.Generic; + +namespace O2NextGen.MediaBasket.Api.Helpers +{ + public static class MimeTypes + { + private static IDictionary _mappings = + new Dictionary(StringComparer.InvariantCultureIgnoreCase) + { + #region Big freaking list of mime types + + // combination of values from Windows 7 Registry and + // from C:\Windows\System32\inetsrv\config\applicationHost.config + // some added, including .7z and .dat + { ".323", "text/h323" }, + { ".3g2", "video/3gpp2" }, + { ".3gp", "video/3gpp" }, + { ".3gp2", "video/3gpp2" }, + { ".3gpp", "video/3gpp" }, + { ".7z", "application/x-7z-compressed" }, + { ".aa", "audio/audible" }, + { ".AAC", "audio/aac" }, + { ".aaf", "application/octet-stream" }, + { ".aax", "audio/vnd.audible.aax" }, + { ".ac3", "audio/ac3" }, + { ".aca", "application/octet-stream" }, + { ".accda", "application/msaccess.addin" }, + { ".accdb", "application/msaccess" }, + { ".accdc", "application/msaccess.cab" }, + { ".accde", "application/msaccess" }, + { ".accdr", "application/msaccess.runtime" }, + { ".accdt", "application/msaccess" }, + { ".accdw", "application/msaccess.webapplication" }, + { ".accft", "application/msaccess.ftemplate" }, + { ".acx", "application/internet-property-stream" }, + { ".AddIn", "text/xml" }, + { ".ade", "application/msaccess" }, + { ".adobebridge", "application/x-bridge-url" }, + { ".adp", "application/msaccess" }, + { ".ADT", "audio/vnd.dlna.adts" }, + { ".ADTS", "audio/aac" }, + { ".afm", "application/octet-stream" }, + { ".ai", "application/postscript" }, + { ".aif", "audio/x-aiff" }, + { ".aifc", "audio/aiff" }, + { ".aiff", "audio/aiff" }, + { ".air", "application/vnd.adobe.air-application-installer-package+zip" }, + { ".amc", "application/x-mpeg" }, + { ".application", "application/x-ms-application" }, + { ".art", "image/x-jg" }, + { ".asa", "application/xml" }, + { ".asax", "application/xml" }, + { ".ascx", "application/xml" }, + { ".asd", "application/octet-stream" }, + { ".asf", "video/x-ms-asf" }, + { ".ashx", "application/xml" }, + { ".asi", "application/octet-stream" }, + { ".asm", "text/plain" }, + { ".asmx", "application/xml" }, + { ".aspx", "application/xml" }, + { ".asr", "video/x-ms-asf" }, + { ".asx", "video/x-ms-asf" }, + { ".atom", "application/atom+xml" }, + { ".au", "audio/basic" }, + { ".avi", "video/x-msvideo" }, + { ".axs", "application/olescript" }, + { ".bas", "text/plain" }, + { ".bcpio", "application/x-bcpio" }, + { ".bin", "application/octet-stream" }, + { ".bmp", "image/bmp" }, + { ".c", "text/plain" }, + { ".cab", "application/octet-stream" }, + { ".caf", "audio/x-caf" }, + { ".calx", "application/vnd.ms-office.calx" }, + { ".cat", "application/vnd.ms-pki.seccat" }, + { ".cc", "text/plain" }, + { ".cd", "text/plain" }, + { ".cdda", "audio/aiff" }, + { ".cdf", "application/x-cdf" }, + { ".cer", "application/x-x509-ca-cert" }, + { ".chm", "application/octet-stream" }, + { ".class", "application/x-java-applet" }, + { ".clp", "application/x-msclip" }, + { ".cmx", "image/x-cmx" }, + { ".cnf", "text/plain" }, + { ".cod", "image/cis-cod" }, + { ".config", "application/xml" }, + { ".contact", "text/x-ms-contact" }, + { ".coverage", "application/xml" }, + { ".cpio", "application/x-cpio" }, + { ".cpp", "text/plain" }, + { ".crd", "application/x-mscardfile" }, + { ".crl", "application/pkix-crl" }, + { ".crt", "application/x-x509-ca-cert" }, + { ".cs", "text/plain" }, + { ".csdproj", "text/plain" }, + { ".csh", "application/x-csh" }, + { ".csproj", "text/plain" }, + { ".css", "text/css" }, + { ".csv", "text/csv" }, + { ".cur", "application/octet-stream" }, + { ".cxx", "text/plain" }, + { ".dat", "application/octet-stream" }, + { ".datasource", "application/xml" }, + { ".dbproj", "text/plain" }, + { ".dcr", "application/x-director" }, + { ".def", "text/plain" }, + { ".deploy", "application/octet-stream" }, + { ".der", "application/x-x509-ca-cert" }, + { ".dgml", "application/xml" }, + { ".dib", "image/bmp" }, + { ".dif", "video/x-dv" }, + { ".dir", "application/x-director" }, + { ".disco", "text/xml" }, + { ".dll", "application/x-msdownload" }, + { ".dll.config", "text/xml" }, + { ".dlm", "text/dlm" }, + { ".doc", "application/msword" }, + { ".docm", "application/vnd.ms-word.document.macroEnabled.12" }, + { ".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document" }, + { ".dot", "application/msword" }, + { ".dotm", "application/vnd.ms-word.template.macroEnabled.12" }, + { ".dotx", "application/vnd.openxmlformats-officedocument.wordprocessingml.template" }, + { ".dsp", "application/octet-stream" }, + { ".dsw", "text/plain" }, + { ".dtd", "text/xml" }, + { ".dtsConfig", "text/xml" }, + { ".dv", "video/x-dv" }, + { ".dvi", "application/x-dvi" }, + { ".dwf", "drawing/x-dwf" }, + { ".dwp", "application/octet-stream" }, + { ".dxr", "application/x-director" }, + { ".eml", "message/rfc822" }, + { ".emz", "application/octet-stream" }, + { ".eot", "application/octet-stream" }, + { ".eps", "application/postscript" }, + { ".etl", "application/etl" }, + { ".etx", "text/x-setext" }, + { ".evy", "application/envoy" }, + { ".exe", "application/octet-stream" }, + { ".exe.config", "text/xml" }, + { ".fdf", "application/vnd.fdf" }, + { ".fif", "application/fractals" }, + { ".filters", "Application/xml" }, + { ".fla", "application/octet-stream" }, + { ".flr", "x-world/x-vrml" }, + { ".flv", "video/x-flv" }, + { ".fsscript", "application/fsharp-script" }, + { ".fsx", "application/fsharp-script" }, + { ".generictest", "application/xml" }, + { ".gif", "image/gif" }, + { ".group", "text/x-ms-group" }, + { ".gsm", "audio/x-gsm" }, + { ".gtar", "application/x-gtar" }, + { ".gz", "application/x-gzip" }, + { ".h", "text/plain" }, + { ".hdf", "application/x-hdf" }, + { ".hdml", "text/x-hdml" }, + { ".hhc", "application/x-oleobject" }, + { ".hhk", "application/octet-stream" }, + { ".hhp", "application/octet-stream" }, + { ".hlp", "application/winhlp" }, + { ".hpp", "text/plain" }, + { ".hqx", "application/mac-binhex40" }, + { ".hta", "application/hta" }, + { ".htc", "text/x-component" }, + { ".htm", "text/html" }, + { ".html", "text/html" }, + { ".htt", "text/webviewhtml" }, + { ".hxa", "application/xml" }, + { ".hxc", "application/xml" }, + { ".hxd", "application/octet-stream" }, + { ".hxe", "application/xml" }, + { ".hxf", "application/xml" }, + { ".hxh", "application/octet-stream" }, + { ".hxi", "application/octet-stream" }, + { ".hxk", "application/xml" }, + { ".hxq", "application/octet-stream" }, + { ".hxr", "application/octet-stream" }, + { ".hxs", "application/octet-stream" }, + { ".hxt", "text/html" }, + { ".hxv", "application/xml" }, + { ".hxw", "application/octet-stream" }, + { ".hxx", "text/plain" }, + { ".i", "text/plain" }, + { ".ico", "image/x-icon" }, + { ".ics", "application/octet-stream" }, + { ".idl", "text/plain" }, + { ".ief", "image/ief" }, + { ".iii", "application/x-iphone" }, + { ".inc", "text/plain" }, + { ".inf", "application/octet-stream" }, + { ".inl", "text/plain" }, + { ".ins", "application/x-internet-signup" }, + { ".ipa", "application/x-itunes-ipa" }, + { ".ipg", "application/x-itunes-ipg" }, + { ".ipproj", "text/plain" }, + { ".ipsw", "application/x-itunes-ipsw" }, + { ".iqy", "text/x-ms-iqy" }, + { ".isp", "application/x-internet-signup" }, + { ".ite", "application/x-itunes-ite" }, + { ".itlp", "application/x-itunes-itlp" }, + { ".itms", "application/x-itunes-itms" }, + { ".itpc", "application/x-itunes-itpc" }, + { ".IVF", "video/x-ivf" }, + { ".jar", "application/java-archive" }, + { ".java", "application/octet-stream" }, + { ".jck", "application/liquidmotion" }, + { ".jcz", "application/liquidmotion" }, + { ".jfif", "image/pjpeg" }, + { ".jnlp", "application/x-java-jnlp-file" }, + { ".jpb", "application/octet-stream" }, + { ".jpe", "image/jpeg" }, + { ".jpeg", "image/jpeg" }, + { ".jpg", "image/jpeg" }, + { ".js", "application/x-javascript" }, + { ".json", "application/json" }, + { ".jsx", "text/jscript" }, + { ".jsxbin", "text/plain" }, + { ".latex", "application/x-latex" }, + { ".library-ms", "application/windows-library+xml" }, + { ".lit", "application/x-ms-reader" }, + { ".loadtest", "application/xml" }, + { ".lpk", "application/octet-stream" }, + { ".lsf", "video/x-la-asf" }, + { ".lst", "text/plain" }, + { ".lsx", "video/x-la-asf" }, + { ".lzh", "application/octet-stream" }, + { ".m13", "application/x-msmediaview" }, + { ".m14", "application/x-msmediaview" }, + { ".m1v", "video/mpeg" }, + { ".m2t", "video/vnd.dlna.mpeg-tts" }, + { ".m2ts", "video/vnd.dlna.mpeg-tts" }, + { ".m2v", "video/mpeg" }, + { ".m3u", "audio/x-mpegurl" }, + { ".m3u8", "audio/x-mpegurl" }, + { ".m4a", "audio/m4a" }, + { ".m4b", "audio/m4b" }, + { ".m4p", "audio/m4p" }, + { ".m4r", "audio/x-m4r" }, + { ".m4v", "video/x-m4v" }, + { ".mac", "image/x-macpaint" }, + { ".mak", "text/plain" }, + { ".man", "application/x-troff-man" }, + { ".manifest", "application/x-ms-manifest" }, + { ".map", "text/plain" }, + { ".master", "application/xml" }, + { ".mda", "application/msaccess" }, + { ".mdb", "application/x-msaccess" }, + { ".mde", "application/msaccess" }, + { ".mdp", "application/octet-stream" }, + { ".me", "application/x-troff-me" }, + { ".mfp", "application/x-shockwave-flash" }, + { ".mht", "message/rfc822" }, + { ".mhtml", "message/rfc822" }, + { ".mid", "audio/mid" }, + { ".midi", "audio/mid" }, + { ".mix", "application/octet-stream" }, + { ".mk", "text/plain" }, + { ".mmf", "application/x-smaf" }, + { ".mno", "text/xml" }, + { ".mny", "application/x-msmoney" }, + { ".mod", "video/mpeg" }, + { ".mov", "video/quicktime" }, + { ".movie", "video/x-sgi-movie" }, + { ".mp2", "video/mpeg" }, + { ".mp2v", "video/mpeg" }, + { ".mp3", "audio/mpeg" }, + { ".mp4", "video/mp4" }, + { ".mp4v", "video/mp4" }, + { ".mpa", "video/mpeg" }, + { ".mpe", "video/mpeg" }, + { ".mpeg", "video/mpeg" }, + { ".mpf", "application/vnd.ms-mediapackage" }, + { ".mpg", "video/mpeg" }, + { ".mpp", "application/vnd.ms-project" }, + { ".mpv2", "video/mpeg" }, + { ".mqv", "video/quicktime" }, + { ".ms", "application/x-troff-ms" }, + { ".msi", "application/octet-stream" }, + { ".mso", "application/octet-stream" }, + { ".mts", "video/vnd.dlna.mpeg-tts" }, + { ".mtx", "application/xml" }, + { ".mvb", "application/x-msmediaview" }, + { ".mvc", "application/x-miva-compiled" }, + { ".mxp", "application/x-mmxp" }, + { ".nc", "application/x-netcdf" }, + { ".nsc", "video/x-ms-asf" }, + { ".nws", "message/rfc822" }, + { ".ocx", "application/octet-stream" }, + { ".oda", "application/oda" }, + { ".odc", "text/x-ms-odc" }, + { ".odh", "text/plain" }, + { ".odl", "text/plain" }, + { ".odp", "application/vnd.oasis.opendocument.presentation" }, + { ".ods", "application/oleobject" }, + { ".odt", "application/vnd.oasis.opendocument.text" }, + { ".one", "application/onenote" }, + { ".onea", "application/onenote" }, + { ".onepkg", "application/onenote" }, + { ".onetmp", "application/onenote" }, + { ".onetoc", "application/onenote" }, + { ".onetoc2", "application/onenote" }, + { ".orderedtest", "application/xml" }, + { ".osdx", "application/opensearchdescription+xml" }, + { ".p10", "application/pkcs10" }, + { ".p12", "application/x-pkcs12" }, + { ".p7b", "application/x-pkcs7-certificates" }, + { ".p7c", "application/pkcs7-mime" }, + { ".p7m", "application/pkcs7-mime" }, + { ".p7r", "application/x-pkcs7-certreqresp" }, + { ".p7s", "application/pkcs7-signature" }, + { ".pbm", "image/x-portable-bitmap" }, + { ".pcast", "application/x-podcast" }, + { ".pct", "image/pict" }, + { ".pcx", "application/octet-stream" }, + { ".pcz", "application/octet-stream" }, + { ".pdf", "application/pdf" }, + { ".pfb", "application/octet-stream" }, + { ".pfm", "application/octet-stream" }, + { ".pfx", "application/x-pkcs12" }, + { ".pgm", "image/x-portable-graymap" }, + { ".pic", "image/pict" }, + { ".pict", "image/pict" }, + { ".pkgdef", "text/plain" }, + { ".pkgundef", "text/plain" }, + { ".pko", "application/vnd.ms-pki.pko" }, + { ".pls", "audio/scpls" }, + { ".pma", "application/x-perfmon" }, + { ".pmc", "application/x-perfmon" }, + { ".pml", "application/x-perfmon" }, + { ".pmr", "application/x-perfmon" }, + { ".pmw", "application/x-perfmon" }, + { ".png", "image/png" }, + { ".pnm", "image/x-portable-anymap" }, + { ".pnt", "image/x-macpaint" }, + { ".pntg", "image/x-macpaint" }, + { ".pnz", "image/png" }, + { ".pot", "application/vnd.ms-powerpoint" }, + { ".potm", "application/vnd.ms-powerpoint.template.macroEnabled.12" }, + { ".potx", "application/vnd.openxmlformats-officedocument.presentationml.template" }, + { ".ppa", "application/vnd.ms-powerpoint" }, + { ".ppam", "application/vnd.ms-powerpoint.addin.macroEnabled.12" }, + { ".ppm", "image/x-portable-pixmap" }, + { ".pps", "application/vnd.ms-powerpoint" }, + { ".ppsm", "application/vnd.ms-powerpoint.slideshow.macroEnabled.12" }, + { ".ppsx", "application/vnd.openxmlformats-officedocument.presentationml.slideshow" }, + { ".ppt", "application/vnd.ms-powerpoint" }, + { ".pptm", "application/vnd.ms-powerpoint.presentation.macroEnabled.12" }, + { ".pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation" }, + { ".prf", "application/pics-rules" }, + { ".prm", "application/octet-stream" }, + { ".prx", "application/octet-stream" }, + { ".ps", "application/postscript" }, + { ".psc1", "application/PowerShell" }, + { ".psd", "application/octet-stream" }, + { ".psess", "application/xml" }, + { ".psm", "application/octet-stream" }, + { ".psp", "application/octet-stream" }, + { ".pub", "application/x-mspublisher" }, + { ".pwz", "application/vnd.ms-powerpoint" }, + { ".qht", "text/x-html-insertion" }, + { ".qhtm", "text/x-html-insertion" }, + { ".qt", "video/quicktime" }, + { ".qti", "image/x-quicktime" }, + { ".qtif", "image/x-quicktime" }, + { ".qtl", "application/x-quicktimeplayer" }, + { ".qxd", "application/octet-stream" }, + { ".ra", "audio/x-pn-realaudio" }, + { ".ram", "audio/x-pn-realaudio" }, + { ".rar", "application/octet-stream" }, + { ".ras", "image/x-cmu-raster" }, + { ".rat", "application/rat-file" }, + { ".rc", "text/plain" }, + { ".rc2", "text/plain" }, + { ".rct", "text/plain" }, + { ".rdlc", "application/xml" }, + { ".resx", "application/xml" }, + { ".rf", "image/vnd.rn-realflash" }, + { ".rgb", "image/x-rgb" }, + { ".rgs", "text/plain" }, + { ".rm", "application/vnd.rn-realmedia" }, + { ".rmi", "audio/mid" }, + { ".rmp", "application/vnd.rn-rn_music_package" }, + { ".roff", "application/x-troff" }, + { ".rpm", "audio/x-pn-realaudio-plugin" }, + { ".rqy", "text/x-ms-rqy" }, + { ".rtf", "application/rtf" }, + { ".rtx", "text/richtext" }, + { ".ruleset", "application/xml" }, + { ".s", "text/plain" }, + { ".safariextz", "application/x-safari-safariextz" }, + { ".scd", "application/x-msschedule" }, + { ".sct", "text/scriptlet" }, + { ".sd2", "audio/x-sd2" }, + { ".sdp", "application/sdp" }, + { ".sea", "application/octet-stream" }, + { ".searchConnector-ms", "application/windows-search-connector+xml" }, + { ".setpay", "application/set-payment-initiation" }, + { ".setreg", "application/set-registration-initiation" }, + { ".settings", "application/xml" }, + { ".sgimb", "application/x-sgimb" }, + { ".sgml", "text/sgml" }, + { ".sh", "application/x-sh" }, + { ".shar", "application/x-shar" }, + { ".shtml", "text/html" }, + { ".sit", "application/x-stuffit" }, + { ".sitemap", "application/xml" }, + { ".skin", "application/xml" }, + { ".sldm", "application/vnd.ms-powerpoint.slide.macroEnabled.12" }, + { ".sldx", "application/vnd.openxmlformats-officedocument.presentationml.slide" }, + { ".slk", "application/vnd.ms-excel" }, + { ".sln", "text/plain" }, + { ".slupkg-ms", "application/x-ms-license" }, + { ".smd", "audio/x-smd" }, + { ".smi", "application/octet-stream" }, + { ".smx", "audio/x-smd" }, + { ".smz", "audio/x-smd" }, + { ".snd", "audio/basic" }, + { ".snippet", "application/xml" }, + { ".snp", "application/octet-stream" }, + { ".sol", "text/plain" }, + { ".sor", "text/plain" }, + { ".spc", "application/x-pkcs7-certificates" }, + { ".spl", "application/futuresplash" }, + { ".src", "application/x-wais-source" }, + { ".srf", "text/plain" }, + { ".SSISDeploymentManifest", "text/xml" }, + { ".ssm", "application/streamingmedia" }, + { ".sst", "application/vnd.ms-pki.certstore" }, + { ".stl", "application/vnd.ms-pki.stl" }, + { ".sv4cpio", "application/x-sv4cpio" }, + { ".sv4crc", "application/x-sv4crc" }, + { ".svc", "application/xml" }, + { ".swf", "application/x-shockwave-flash" }, + { ".t", "application/x-troff" }, + { ".tar", "application/x-tar" }, + { ".tcl", "application/x-tcl" }, + { ".testrunconfig", "application/xml" }, + { ".testsettings", "application/xml" }, + { ".tex", "application/x-tex" }, + { ".texi", "application/x-texinfo" }, + { ".texinfo", "application/x-texinfo" }, + { ".tgz", "application/x-compressed" }, + { ".thmx", "application/vnd.ms-officetheme" }, + { ".thn", "application/octet-stream" }, + { ".tif", "image/tiff" }, + { ".tiff", "image/tiff" }, + { ".tlh", "text/plain" }, + { ".tli", "text/plain" }, + { ".toc", "application/octet-stream" }, + { ".tr", "application/x-troff" }, + { ".trm", "application/x-msterminal" }, + { ".trx", "application/xml" }, + { ".ts", "video/vnd.dlna.mpeg-tts" }, + { ".tsv", "text/tab-separated-values" }, + { ".ttf", "application/octet-stream" }, + { ".tts", "video/vnd.dlna.mpeg-tts" }, + { ".txt", "text/plain" }, + { ".u32", "application/octet-stream" }, + { ".uls", "text/iuls" }, + { ".user", "text/plain" }, + { ".ustar", "application/x-ustar" }, + { ".vb", "text/plain" }, + { ".vbdproj", "text/plain" }, + { ".vbk", "video/mpeg" }, + { ".vbproj", "text/plain" }, + { ".vbs", "text/vbscript" }, + { ".vcf", "text/x-vcard" }, + { ".vcproj", "Application/xml" }, + { ".vcs", "text/plain" }, + { ".vcxproj", "Application/xml" }, + { ".vddproj", "text/plain" }, + { ".vdp", "text/plain" }, + { ".vdproj", "text/plain" }, + { ".vdx", "application/vnd.ms-visio.viewer" }, + { ".vml", "text/xml" }, + { ".vscontent", "application/xml" }, + { ".vsct", "text/xml" }, + { ".vsd", "application/vnd.visio" }, + { ".vsi", "application/ms-vsi" }, + { ".vsix", "application/vsix" }, + { ".vsixlangpack", "text/xml" }, + { ".vsixmanifest", "text/xml" }, + { ".vsmdi", "application/xml" }, + { ".vspscc", "text/plain" }, + { ".vss", "application/vnd.visio" }, + { ".vsscc", "text/plain" }, + { ".vssettings", "text/xml" }, + { ".vssscc", "text/plain" }, + { ".vst", "application/vnd.visio" }, + { ".vstemplate", "text/xml" }, + { ".vsto", "application/x-ms-vsto" }, + { ".vsw", "application/vnd.visio" }, + { ".vsx", "application/vnd.visio" }, + { ".vtx", "application/vnd.visio" }, + { ".wav", "audio/wav" }, + { ".wave", "audio/wav" }, + { ".wax", "audio/x-ms-wax" }, + { ".wbk", "application/msword" }, + { ".wbmp", "image/vnd.wap.wbmp" }, + { ".wcm", "application/vnd.ms-works" }, + { ".wdb", "application/vnd.ms-works" }, + { ".wdp", "image/vnd.ms-photo" }, + { ".webarchive", "application/x-safari-webarchive" }, + { ".webtest", "application/xml" }, + { ".wiq", "application/xml" }, + { ".wiz", "application/msword" }, + { ".wks", "application/vnd.ms-works" }, + { ".WLMP", "application/wlmoviemaker" }, + { ".wlpginstall", "application/x-wlpg-detect" }, + { ".wlpginstall3", "application/x-wlpg3-detect" }, + { ".wm", "video/x-ms-wm" }, + { ".wma", "audio/x-ms-wma" }, + { ".wmd", "application/x-ms-wmd" }, + { ".wmf", "application/x-msmetafile" }, + { ".wml", "text/vnd.wap.wml" }, + { ".wmlc", "application/vnd.wap.wmlc" }, + { ".wmls", "text/vnd.wap.wmlscript" }, + { ".wmlsc", "application/vnd.wap.wmlscriptc" }, + { ".wmp", "video/x-ms-wmp" }, + { ".wmv", "video/x-ms-wmv" }, + { ".wmx", "video/x-ms-wmx" }, + { ".wmz", "application/x-ms-wmz" }, + { ".wpl", "application/vnd.ms-wpl" }, + { ".wps", "application/vnd.ms-works" }, + { ".wri", "application/x-mswrite" }, + { ".wrl", "x-world/x-vrml" }, + { ".wrz", "x-world/x-vrml" }, + { ".wsc", "text/scriptlet" }, + { ".wsdl", "text/xml" }, + { ".wvx", "video/x-ms-wvx" }, + { ".x", "application/directx" }, + { ".xaf", "x-world/x-vrml" }, + { ".xaml", "application/xaml+xml" }, + { ".xap", "application/x-silverlight-app" }, + { ".xbap", "application/x-ms-xbap" }, + { ".xbm", "image/x-xbitmap" }, + { ".xdr", "text/plain" }, + { ".xht", "application/xhtml+xml" }, + { ".xhtml", "application/xhtml+xml" }, + { ".xla", "application/vnd.ms-excel" }, + { ".xlam", "application/vnd.ms-excel.addin.macroEnabled.12" }, + { ".xlc", "application/vnd.ms-excel" }, + { ".xld", "application/vnd.ms-excel" }, + { ".xlk", "application/vnd.ms-excel" }, + { ".xll", "application/vnd.ms-excel" }, + { ".xlm", "application/vnd.ms-excel" }, + { ".xls", "application/vnd.ms-excel" }, + { ".xlsb", "application/vnd.ms-excel.sheet.binary.macroEnabled.12" }, + { ".xlsm", "application/vnd.ms-excel.sheet.macroEnabled.12" }, + { ".xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }, + { ".xlt", "application/vnd.ms-excel" }, + { ".xltm", "application/vnd.ms-excel.template.macroEnabled.12" }, + { ".xltx", "application/vnd.openxmlformats-officedocument.spreadsheetml.template" }, + { ".xlw", "application/vnd.ms-excel" }, + { ".xml", "text/xml" }, + { ".xmta", "application/xml" }, + { ".xof", "x-world/x-vrml" }, + { ".XOML", "text/plain" }, + { ".xpm", "image/x-xpixmap" }, + { ".xps", "application/vnd.ms-xpsdocument" }, + { ".xrm-ms", "text/xml" }, + { ".xsc", "application/xml" }, + { ".xsd", "text/xml" }, + { ".xsf", "text/xml" }, + { ".xsl", "text/xml" }, + { ".xslt", "text/xml" }, + { ".xsn", "application/octet-stream" }, + { ".xss", "application/xml" }, + { ".xtp", "application/octet-stream" }, + { ".xwd", "image/x-xwindowdump" }, + { ".z", "application/x-compress" }, + { ".zip", "application/x-zip-compressed" }, + + #endregion + }; + + public static string GetMimeType(string extension) + { + if (extension == null) + { + throw new ArgumentNullException("extension"); + } + + if (!extension.StartsWith(".")) + { + extension = "." + extension; + } + + string mime; + + return _mappings.TryGetValue(extension, out mime) ? mime : "application/octet-stream"; + } + } +} \ No newline at end of file diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Api/Helpers/Singleton.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Helpers/Singleton.cs new file mode 100644 index 00000000..99f87b32 --- /dev/null +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Helpers/Singleton.cs @@ -0,0 +1,38 @@ +using System; +using System.Reflection; + +namespace O2NextGen.MediaBasket.Api.Helpers +{ + public class Singleton where T : class + { + private static T _instance; + + protected Singleton() + { + } + + private static T CreateInstance() + { + var cInfo = typeof(T).GetConstructor( + BindingFlags.Instance | BindingFlags.NonPublic, + null, + new Type[0], + new ParameterModifier[0]); + + return (T)cInfo.Invoke(null); + } + + public static T Instance + { + get + { + if (_instance == null) + { + _instance = CreateInstance(); + } + + return _instance; + } + } + } +} \ No newline at end of file diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Api/Helpers/TypeTable.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Helpers/TypeTable.cs new file mode 100644 index 00000000..00708ce7 --- /dev/null +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Helpers/TypeTable.cs @@ -0,0 +1,10 @@ +namespace O2NextGen.MediaBasket.Api.Helpers +{ + public enum TypeTable + { + Videos, + Certificates, + Users, + Events + } +} \ No newline at end of file diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Api/IoC/ServiceCollectionExtensions.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Api/IoC/ServiceCollectionExtensions.cs index 3d216420..d08feb8e 100644 --- a/src/Services/media-basket/O2NextGen.MediaBasket.Api/IoC/ServiceCollectionExtensions.cs +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Api/IoC/ServiceCollectionExtensions.cs @@ -4,6 +4,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using O2NextGen.MediaBasket.Api.Filters; +using O2NextGen.MediaBasket.Api.Services; using O2NextGen.MediaBasket.Business.Services; using O2NextGen.MediaBasket.Data; using O2NextGen.MediaBasket.Impl.Services; @@ -49,7 +50,8 @@ public static IServiceCollection AddConfigEf(this IServiceCollection services, I public static IServiceCollection AddBusiness(this IServiceCollection services) { - // services.AddSingleton(); + //services.AddSingleton(); + services.AddSingleton(); // Include DataLayer services.AddScoped(); //more business services... diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Api/Mappings/MediaMappings.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Mappings/MediaMappings.cs index 065b2dbd..bb79d186 100644 --- a/src/Services/media-basket/O2NextGen.MediaBasket.Api/Mappings/MediaMappings.cs +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Mappings/MediaMappings.cs @@ -19,6 +19,17 @@ public static MediaViewModel ToViewModel(this Media model) //Bindings viewModel.Id = model.Id; viewModel.Name = model.Name; + viewModel.OriginalName = model.OriginalName; + viewModel.PublicId = model.PublicId; + viewModel.AccountId = model.AccountId; + viewModel.ContentType = model.ContentType; + viewModel.DateAdded = model.DateAdded; + viewModel.Description = model.Description; + viewModel.Width = model.Width; + viewModel.Height = model.Height; + viewModel.ExtType = model.ExtType; + viewModel.MediaType = model.MediaType; + viewModel.Url = model.Url; return viewModel; } @@ -33,6 +44,17 @@ public static Media ToModel(this MediaViewModel viewModel) //Bindings model.Id = viewModel.Id; model.Name = viewModel.Name; + model.OriginalName = viewModel.OriginalName; + model.PublicId = viewModel.PublicId; + model.AccountId = viewModel.AccountId; + model.ContentType = viewModel.ContentType; + model.DateAdded = viewModel.DateAdded; + model.Description = viewModel.Description; + model.Width = viewModel.Width ?? 0; + model.Height = viewModel.Height ?? 0; + model.ExtType = viewModel.ExtType; + model.MediaType = viewModel.MediaType; + model.Url = viewModel.Url; return model; } diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Api/O2NextGen.MediaBasket.Api.csproj b/src/Services/media-basket/O2NextGen.MediaBasket.Api/O2NextGen.MediaBasket.Api.csproj index 231da833..e1ee21bc 100644 --- a/src/Services/media-basket/O2NextGen.MediaBasket.Api/O2NextGen.MediaBasket.Api.csproj +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Api/O2NextGen.MediaBasket.Api.csproj @@ -33,6 +33,7 @@ + diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Api/Services/AzureStorageService.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Services/AzureStorageService.cs new file mode 100644 index 00000000..ccd378af --- /dev/null +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Services/AzureStorageService.cs @@ -0,0 +1,18 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using O2NextGen.MediaBasket.Business.Models; +using O2NextGen.MediaBasket.Business.Services; + +namespace O2NextGen.MediaBasket.Api.Services +{ + public class AzureStorageService : ICloudStorageManager + { + + public Task UploadFileAsync(Media media, IFormFile formFile, CancellationToken ct) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Api/Services/CloudStorage.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Services/CloudStorage.cs new file mode 100644 index 00000000..9ede1a4d --- /dev/null +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Services/CloudStorage.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using System.Linq; +using O2NextGen.MediaBasket.Api.Helpers; + +namespace O2NextGen.MediaBasket.Api.Services +{ + public abstract class CloudStorage: Singleton + { + public List AccountCloudStorages { get; set; } = new List(); + + protected CloudStorage() + { + Clear(); + } + + public AccountCloudStorage GetAccountCloudStorage(TypeTable typeTable) + { + return AccountCloudStorages.Single(x => x.TypeTable == typeTable); + } + + public void Clear() + { + AccountCloudStorages.Clear(); + } + } +} \ No newline at end of file diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Api/Services/CloudinaryStorageService.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Services/CloudinaryStorageService.cs new file mode 100644 index 00000000..e0d2b5b4 --- /dev/null +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Services/CloudinaryStorageService.cs @@ -0,0 +1,77 @@ +using System; +using System.IO; +using System.Threading; +using System.Threading.Tasks; +using CloudinaryDotNet; +using CloudinaryDotNet.Actions; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using O2NextGen.MediaBasket.Api.Helpers; +using O2NextGen.MediaBasket.Business.Models; +using O2NextGen.MediaBasket.Business.Services; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.Formats.Jpeg; +using SixLabors.ImageSharp.Processing; + +namespace O2NextGen.MediaBasket.Api.Services +{ + public class CloudinaryStorageService : ICloudStorageManager + { + private readonly IOptions _cloudinaryConfig; + private readonly ILogger _logger; + private readonly Cloudinary _cloudinary; + + public CloudinaryStorageService(IOptions cloudinaryConfig, ILogger logger) + { + _cloudinaryConfig = cloudinaryConfig ?? throw new ArgumentException(nameof(cloudinaryConfig)); + _logger = logger; + Account acc = new Account( + _cloudinaryConfig.Value.CloudName, + _cloudinaryConfig.Value.ApiKey, + _cloudinaryConfig.Value.ApiSecret + ); + _cloudinary = new Cloudinary(acc); + } + + public async Task UploadFileAsync(Media media, IFormFile formFile, CancellationToken ct) + { + if (formFile == null) throw new ArgumentException(nameof(formFile)); + + media.OriginalName = formFile.FileName; + + var filename = media.AccountId + "-" + DateTime.UtcNow.ToString("hh/mm/ss/dd/MM/yyyy").Replace('/', '-') + + media.OriginalName.GetFileExtension(); + + var contentType = MimeTypes.GetMimeType(filename.GetFileExtension().ToLower()); + + if (formFile.Length > 0) + { + var filePath = Path.GetTempFileName(); + _logger.LogInformation($"string filePath={filePath}"); + using (var stream = File.Create(filename)) + { + using (Image image = Image.Load(stream)) + { + await formFile.CopyToAsync(stream, ct); + var uploadParams = new ImageUploadParams() + { + Folder = "/Media-Basket/Dev", + File = new FileDescription(media.Name, stream), + }; + var uploadResult = _cloudinary.Upload(uploadParams); + media.PublicId = uploadResult.PublicId; + media.Width = image.Width; + media.Height = image.Height; + media.ExtType = filename.GetFileExtension(); + media.Url = uploadResult.Uri.ToString(); + media.MediaType = "image"; + media.ContentType = contentType; + } + } + } + + return await Task.FromResult(media); + } + } +} \ No newline at end of file diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Api/Startup.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Startup.cs index 04216ed2..5ae47643 100644 --- a/src/Services/media-basket/O2NextGen.MediaBasket.Api/Startup.cs +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Startup.cs @@ -8,7 +8,9 @@ using Microsoft.Extensions.DependencyInjection; using O2NextGen.MediaBasket.Api.Helpers; using O2NextGen.MediaBasket.Api.IoC; +using O2NextGen.MediaBasket.Api.Services; using O2NextGen.MediaBasket.Api.Setup; +using Serilog; using Swashbuckle.AspNetCore.Swagger; namespace O2NextGen.MediaBasket.Api @@ -23,8 +25,33 @@ public Startup(IConfiguration appConfiguration, IHostingEnvironment env) this.HostingEnvironment = env; this.AppConfiguration = appConfiguration; } + + + //private void ConfigureCloudStorageProfile() + //{ + + // CloudStorage.Instance.AccountCloudStorages.Add( + // new AccountCloudStorage() + // { + // StorageType = StorageType.Cloudinary, + // AccountName = AppConfiguration.GetSection("CloudStorage:Videos:AccountName").Value, + // Container = AppConfiguration.GetSection("CloudStorage:Videos:Container").Value, + // AccountKey = AppConfiguration.GetSection("CloudStorage:Videos:AccountKey").Value, + // TypeTable = TypeTable.Videos + // }); + + // Log.Information( + // $"CloudStorage:Events:AccountName={AppConfiguration.GetSection("CloudStorage:Videos:AccountName").Value}"); + // Log.Information( + // $"CloudStorage:Events:Container={AppConfiguration.GetSection("CloudStorage:Videos:Container").Value}"); + // Log.Information( + // $"CloudStorage:Events:AccountKey={AppConfiguration.GetSection("CloudStorage:Videos:AccountKey").Value}"); + //} + public void ConfigureServices(IServiceCollection services) { + services.Configure(AppConfiguration.GetSection("CloudinarySettings")); + //ConfigureCloudStorageProfile(); services.AddRequiredMvcComponents(); services.AddBusiness(); services.AddSwaggerGen(options => diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Business/Models/Media.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Business/Models/Media.cs index e056d832..e7295c2b 100644 --- a/src/Services/media-basket/O2NextGen.MediaBasket.Business/Models/Media.cs +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Business/Models/Media.cs @@ -1,8 +1,21 @@ +using System; + namespace O2NextGen.MediaBasket.Business.Models { public class Media { public long Id { get; set; } public string Name { get; set; } + public string OriginalName { get; set; } + public string PublicId { get; set; } + public string AccountId { get; set; } + public string ContentType { get; set; } + public DateTime? DateAdded { get; set; } + public string Description { get; set; } + public int Width { get; set; } + public int Height { get; set; } + public string ExtType { get; set; } + public string Url { get; set; } + public string MediaType { get; set; } } } \ No newline at end of file diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Business/O2NextGen.MediaBasket.Business.csproj b/src/Services/media-basket/O2NextGen.MediaBasket.Business/O2NextGen.MediaBasket.Business.csproj index a134b7dd..79d2defe 100644 --- a/src/Services/media-basket/O2NextGen.MediaBasket.Business/O2NextGen.MediaBasket.Business.csproj +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Business/O2NextGen.MediaBasket.Business.csproj @@ -4,4 +4,8 @@ netcoreapp2.2 + + + + \ No newline at end of file diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Business/Services/ICloudStorageManager.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Business/Services/ICloudStorageManager.cs new file mode 100644 index 00000000..57134140 --- /dev/null +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Business/Services/ICloudStorageManager.cs @@ -0,0 +1,13 @@ +using System.IO; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using O2NextGen.MediaBasket.Business.Models; + +namespace O2NextGen.MediaBasket.Business.Services +{ + public interface ICloudStorageManager + { + Task UploadFileAsync(Media media, IFormFile formFile, CancellationToken ct); + } +} \ No newline at end of file diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Business/Services/IMediaService.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Business/Services/IMediaService.cs index 10bf4b1c..b1a1cb27 100644 --- a/src/Services/media-basket/O2NextGen.MediaBasket.Business/Services/IMediaService.cs +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Business/Services/IMediaService.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; +using System.IO; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; using O2NextGen.MediaBasket.Business.Models; namespace O2NextGen.MediaBasket.Business.Services @@ -13,7 +15,7 @@ public interface IMediaService Task UpdateAsync(Media media, CancellationToken ct); - Task AddAsync(Media media, CancellationToken ct); + Task AddAsync(Media media, IFormFile formFile, CancellationToken ct); Task RemoveAsync(long id, CancellationToken ct); } diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Data/Entities/MediaEntity.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Data/Entities/MediaEntity.cs index 0b58100c..6a0df0ba 100644 --- a/src/Services/media-basket/O2NextGen.MediaBasket.Data/Entities/MediaEntity.cs +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Data/Entities/MediaEntity.cs @@ -4,5 +4,6 @@ public class MediaEntity { public long Id { get; set; } public string Name { get; set; } + public string OriginalName { get; set; } } } \ No newline at end of file diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Impl/Mappings/MediaMappings.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Impl/Mappings/MediaMappings.cs index 171b9c93..c0d3b313 100644 --- a/src/Services/media-basket/O2NextGen.MediaBasket.Impl/Mappings/MediaMappings.cs +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Impl/Mappings/MediaMappings.cs @@ -8,12 +8,22 @@ internal static class MediaMappings { public static Media ToService(this MediaEntity entity) { - return entity != null ? new Media() {Id = entity.Id, Name = entity.Name} : null; + return entity != null ? new Media() + { + Id = entity.Id, + Name = entity.Name, + OriginalName = entity.OriginalName + } : null; } public static MediaEntity ToEntity(this Media model) { - return model != null ? new MediaEntity() {Id = model.Id, Name = model.Name} : null; + return model != null ? new MediaEntity() + { + Id = model.Id, + Name = model.Name, + OriginalName = model.OriginalName + } : null; } public static IReadOnlyCollection diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Impl/O2NextGen.MediaBasket.Impl.csproj b/src/Services/media-basket/O2NextGen.MediaBasket.Impl/O2NextGen.MediaBasket.Impl.csproj index 4e5e4226..d8112c49 100644 --- a/src/Services/media-basket/O2NextGen.MediaBasket.Impl/O2NextGen.MediaBasket.Impl.csproj +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Impl/O2NextGen.MediaBasket.Impl.csproj @@ -8,5 +8,8 @@ + + + \ No newline at end of file diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Impl/Services/InMemoryMediaService.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Impl/Services/InMemoryMediaService.cs index a703203f..b85552f4 100644 --- a/src/Services/media-basket/O2NextGen.MediaBasket.Impl/Services/InMemoryMediaService.cs +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Impl/Services/InMemoryMediaService.cs @@ -1,7 +1,9 @@ using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; using O2NextGen.MediaBasket.Business.Models; using O2NextGen.MediaBasket.Business.Services; @@ -10,6 +12,7 @@ namespace O2NextGen.MediaBasket.Impl.Services public class InMemoryMediaService : IMediaService { #region Fields + private readonly ICloudStorageManager _cloudStorage; private static readonly List Certificates = new List() { @@ -24,8 +27,9 @@ public class InMemoryMediaService : IMediaService #region Ctors - public InMemoryMediaService() + public InMemoryMediaService(ICloudStorageManager cloudStorage) { + _cloudStorage = cloudStorage; _currentId = Certificates.Count(); } #endregion @@ -55,14 +59,16 @@ public async Task UpdateAsync(Media media, CancellationToken ct) return await Task.FromResult(toUpdate); } - public async Task AddAsync(Media media, CancellationToken ct) + public async Task AddAsync(Media media, IFormFile formFile, CancellationToken ct) { await Task.Delay(3000, ct); media.Id = ++_currentId; + await _cloudStorage.UploadFileAsync(media, formFile, ct); Certificates.Add(media); return await Task.FromResult(media); } + public Task RemoveAsync(long id, CancellationToken ct) { throw new System.NotImplementedException(); diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Impl/Services/MediaService.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Impl/Services/MediaService.cs index 8a5bfb49..82e102b2 100644 --- a/src/Services/media-basket/O2NextGen.MediaBasket.Impl/Services/MediaService.cs +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Impl/Services/MediaService.cs @@ -1,7 +1,9 @@ using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using O2NextGen.MediaBasket.Business.Models; using O2NextGen.MediaBasket.Business.Services; @@ -15,15 +17,17 @@ public class MediaService : IMediaService #region Fields private readonly MadiaManagementDbContext _context; + private readonly ICloudStorageManager _cloudStorage; #endregion #region Ctors - public MediaService(MadiaManagementDbContext context) + public MediaService(MadiaManagementDbContext context,ICloudStorageManager cloudStorage) { _context = context; + _cloudStorage = cloudStorage; } #endregion @@ -47,8 +51,9 @@ public async Task UpdateAsync(Media media, CancellationToken ct) return updatedCertificateEntity.Entity.ToService(); } - public async Task AddAsync(Media media, CancellationToken ct) + public async Task AddAsync(Media media, IFormFile formFile, CancellationToken ct) { + await _cloudStorage.UploadFileAsync(media, formFile, ct); var addedCertificateEntity = await _context.Certificates.AddAsync(media.ToEntity(), ct); await _context.SaveChangesAsync(ct); return addedCertificateEntity.Entity.ToService(); diff --git a/src/Services/smalltalk/O2NextGen.SmallTalk.Api/Helpers/ServiceCollectionExtensions.cs b/src/Services/smalltalk/O2NextGen.SmallTalk.Api/Helpers/ServiceCollectionExtensions.cs index 553a7419..a6bce19c 100644 --- a/src/Services/smalltalk/O2NextGen.SmallTalk.Api/Helpers/ServiceCollectionExtensions.cs +++ b/src/Services/smalltalk/O2NextGen.SmallTalk.Api/Helpers/ServiceCollectionExtensions.cs @@ -1,7 +1,6 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using O2NextGen.SmallTalk.Api.Services; using O2NextGen.SmallTalk.Business.Services; using O2NextGen.SmallTalk.Impl.Services; using System; diff --git a/src/docker-compose.override.yml b/src/docker-compose.override.yml index 482f5a7f..546aeeb5 100644 --- a/src/docker-compose.override.yml +++ b/src/docker-compose.override.yml @@ -115,6 +115,18 @@ services: # - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro # - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro + o2nextgen.mediabasket.api: + environment: + - ASPNETCORE_ENVIRONMENT=Development + - ConnectionString=Server=sql.data;Initial Catalog=O2NextGen.MediaBasketDb;Persist Security Info=False;User ID=sa;Password=your@Password;Connection Timeout=30; + #- ASPNETCORE_URLS=https://+:443;http://+:80 + ports: + - "5005:80" + depends_on: + - sql.data + networks: + - backend + smalltalk.app: environment: - ASPNETCORE_ENVIRONMENT=Development diff --git a/src/docker-compose.yml b/src/docker-compose.yml index 254c6a4f..c09050ca 100644 --- a/src/docker-compose.yml +++ b/src/docker-compose.yml @@ -39,6 +39,12 @@ services: context: . dockerfile: Services/e-sender/O2NextGen.ESender.Api/Dockerfile + o2nextgen.mediabasket.api: + image: ${DOCKER_REGISTRY-}o2ng-media-basket-api + build: + context: . + dockerfile: Services/media-basket/O2NextGen.MediaBasket.Api/Dockerfile + smalltalk.app: image: ${DOCKER_REGISTRY-}smalltalk-app build: From a2a958d731b55b2d683419fbd7582534b46a78b6 Mon Sep 17 00:00:00 2001 From: Denis Prokhorchik Date: Sun, 12 Jun 2022 18:22:03 +0300 Subject: [PATCH 2/2] feat(issue-385): update swgger 1.2.0 to 4.0.0 feat(issue-385): media-basket api loaded files feat(issue-385): update appserttings.json --- ...O2NextGen.CertificateManagement.Api.csproj | 2 +- .../O2NextGen.ESender.Api.csproj | 2 +- .../O2NextGen.FeedBackX.Api.csproj | 2 +- .../Mappings/MediaMappings.cs | 2 +- .../O2NextGen.MediaBasket.Api.csproj | 2 +- .../Services/CloudinaryStorageService.cs | 38 +++--- .../appsettings.json | 5 + .../Models/Media.cs | 2 +- .../Entities/MediaEntity.cs | 12 ++ ...612161450_InitFieldsInDatabase.Designer.cs | 64 ++++++++++ .../20220612161450_InitFieldsInDatabase.cs | 115 ++++++++++++++++++ .../MadiaManagementDbContextModelSnapshot.cs | 23 ++++ .../Mappings/MediaMappings.cs | 49 ++++++-- .../Services/MediaService.cs | 1 + .../O2NextGen.OnTracker.Api.csproj | 2 +- .../O2NextGen.SLink.Api.csproj | 2 +- .../O2NextGen.SmallTalk.Api.csproj | 2 +- src/docker-compose.override.yml | 3 + 18 files changed, 290 insertions(+), 38 deletions(-) create mode 100644 src/Services/media-basket/O2NextGen.MediaBasket.Data/Migrations/20220612161450_InitFieldsInDatabase.Designer.cs create mode 100644 src/Services/media-basket/O2NextGen.MediaBasket.Data/Migrations/20220612161450_InitFieldsInDatabase.cs diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Api/O2NextGen.CertificateManagement.Api.csproj b/src/Services/c-gen/O2NextGen.CertificateManagement.Api/O2NextGen.CertificateManagement.Api.csproj index c7bb9e21..ba989a7c 100644 --- a/src/Services/c-gen/O2NextGen.CertificateManagement.Api/O2NextGen.CertificateManagement.Api.csproj +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Api/O2NextGen.CertificateManagement.Api.csproj @@ -27,7 +27,7 @@ - + diff --git a/src/Services/e-sender/O2NextGen.ESender.Api/O2NextGen.ESender.Api.csproj b/src/Services/e-sender/O2NextGen.ESender.Api/O2NextGen.ESender.Api.csproj index bb73937a..8e9ba165 100644 --- a/src/Services/e-sender/O2NextGen.ESender.Api/O2NextGen.ESender.Api.csproj +++ b/src/Services/e-sender/O2NextGen.ESender.Api/O2NextGen.ESender.Api.csproj @@ -29,7 +29,7 @@ - + diff --git a/src/Services/feedback-x/O2NextGen.FeedBackX.Api/O2NextGen.FeedBackX.Api.csproj b/src/Services/feedback-x/O2NextGen.FeedBackX.Api/O2NextGen.FeedBackX.Api.csproj index 1f35a2e8..50bdeb58 100644 --- a/src/Services/feedback-x/O2NextGen.FeedBackX.Api/O2NextGen.FeedBackX.Api.csproj +++ b/src/Services/feedback-x/O2NextGen.FeedBackX.Api/O2NextGen.FeedBackX.Api.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Api/Mappings/MediaMappings.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Mappings/MediaMappings.cs index bb79d186..4ac9a587 100644 --- a/src/Services/media-basket/O2NextGen.MediaBasket.Api/Mappings/MediaMappings.cs +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Mappings/MediaMappings.cs @@ -48,7 +48,7 @@ public static Media ToModel(this MediaViewModel viewModel) model.PublicId = viewModel.PublicId; model.AccountId = viewModel.AccountId; model.ContentType = viewModel.ContentType; - model.DateAdded = viewModel.DateAdded; + model.DateAdded = viewModel.DateAdded ?? DateTime.Now; model.Description = viewModel.Description; model.Width = viewModel.Width ?? 0; model.Height = viewModel.Height ?? 0; diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Api/O2NextGen.MediaBasket.Api.csproj b/src/Services/media-basket/O2NextGen.MediaBasket.Api/O2NextGen.MediaBasket.Api.csproj index e1ee21bc..2ecd8528 100644 --- a/src/Services/media-basket/O2NextGen.MediaBasket.Api/O2NextGen.MediaBasket.Api.csproj +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Api/O2NextGen.MediaBasket.Api.csproj @@ -32,7 +32,7 @@ - + diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Api/Services/CloudinaryStorageService.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Services/CloudinaryStorageService.cs index e0d2b5b4..a98b8487 100644 --- a/src/Services/media-basket/O2NextGen.MediaBasket.Api/Services/CloudinaryStorageService.cs +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Api/Services/CloudinaryStorageService.cs @@ -11,8 +11,7 @@ using O2NextGen.MediaBasket.Business.Models; using O2NextGen.MediaBasket.Business.Services; using SixLabors.ImageSharp; -using SixLabors.ImageSharp.Formats.Jpeg; -using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Formats; namespace O2NextGen.MediaBasket.Api.Services { @@ -49,24 +48,29 @@ public async Task UploadFileAsync(Media media, IFormFile formFile, Cancel { var filePath = Path.GetTempFileName(); _logger.LogInformation($"string filePath={filePath}"); - using (var stream = File.Create(filename)) + using (var stream = formFile.OpenReadStream()) { - using (Image image = Image.Load(stream)) + using (Image image = Image.Load(stream, out IImageFormat format)) { - await formFile.CopyToAsync(stream, ct); - var uploadParams = new ImageUploadParams() + using (var stream2 = formFile.OpenReadStream()) { - Folder = "/Media-Basket/Dev", - File = new FileDescription(media.Name, stream), - }; - var uploadResult = _cloudinary.Upload(uploadParams); - media.PublicId = uploadResult.PublicId; - media.Width = image.Width; - media.Height = image.Height; - media.ExtType = filename.GetFileExtension(); - media.Url = uploadResult.Uri.ToString(); - media.MediaType = "image"; - media.ContentType = contentType; + // await formFile.CopyToAsync(stream, ct); + var uploadParams = new ImageUploadParams() + { + Folder = "Media-Basket/Dev", + File = new FileDescription(media.OriginalName, stream2), + }; + + var uploadResult = _cloudinary.Upload(uploadParams); + media.Name = filename; + media.PublicId = uploadResult.PublicId; + media.Width = image.Width; + media.Height = image.Height; + media.ExtType = filename.GetFileExtension(); + media.Url = uploadResult.Uri.ToString(); + media.MediaType = "image"; + media.ContentType = contentType; + } } } } diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Api/appsettings.json b/src/Services/media-basket/O2NextGen.MediaBasket.Api/appsettings.json index 951b4c78..12873ab5 100644 --- a/src/Services/media-basket/O2NextGen.MediaBasket.Api/appsettings.json +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Api/appsettings.json @@ -21,6 +21,11 @@ } ] }, + "CloudinarySettings": { + "CloudName": "cloudname", + "ApiKey": "apikey", + "ApiSecret": "apisecret" + }, "Logging": { "IncludeScopes": false, "LogLevel": { diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Business/Models/Media.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Business/Models/Media.cs index e7295c2b..00a43ded 100644 --- a/src/Services/media-basket/O2NextGen.MediaBasket.Business/Models/Media.cs +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Business/Models/Media.cs @@ -10,7 +10,7 @@ public class Media public string PublicId { get; set; } public string AccountId { get; set; } public string ContentType { get; set; } - public DateTime? DateAdded { get; set; } + public DateTime DateAdded { get; set; } public string Description { get; set; } public int Width { get; set; } public int Height { get; set; } diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Data/Entities/MediaEntity.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Data/Entities/MediaEntity.cs index 6a0df0ba..35f3ef0a 100644 --- a/src/Services/media-basket/O2NextGen.MediaBasket.Data/Entities/MediaEntity.cs +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Data/Entities/MediaEntity.cs @@ -1,3 +1,5 @@ +using System; + namespace O2NextGen.MediaBasket.Data.Entities { public class MediaEntity @@ -5,5 +7,15 @@ public class MediaEntity public long Id { get; set; } public string Name { get; set; } public string OriginalName { get; set; } + public string PublicId { get; set; } + public string AccountId { get; set; } + public string ContentType { get; set; } + public DateTime? DateAdded { get; set; } + public string Description { get; set; } + public int Width { get; set; } + public int Height { get; set; } + public string ExtType { get; set; } + public string MediaType { get; set; } + public string Url { get; set; } } } \ No newline at end of file diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Data/Migrations/20220612161450_InitFieldsInDatabase.Designer.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Data/Migrations/20220612161450_InitFieldsInDatabase.Designer.cs new file mode 100644 index 00000000..3a1fc65e --- /dev/null +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Data/Migrations/20220612161450_InitFieldsInDatabase.Designer.cs @@ -0,0 +1,64 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using O2NextGen.MediaBasket.Data; + +namespace O2NextGen.MediaBasket.Data.Migrations +{ + [DbContext(typeof(MadiaManagementDbContext))] + [Migration("20220612161450_InitFieldsInDatabase")] + partial class InitFieldsInDatabase + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.2.0-rtm-35687") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("Relational:Sequence:.media_hilo", "'media_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("O2NextGen.MediaBasket.Data.Entities.MediaEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasAnnotation("SqlServer:HiLoSequenceName", "media_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("AccountId"); + + b.Property("ContentType"); + + b.Property("DateAdded"); + + b.Property("Description"); + + b.Property("ExtType"); + + b.Property("Height"); + + b.Property("MediaType"); + + b.Property("Name"); + + b.Property("OriginalName"); + + b.Property("PublicId"); + + b.Property("Url"); + + b.Property("Width"); + + b.HasKey("Id"); + + b.ToTable("Media"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Data/Migrations/20220612161450_InitFieldsInDatabase.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Data/Migrations/20220612161450_InitFieldsInDatabase.cs new file mode 100644 index 00000000..8260a56c --- /dev/null +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Data/Migrations/20220612161450_InitFieldsInDatabase.cs @@ -0,0 +1,115 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace O2NextGen.MediaBasket.Data.Migrations +{ + public partial class InitFieldsInDatabase : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "AccountId", + table: "Media", + nullable: true); + + migrationBuilder.AddColumn( + name: "ContentType", + table: "Media", + nullable: true); + + migrationBuilder.AddColumn( + name: "DateAdded", + table: "Media", + nullable: true); + + migrationBuilder.AddColumn( + name: "Description", + table: "Media", + nullable: true); + + migrationBuilder.AddColumn( + name: "ExtType", + table: "Media", + nullable: true); + + migrationBuilder.AddColumn( + name: "Height", + table: "Media", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "MediaType", + table: "Media", + nullable: true); + + migrationBuilder.AddColumn( + name: "OriginalName", + table: "Media", + nullable: true); + + migrationBuilder.AddColumn( + name: "PublicId", + table: "Media", + nullable: true); + + migrationBuilder.AddColumn( + name: "Url", + table: "Media", + nullable: true); + + migrationBuilder.AddColumn( + name: "Width", + table: "Media", + nullable: false, + defaultValue: 0); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "AccountId", + table: "Media"); + + migrationBuilder.DropColumn( + name: "ContentType", + table: "Media"); + + migrationBuilder.DropColumn( + name: "DateAdded", + table: "Media"); + + migrationBuilder.DropColumn( + name: "Description", + table: "Media"); + + migrationBuilder.DropColumn( + name: "ExtType", + table: "Media"); + + migrationBuilder.DropColumn( + name: "Height", + table: "Media"); + + migrationBuilder.DropColumn( + name: "MediaType", + table: "Media"); + + migrationBuilder.DropColumn( + name: "OriginalName", + table: "Media"); + + migrationBuilder.DropColumn( + name: "PublicId", + table: "Media"); + + migrationBuilder.DropColumn( + name: "Url", + table: "Media"); + + migrationBuilder.DropColumn( + name: "Width", + table: "Media"); + } + } +} diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Data/Migrations/MadiaManagementDbContextModelSnapshot.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Data/Migrations/MadiaManagementDbContextModelSnapshot.cs index 8f6f1ef3..a0b9cb71 100644 --- a/src/Services/media-basket/O2NextGen.MediaBasket.Data/Migrations/MadiaManagementDbContextModelSnapshot.cs +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Data/Migrations/MadiaManagementDbContextModelSnapshot.cs @@ -1,4 +1,5 @@ // +using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; @@ -27,8 +28,30 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasAnnotation("SqlServer:HiLoSequenceName", "media_hilo") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + b.Property("AccountId"); + + b.Property("ContentType"); + + b.Property("DateAdded"); + + b.Property("Description"); + + b.Property("ExtType"); + + b.Property("Height"); + + b.Property("MediaType"); + b.Property("Name"); + b.Property("OriginalName"); + + b.Property("PublicId"); + + b.Property("Url"); + + b.Property("Width"); + b.HasKey("Id"); b.ToTable("Media"); diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Impl/Mappings/MediaMappings.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Impl/Mappings/MediaMappings.cs index c0d3b313..806d56da 100644 --- a/src/Services/media-basket/O2NextGen.MediaBasket.Impl/Mappings/MediaMappings.cs +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Impl/Mappings/MediaMappings.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using O2NextGen.MediaBasket.Business.Models; using O2NextGen.MediaBasket.Data.Entities; @@ -8,22 +9,46 @@ internal static class MediaMappings { public static Media ToService(this MediaEntity entity) { - return entity != null ? new Media() - { - Id = entity.Id, - Name = entity.Name, - OriginalName = entity.OriginalName - } : null; + return entity != null + ? new Media() + { + Id = entity.Id, + Name = entity.Name, + OriginalName = entity.OriginalName, + PublicId = entity.PublicId, + AccountId = entity.AccountId, + ContentType = entity.ContentType, + DateAdded = entity.DateAdded ?? DateTime.Now, + Description = entity.Description, + Width = entity.Width, + Height = entity.Height, + ExtType = entity.ExtType, + MediaType = entity.MediaType, + Url = entity.Url, + } + : null; } public static MediaEntity ToEntity(this Media model) { - return model != null ? new MediaEntity() - { - Id = model.Id, - Name = model.Name, - OriginalName = model.OriginalName - } : null; + return model != null + ? new MediaEntity() + { + Id = model.Id, + Name = model.Name, + OriginalName = model.OriginalName, + PublicId = model.PublicId, + AccountId = model.AccountId, + ContentType = model.ContentType, + DateAdded = model.DateAdded, + Description = model.Description, + Width = model.Width, + Height = model.Height, + ExtType = model.ExtType, + MediaType = model.MediaType, + Url = model.Url, + } + : null; } public static IReadOnlyCollection diff --git a/src/Services/media-basket/O2NextGen.MediaBasket.Impl/Services/MediaService.cs b/src/Services/media-basket/O2NextGen.MediaBasket.Impl/Services/MediaService.cs index 82e102b2..39436b30 100644 --- a/src/Services/media-basket/O2NextGen.MediaBasket.Impl/Services/MediaService.cs +++ b/src/Services/media-basket/O2NextGen.MediaBasket.Impl/Services/MediaService.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.IO; using System.Linq; diff --git a/src/Services/on-tracker/O2NextGen.OnTracker.Api/O2NextGen.OnTracker.Api.csproj b/src/Services/on-tracker/O2NextGen.OnTracker.Api/O2NextGen.OnTracker.Api.csproj index 80014d9b..c37f54b5 100644 --- a/src/Services/on-tracker/O2NextGen.OnTracker.Api/O2NextGen.OnTracker.Api.csproj +++ b/src/Services/on-tracker/O2NextGen.OnTracker.Api/O2NextGen.OnTracker.Api.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/Services/s-link/O2NextGen.SLink.Api/O2NextGen.SLink.Api.csproj b/src/Services/s-link/O2NextGen.SLink.Api/O2NextGen.SLink.Api.csproj index 2f8a0d68..94cfad5e 100644 --- a/src/Services/s-link/O2NextGen.SLink.Api/O2NextGen.SLink.Api.csproj +++ b/src/Services/s-link/O2NextGen.SLink.Api/O2NextGen.SLink.Api.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/Services/smalltalk/O2NextGen.SmallTalk.Api/O2NextGen.SmallTalk.Api.csproj b/src/Services/smalltalk/O2NextGen.SmallTalk.Api/O2NextGen.SmallTalk.Api.csproj index 11923b9c..4f32940c 100644 --- a/src/Services/smalltalk/O2NextGen.SmallTalk.Api/O2NextGen.SmallTalk.Api.csproj +++ b/src/Services/smalltalk/O2NextGen.SmallTalk.Api/O2NextGen.SmallTalk.Api.csproj @@ -24,7 +24,7 @@ 2.2.0 - + diff --git a/src/docker-compose.override.yml b/src/docker-compose.override.yml index 546aeeb5..17fa8f1d 100644 --- a/src/docker-compose.override.yml +++ b/src/docker-compose.override.yml @@ -120,6 +120,9 @@ services: - ASPNETCORE_ENVIRONMENT=Development - ConnectionString=Server=sql.data;Initial Catalog=O2NextGen.MediaBasketDb;Persist Security Info=False;User ID=sa;Password=your@Password;Connection Timeout=30; #- ASPNETCORE_URLS=https://+:443;http://+:80 + - CloudinarySettings__CloudName=cloudName + - CloudinarySettings__ApiKey=api_key + - CloudinarySettings__ApiSecret=api_secret ports: - "5005:80" depends_on: