Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="2.2.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -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; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</PackageReference>
<PackageReference Include="Serilog.Sinks.File" Version="2.2.0">
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</PackageReference>
<PackageReference Include="Serilog.Sinks.File" Version="2.2.0">
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,16 +17,18 @@ public class MediaController : ControllerBase

private readonly IMediaService _mediaService;
private readonly UrlsConfig _config;
private readonly ILogger<MediaController> _logger;

#endregion


#region Ctors

public MediaController(IMediaService mediaService, UrlsConfig config)
public MediaController(IMediaService mediaService, UrlsConfig config,ILogger<MediaController> logger)
{
_mediaService = mediaService;
_config = config;
_mediaService = mediaService ?? throw new ArgumentException(nameof(mediaService));
_config = config ?? throw new ArgumentException(nameof(config));
_logger = logger;
}

#endregion
Expand All @@ -36,6 +40,7 @@ public MediaController(IMediaService mediaService, UrlsConfig config)
[Route("")]
public async Task<IActionResult> GetAllAsync()
{
_logger.LogInformation($"Execute method - {nameof(GetAllAsync)}");
var url = _config.Auth;
var models = await _mediaService.GetAllAsync(CancellationToken.None);
return Ok(models.ToViewModel());
Expand All @@ -45,27 +50,30 @@ public async Task<IActionResult> GetAllAsync()
[Route("{id}")]
public async Task<IActionResult> 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<IActionResult> 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<IActionResult> AddAsync(MediaViewModel model, CancellationToken ct)
public async Task<IActionResult> 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
Expand All @@ -74,6 +82,7 @@ public async Task<IActionResult> AddAsync(MediaViewModel model, CancellationToke
[Route("id")]
public async Task<IActionResult> RemoveAsync(long id,CancellationToken ct)
{
_logger.LogInformation($"Execute method - {nameof(RemoveAsync)}");
await _mediaService.RemoveAsync(id, ct);
return NoContent();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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/"]
Expand Down
Original file line number Diff line number Diff line change
@@ -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; }
}
}
Original file line number Diff line number Diff line change
@@ -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; }
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Loading