develop #10

Merged
s426229 merged 80 commits from develop into master 2021-01-27 18:32:19 +01:00
7 changed files with 134 additions and 1 deletions
Showing only changes of commit 4447d72032 - Show all commits

View File

@ -0,0 +1,37 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Serwer.Infrastructure.Services;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace Serwer.Api.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class ImageController : ControllerBase
{
private readonly IImageService _imageService;
public ImageController(IImageService imageService)
{
_imageService = imageService;
}
[HttpPost("Process")]
public async Task<IActionResult> Process(IFormFile image)
{
if(image == null)
{
return NotFound();
}
using (var memoryStream = new MemoryStream())
{
await image.CopyToAsync(memoryStream);
await _imageService.Process(image.Name, image.ContentType, memoryStream.ToArray());
}
return Ok();
}
}
}

View File

@ -63,6 +63,7 @@ namespace Serwer.Api
services.AddSingleton<IMapper>(AutoMapperConfig.Initialize());
services.AddSingleton<IJwtHandler, JwtHandler>(sp => new JwtHandler(jwtSettings));
services.AddScoped<IUserRepository, UserRepository>();
services.AddScoped<IImageService, ImageService>();
services.AddScoped<IUserService, UserService>();
}
@ -71,12 +72,17 @@ namespace Serwer.Api
{
if (env.IsDevelopment())
{
app.UseCors(builder =>
{
builder.AllowAnyHeader();
builder.AllowAnyMethod();
builder.AllowAnyOrigin();
});
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Serwer.Api v1"));
}
app.UseHttpsRedirection();
app.UseRouting();

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Serwer.Core.Domain
{
public class File
{
public string Name { get; protected set; }
public string ContentType { get; protected set; }
public byte[] Bytes { get; protected set; }
public long SizeBytes => Bytes.Length;
protected File()
{
}
protected File(string name, string contentType, byte[] bytes)
{
Name = name;
ContentType = contentType;
Bytes = bytes;
}
public static File Empty => new File();
public static File Create(string name, string contentType, byte[] bytes)
=> new File(name, contentType, bytes);
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Serwer.Infrastructure.Services
{
public interface IImageHandler
{
}
}

View File

@ -0,0 +1,14 @@
using Serwer.Core.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Serwer.Infrastructure.Services
{
public interface IImageService
{
Task Process(string name, string contentType, byte[] bytes);
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Serwer.Infrastructure.Services
{
class ImageHandler
{
}
}

View File

@ -0,0 +1,19 @@
using Serwer.Core.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Serwer.Infrastructure.Services
{
public class ImageService : IImageService
{
private readonly ISet<File> _files = new HashSet<File>();
public async Task Process(string name, string contentType, byte[] bytes)
{
var file = File.Create(name, contentType, bytes);
await Task.FromResult(_files.Add(file));
}
}
}