-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added File Data Access TODO : FTP Layer
- Loading branch information
Showing
12 changed files
with
227 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Microsoft.AspNetCore.Mvc.Filters; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using System; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Library.Encyclopedia.API.Attributes | ||
| { | ||
| [AttributeUsage(validOn: AttributeTargets.Class | AttributeTargets.Method)] | ||
| public class ApiKeyAttribute : Attribute, IAsyncActionFilter | ||
| { | ||
| private const string APIKEYNAME = "ApiKey"; | ||
| public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) | ||
| { | ||
| if (!context.HttpContext.Request.Headers.TryGetValue(APIKEYNAME, out var extractedApiKey)) | ||
| { | ||
| context.Result = new ContentResult() | ||
| { | ||
| StatusCode = 401, | ||
| Content = "Api Key was not provided" | ||
| }; | ||
| return; | ||
| } | ||
|
|
||
| var appSettings = context.HttpContext.RequestServices.GetRequiredService<IConfiguration>(); | ||
|
|
||
| var apiKey = appSettings.GetValue<string>(APIKEYNAME); | ||
|
|
||
| if (!apiKey.Equals(extractedApiKey)) | ||
| { | ||
| context.Result = new ContentResult() | ||
| { | ||
| StatusCode = 401, | ||
| Content = "Api Key is not valid" | ||
| }; | ||
| return; | ||
| } | ||
|
|
||
| await next(); | ||
| } | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| using Library.Encyclopedia.API.Attributes; | ||
| using Library.Encyclopedia.DataAccess; | ||
| using Library.Encyclopedia.DataAccess.DataAccess; | ||
| using Library.Encyclopedia.Entity.Interfaces; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Microsoft.Extensions.Logging; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Library.Encyclopedia.API.Controllers | ||
| { | ||
| [ApiController] | ||
| [Route("[controller]")] | ||
| public class FilesController : ControllerBase | ||
| { | ||
| private readonly ILogger<FilesController> _logger; | ||
| private readonly IFilesDataAccess filesDataAccess; | ||
|
|
||
| public FilesController(ILogger<FilesController> logger, IApplicationDbContext dbContext) | ||
| { | ||
| _logger = logger; | ||
| this.filesDataAccess = new FilesDataAccess(dbContext); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Upload Files | ||
| /// </summary> | ||
| /// <param name="query"></param> | ||
| /// <param name="offset"></param> | ||
| /// <param name="size"></param> | ||
| /// <param name="asc"></param> | ||
| /// <returns></returns> | ||
| //[HttpPost("{id}")] | ||
| //[ApiKey] | ||
| //public async Task<IActionResult> Get(Guid id, List<IFormFile> files) | ||
| //{ | ||
| // try | ||
| // { | ||
| // ////var response = await filesDataAccess.AddFiles(id, files); | ||
|
|
||
| // //if (response == null) | ||
| // //{ | ||
| // // return StatusCode(204); | ||
| // //} | ||
| // //else | ||
| // //{ | ||
| // // return Ok(response); | ||
| // //} | ||
| // } | ||
| // catch (Exception ex) | ||
| // { | ||
| // _logger.LogError(ex, $"an error has occured {ex.Message}"); | ||
| // throw; | ||
| // } | ||
| //} | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
Library.Encyclopedia.DataAccess/DataAccess/FilesDataAccess.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| using Library.Encyclopedia.Entity.Interfaces; | ||
| using Library.Encyclopedia.Entity.Models; | ||
| using Microsoft.EntityFrameworkCore; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Library.Encyclopedia.DataAccess.DataAccess | ||
| { | ||
| public class FilesDataAccess : IFilesDataAccess | ||
| { | ||
| private IApplicationDbContext _dbcontext; | ||
| public FilesDataAccess(IApplicationDbContext dbcontext) | ||
| { | ||
| _dbcontext = dbcontext; | ||
| } | ||
|
|
||
| public async Task AddFiles(IEnumerable<Files> files) | ||
| { | ||
| await _dbcontext.Files.AddRangeAsync(files); | ||
| await _dbcontext.SaveChanges(); | ||
| } | ||
|
|
||
| public async Task RemoveFiles(IEnumerable<Guid> ids) | ||
| { | ||
| //find file entities | ||
| var files = await _dbcontext.Files.Where(s => ids.Contains(s.Id)).ToListAsync(); | ||
|
|
||
| _dbcontext.Files.RemoveRange(files); | ||
| await _dbcontext.SaveChanges(); | ||
| } | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
Library.Encyclopedia.Entity/Interfaces/IFilesDataAccess.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| using Library.Encyclopedia.Entity.Models; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Library.Encyclopedia.Entity.Interfaces | ||
| { | ||
| public interface IFilesDataAccess | ||
| { | ||
| Task AddFiles(IEnumerable<Files> files); | ||
| Task RemoveFiles(IEnumerable<Guid> ids); | ||
| } | ||
| } |
Oops, something went wrong.