Skip to content

Commit

Permalink
Merge pull request #31 from lrodolfol/main
Browse files Browse the repository at this point in the history
chore: refactor outflow
tinosnegocios authored Nov 15, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 9b4c124 + fe611f6 commit 4a8f1d9
Showing 12 changed files with 116 additions and 26 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/main_churchmanager.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy ASP.Net Core app to Azure Web App - churchmanager

on:
push:
branches:
- main
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '7.x'
include-prerelease: true

- name: Build with dotnet
run: dotnet build ./Registration/src/Application/Registration.API/Registration.API.csproj --configuration Release

- name: dotnet publish
run: dotnet publish ./Registration/src/Application/Registration.API/Registration.API.csproj -c Release -o ${{env.DOTNET_ROOT}}/myapp

- name: Upload artifact for deployment job
uses: actions/upload-artifact@v3
with:
name: .net-app
path: ${{env.DOTNET_ROOT}}/myapp

deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: .net-app

- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: 'churchmanager'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_7F53C6FD785745CAADB6C1E603A085F5 }}
package: .
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ public async Task<IActionResult> GetOne([FromRoute] int id)
}

[Authorize(Roles = "L-SCT, M-SCT, M-TRS, L-TRS")]
[HttpGet("api/v1/out-flow/{yearMonth:int}/{id:int}")]
[HttpGet("api/v1/out-flow/{yearMonth:int}/{churchId:int}")]
public async Task<IActionResult> GetOneByMonth([FromRoute] int yearMonth, [FromRoute] int churchId)
{
var resultViewModel = await _handler.GetAllByMonth(yearMonth.ToString(), churchId);
Original file line number Diff line number Diff line change
@@ -41,7 +41,6 @@ public Offering(int id, string description, DateTime day, string competence, int

private void SetPhoto()
{

Photo = $"offeringCH-{ChurchId}-{CreateGuid(6)}";
}

Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ public class OutFlow : Entitie
public decimal Discount { get; private set; }
public decimal TotalAmount { get; private set; }
public int OutFlowKindId { get; private set; }
public string? Photo { get; private set; }
public OutFlowKind? OutFlowKind { get; private set; }
public int ChurchId { get; private set; }
public Church? Church { get; set; }
@@ -31,6 +32,10 @@ public OutFlow(int id, DateTime day, string competence, string description, int
public OutFlow()
{
}
private void SetPhoto()
{
Photo = $"outFlowCH-{ChurchId}-{CreateGuid(6)}";
}

public void CalculateTotalAmount()
{
@@ -51,4 +56,9 @@ public void UpdateChanges(OutFlow editOutFlow)

CalculateTotalAmount();
}

public void UpdateData()
{
SetPhoto();
}
}
Original file line number Diff line number Diff line change
@@ -6,13 +6,14 @@ namespace Registration.Infrastructure.AcessCors;
public static class PolicyCors
{
private static readonly string urlChurchFron = "http://localhost:4200";

private static readonly string urlChurchFronCloudAzure = "https://ecclesiafundo.azurewebsites.net";
public static void AddPolicyPermission(this WebApplicationBuilder builder)
{
builder.Services.AddCors(
p => p.AddPolicy("corsp", build =>
{
build.WithOrigins(urlChurchFron).AllowAnyMethod().AllowAnyHeader();
build.WithOrigins(urlChurchFronCloudAzure).AllowAnyMethod().AllowAnyHeader();
}
));
}
Original file line number Diff line number Diff line change
@@ -28,7 +28,6 @@ public async Task Delete(Post Post)
public IQueryable<Post> GetByIds(int[] ids)
{
var post = _context.Posts
.AsNoTracking()
.AsNoTracking()
.Where(x => ids.Contains(x.Id));

Original file line number Diff line number Diff line change
@@ -15,8 +15,8 @@ public UserRepository(DataContext context)
public IQueryable<User>? GetAll()
{
var usersQueryable = _context.Users
.Include(x => x.Church)
.Include(x => x.UserRoles)
.Include(x => x.Church!)
.Include(x => x.UserRoles!)
.ThenInclude(r => r.Role)
.AsNoTracking().AsQueryable();

@@ -26,8 +26,8 @@ public UserRepository(DataContext context)
public async Task<User> GetOne(int id)
{
var user = await _context.Users
.Include(x => x.Church)
.Include(x => x.UserRoles)
.Include(x => x.Church!)
.Include(x => x.UserRoles!)
.ThenInclude(r => r.Role)
.FirstOrDefaultAsync(x => x.Id == id);

6 changes: 6 additions & 0 deletions Registration/src/Service/CloudServices/AWS/AWSBucketS3.cs
Original file line number Diff line number Diff line change
@@ -34,10 +34,16 @@ public Task<bool> SaveImage()
if (!AllowImageTypes.Any() || String.IsNullOrEmpty(StorageName) ||
String.IsNullOrEmpty(FileName) || String.IsNullOrEmpty(ImageType) ||
String.IsNullOrEmpty(Base64Image) || String.IsNullOrEmpty(ImagePath))
{
_logger.Error("Image not save. Invalid Parameters");
return Task.FromResult(false);
}

if (!CheckValues())
{
_logger.Error("Image not save. Invalid Parameters");
return Task.FromResult(false);
}

try
{
Original file line number Diff line number Diff line change
@@ -281,9 +281,8 @@ public async Task<CViewModel> CreateAsync(EditOfferingDto dto)

offering.UpdateData();
await _context.Post(offering);


await SaveImageStoreAsync(offering, offering.Photo, dto.base64Image);
await SaveImageStoreAsync(offering.Photo!, dto.base64Image);

var newOffering = await _context.GetOneAsNoTracking(offering.Id);

@@ -341,7 +340,7 @@ public async Task<CViewModel> UpdateAsync(EditOfferingDto dto, int id)
offering.UpdateChanges(editOffering);

offering.UpdateData();
await SaveImageStoreAsync(offering, offering.Photo, dto.base64Image);
await SaveImageStoreAsync(offering.Photo!, dto.base64Image);

await _context.Put(offering);

@@ -420,7 +419,7 @@ public async Task<CViewModel> DeleteAsync(int id)
return offering.Result;
}

private async Task SaveImageStoreAsync(Offering model, string fileName, string? base64Image)
private async Task SaveImageStoreAsync(string fileName, string? base64Image)
{
ModelImage serviceImage = new("offerings", fileName, _logger, _configuration);
await serviceImage.SaveImageStoreAsync(base64Image);
Original file line number Diff line number Diff line change
@@ -9,19 +9,23 @@
using Registration.DomainBase.Entities.Registrations;
using Registration.Mapper.DTOs.Registration.OutFlow;
using Serilog;
using Microsoft.Extensions.Configuration;
using Registration.Handlers.CloudHandlers;

namespace Registration.Handlers.Handlers.Registrations;
public sealed class OutFlowHanler : BaseRegisterNormalHandler
{
private IOutFlowRepository _context;
private OperationsHandler _operationsHandler;
private readonly ILogger _logger;
private readonly IConfiguration _configuration;

public OutFlowHanler(IOutFlowRepository context, IMapper mapper, CViewModel viewModel, OperationsHandler operationsHandler, ILogger logger) : base(mapper, viewModel)
public OutFlowHanler(IOutFlowRepository context, IMapper mapper, CViewModel viewModel, OperationsHandler operationsHandler, ILogger logger, IConfiguration configuration) : base(mapper, viewModel)
{
_context = context;
_operationsHandler = operationsHandler;
_logger = logger;
_configuration = configuration;
}

protected override async Task<bool> MonthWorkIsBlockAsync(string competence, int churchId)
@@ -82,7 +86,7 @@ public async Task<CViewModel> GetOne(int id)
var outFlow = await _context.GetOne(id);
if (outFlow == null)
{
_statusCode = (int)Scode.NOT_FOUND;
_statusCode = (int)Scode.OK;
_viewModel!.SetErrors("Object not found");
_logger.Error("The outflow with id {id} was not found", id);
return _viewModel;
@@ -147,30 +151,33 @@ public async Task<CViewModel> GetAllByMonth(string yearMonth, int churchId)
return _viewModel;
}

public async Task<CViewModel> Create(EditOutFlowDto outFlowEditDto)
public async Task<CViewModel> Create(EditOutFlowDto dto)
{
_logger.Information("OutFlow - attemp create");

outFlowEditDto.Validate();
if (!outFlowEditDto.IsValid)
dto.Validate();
if (!dto.IsValid)
{
_statusCode = (int)Scode.BAD_REQUEST;
_viewModel!.SetErrors(outFlowEditDto.GetNotification());
_viewModel!.SetErrors(dto.GetNotification());
_logger.Error("Invalid propertie. Check the properties");
return _viewModel;
}

if (await MonthWorkIsBlockAsync(outFlowEditDto.Competence!, outFlowEditDto.ChurchId))
if (await MonthWorkIsBlockAsync(dto.Competence!, dto.ChurchId))
return _viewModel;

try
{
var outFlow = _mapper.Map<OutFlow>(outFlowEditDto);
var outFlow = _mapper.Map<OutFlow>(dto);
outFlow.CalculateTotalAmount();

//verificar o totalAmount
outFlow.UpdateData();
await _context.Post(outFlow)!;

await SaveImageStoreAsync(outFlow.Photo!, dto.base64Image);

var newOutFlow = await _context.GetOne(outFlow.Id);

var outFlowReadDto = _mapper.Map<ReadOutFlowDto>(newOutFlow);
@@ -196,21 +203,21 @@ public async Task<CViewModel> Create(EditOutFlowDto outFlowEditDto)
return _viewModel;
}

public async Task<CViewModel> Update(EditOutFlowDto outFlowEditDto, int id)
public async Task<CViewModel> Update(EditOutFlowDto dto, int id)
{
_logger.Information("OutFlow - attemp update");

outFlowEditDto.Validate();
if (!outFlowEditDto.IsValid)
dto.Validate();
if (!dto.IsValid)
{
_statusCode = (int)Scode.BAD_REQUEST;
_viewModel!.SetErrors(outFlowEditDto.GetNotification());
_viewModel!.SetErrors(dto.GetNotification());
_logger.Error("Invalid propertie. Check the properties");

return _viewModel;
}

if (await MonthWorkIsBlockAsync(outFlowEditDto.Competence, outFlowEditDto.ChurchId))
if (await MonthWorkIsBlockAsync(dto.Competence!, dto.ChurchId))
return _viewModel;

try
@@ -223,11 +230,14 @@ public async Task<CViewModel> Update(EditOutFlowDto outFlowEditDto, int id)
_logger.Error("The outflow with id {id} was not found", id);
}

var editOutFlow = _mapper.Map<OutFlow>(outFlowEditDto);
var editOutFlow = _mapper.Map<OutFlow>(dto);
outFlow!.UpdateChanges(editOutFlow);
outFlow.UpdateData();

await _context.Put(outFlow);

await SaveImageStoreAsync(outFlow.Photo!, dto.base64Image);

var userReadDto = _mapper.Map<ReadOutFlowDto>(editOutFlow);

_statusCode = (int)Scode.OK;
@@ -289,4 +299,10 @@ public async Task<CViewModel> Delete(int id)

return _viewModel;
}

private async Task SaveImageStoreAsync(string fileName, string? base64Image)
{
ModelImage serviceImage = new("outflow", fileName, _logger, _configuration);
await serviceImage.SaveImageStoreAsync(base64Image);
}
}
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ public class EditOutFlowDto : ModelDto
public int OutFlowKindId { get; set; }
[Required]
public int ChurchId { get; set; }
public string? base64Image { get; set; }

public void Validate()
{
Original file line number Diff line number Diff line change
@@ -11,4 +11,6 @@ public class ReadOutFlowDto : ModelDto
public decimal TotalAmount { get; private set; }
public string? OutFlow { get; private set; }
public string? Church { get; private set; }
public string? Photo { get; private set; }
public int OutFlowKindId { get; set; }
}

0 comments on commit 4a8f1d9

Please sign in to comment.