-
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.
Merge pull request #107 from TomaszKandula/dev
merge: dev to stage
- Loading branch information
Showing
15 changed files
with
149 additions
and
1 deletion.
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
9 changes: 9 additions & 0 deletions
9
...Sender.Backend/EmailSender.Backend.Cqrs/Handlers/Queries/Logger/GetLogFileContentQuery.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,9 @@ | ||
namespace EmailSender.Backend.Cqrs.Handlers.Queries.Logger; | ||
|
||
using Microsoft.AspNetCore.Mvc; | ||
using MediatR; | ||
|
||
public class GetLogFileContentQuery : IRequest<FileContentResult> | ||
{ | ||
public string LogFileName { get; set; } | ||
} |
26 changes: 26 additions & 0 deletions
26
...Backend/EmailSender.Backend.Cqrs/Handlers/Queries/Logger/GetLogFileContentQueryHandler.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,26 @@ | ||
namespace EmailSender.Backend.Cqrs.Handlers.Queries.Logger; | ||
|
||
using System; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Core.Exceptions; | ||
using Shared.Resources; | ||
|
||
public class GetLogFileContentQueryHandler : RequestHandler<GetLogFileContentQuery, FileContentResult> | ||
{ | ||
public override async Task<FileContentResult> Handle(GetLogFileContentQuery request, CancellationToken cancellationToken) | ||
{ | ||
var pathToFolder = $"{AppDomain.CurrentDomain.BaseDirectory}logs"; | ||
if (!Directory.Exists(pathToFolder)) | ||
throw new BusinessException(nameof(ErrorCodes.ERROR_UNEXPECTED), ErrorCodes.ERROR_UNEXPECTED); | ||
|
||
var fullFilePath = $"{pathToFolder}{Path.DirectorySeparatorChar}{request.LogFileName}"; | ||
if (!File.Exists(fullFilePath)) | ||
throw new BusinessException(nameof(ErrorCodes.FILE_NOT_FOUND), ErrorCodes.FILE_NOT_FOUND); | ||
|
||
var fileContent = await File.ReadAllBytesAsync(fullFilePath, cancellationToken); | ||
return new FileContentResult(fileContent, "text/plain"); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...ckend/EmailSender.Backend.Cqrs/Handlers/Queries/Logger/GetLogFileContentQueryValidator.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,18 @@ | ||
namespace EmailSender.Backend.Cqrs.Handlers.Queries.Logger; | ||
|
||
using FluentValidation; | ||
using Shared.Resources; | ||
|
||
public class GetLogFileContentQueryValidator : AbstractValidator<GetLogFileContentQuery> | ||
{ | ||
public GetLogFileContentQueryValidator() | ||
{ | ||
RuleFor(query => query.LogFileName) | ||
.NotEmpty() | ||
.WithErrorCode(nameof(ValidationCodes.REQUIRED)) | ||
.WithMessage(ValidationCodes.REQUIRED) | ||
.MaximumLength(255) | ||
.WithErrorCode(nameof(ValidationCodes.NAME_TOO_LONG)) | ||
.WithMessage(ValidationCodes.NAME_TOO_LONG); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
EmailSender.Backend/EmailSender.Backend.Cqrs/Handlers/Queries/Logger/GetLogFilesListQuery.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,5 @@ | ||
namespace EmailSender.Backend.Cqrs.Handlers.Queries.Logger; | ||
|
||
using MediatR; | ||
|
||
public class GetLogFilesListQuery : IRequest<GetLogFilesListQueryResult> { } |
30 changes: 30 additions & 0 deletions
30
...r.Backend/EmailSender.Backend.Cqrs/Handlers/Queries/Logger/GetLogFilesListQueryHandler.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,30 @@ | ||
namespace EmailSender.Backend.Cqrs.Handlers.Queries.Logger; | ||
|
||
using System; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Collections.Generic; | ||
|
||
public class GetLogFilesListQueryHandler : RequestHandler<GetLogFilesListQuery, GetLogFilesListQueryResult> | ||
{ | ||
public override async Task<GetLogFilesListQueryResult> Handle(GetLogFilesListQuery request, CancellationToken cancellationToken) | ||
{ | ||
var pathToFolder = $"{AppDomain.CurrentDomain.BaseDirectory}logs"; | ||
if (!Directory.Exists(pathToFolder)) | ||
return new GetLogFilesListQueryResult(); | ||
|
||
var fullPathFileList = Directory.EnumerateFiles(pathToFolder, "*.txt", SearchOption.TopDirectoryOnly); | ||
var logFiles = new List<string>(); | ||
|
||
foreach (var item in fullPathFileList) | ||
{ | ||
logFiles.Add(Path.GetFileName(item)); | ||
} | ||
|
||
return await Task.FromResult(new GetLogFilesListQueryResult | ||
{ | ||
LogFiles = logFiles | ||
}); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...er.Backend/EmailSender.Backend.Cqrs/Handlers/Queries/Logger/GetLogFilesListQueryResult.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,8 @@ | ||
namespace EmailSender.Backend.Cqrs.Handlers.Queries.Logger; | ||
|
||
using System.Collections.Generic; | ||
|
||
public class GetLogFilesListQueryResult | ||
{ | ||
public List<string> LogFiles { get; set; } | ||
} |
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
6 changes: 6 additions & 0 deletions
6
EmailSender.Backend/EmailSender.Backend.Shared/Resources/ErrorCodes.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
6 changes: 6 additions & 0 deletions
6
EmailSender.Backend/EmailSender.Backend.Shared/Resources/ValidationCodes.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,23 @@ | ||
namespace EmailSender.WebApi.Controllers; | ||
|
||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Http; | ||
using Backend.Cqrs.Handlers.Queries.Logger; | ||
using MediatR; | ||
|
||
[ApiVersion("1.0")] | ||
public class LoggerController : BaseController | ||
{ | ||
public LoggerController(IMediator mediator) : base(mediator) { } | ||
|
||
[HttpGet] | ||
[ProducesResponseType(typeof(GetLogFilesListQueryResult), StatusCodes.Status200OK)] | ||
public async Task<GetLogFilesListQueryResult> GetLogFilesList([FromHeader(Name = HeaderName)] string privateKey) | ||
=> await Mediator.Send(new GetLogFilesListQuery()); | ||
|
||
[HttpGet("{fileName}")] | ||
[ProducesResponseType(typeof(IActionResult), StatusCodes.Status200OK)] | ||
public async Task<IActionResult> GetLogFileContent([FromRoute] string fileName, [FromHeader(Name = HeaderName)] string privateKey) | ||
=> await Mediator.Send(new GetLogFileContentQuery { LogFileName = fileName }); | ||
} |
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