Skip to content

Commit

Permalink
error handling for domain file store upload
Browse files Browse the repository at this point in the history
  • Loading branch information
joao4all committed Jul 26, 2024
1 parent 2da90f6 commit e71a641
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 20 deletions.
10 changes: 0 additions & 10 deletions COMETwebapp/Components/Common/FormButtons.razor.css

This file was deleted.

16 changes: 15 additions & 1 deletion COMETwebapp/Components/EngineeringModel/FileStore/FileForm.razor
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,21 @@ Copyright (c) 2023-2024 Starion Group S.A.

</DxFormLayout>
<div class="pt-3"></div>
<ValidationSummary />

<div class="validation-container mt-3">
<ul class="validation-errors">
<ValidationSummary/>
@if (!this.ViewModel.SelectedFileRevisions.Any())
{
<li class="validation-message">At least one file revision should exist</li>
}
@if (!string.IsNullOrWhiteSpace(this.ErrorMessage))
{
<li class="validation-message">@(this.ErrorMessage)</li>
}
</ul>
</div>

<div class="dxbl-grid-edit-form-buttons">
<DxButton Id="deleteFileButton"
Click="@(() => this.IsDeletePopupVisible = true)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ namespace COMETwebapp.Components.EngineeringModel.FileStore

using System.ComponentModel.DataAnnotations;

using FluentResults;

/// <summary>
/// Support class for the <see cref="FileForm"/>
/// </summary>
Expand All @@ -47,14 +49,25 @@ public partial class FileForm : SelectedDataItemForm
/// </summary>
public bool IsDeletePopupVisible { get; private set; }

/// <summary>
/// Gets the error message from the <see cref="IFileHandlerViewModel.CreateOrEditFile"/>, if any
/// </summary>
public string ErrorMessage { get; private set; } = string.Empty;

/// <summary>
/// Method that is executed when there is a valid submit
/// </summary>
/// <returns>A <see cref="Task"/></returns>
protected override async Task OnValidSubmit()
{
await this.ViewModel.CreateOrEditFile(this.ShouldCreate);
await base.OnValidSubmit();
this.ErrorMessage = string.Empty;
var result = await this.ViewModel.CreateOrEditFile(this.ShouldCreate);
this.ErrorMessage = string.Join(", ", result.Reasons.OfType<IExceptionalError>().Select(x => x.Exception.Message));

if (string.IsNullOrWhiteSpace(this.ErrorMessage))
{
await base.OnValidSubmit();
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ namespace COMETwebapp.ViewModels.Components.EngineeringModel.FileStore.FileHandl

using COMETwebapp.ViewModels.Components.EngineeringModel.FileStore.FileRevisionHandler;

using FluentResults;

using Microsoft.AspNetCore.Components;

/// <summary>
Expand Down Expand Up @@ -149,8 +151,8 @@ public async Task MoveFile(File file, Folder targetFolder)
/// Creates or edits a file
/// </summary>
/// <param name="shouldCreate">The condition to check if the file should be created</param>
/// <returns>A <see cref="Task" /></returns>
public async Task CreateOrEditFile(bool shouldCreate)
/// <returns>A <see cref="Task"/> containing a <see cref="Result"/></returns>
public async Task<Result> CreateOrEditFile(bool shouldCreate)
{
this.IsLoading = true;
this.logger.LogInformation("Creating or editing file");
Expand Down Expand Up @@ -193,11 +195,20 @@ public async Task CreateOrEditFile(bool shouldCreate)
}

thingsToUpdate.Add(this.CurrentThing);
var result = await this.SessionService.CreateOrUpdateThings(fileStoreClone, thingsToUpdate, newFileRevisions.Select(x => x.LocalPath).ToList());

await this.SessionService.CreateOrUpdateThings(fileStoreClone, thingsToUpdate, newFileRevisions.Select(x => x.LocalPath).ToList());
if (result.IsSuccess)
{
this.logger.LogInformation("File with iid {iid} updated successfully", this.CurrentThing.Iid);
}
else
{
this.logger.LogWarning("File could not be created. {warning}", string.Join(", ", string.Join(", ", result.Reasons.Select(x => x.Message))));
}

this.logger.LogInformation("File with iid {iid} updated successfully", this.CurrentThing.Iid);
this.IsLoading = false;

return result;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace COMETwebapp.ViewModels.Components.EngineeringModel.FileStore.FileHandl

using COMETwebapp.ViewModels.Components.EngineeringModel.FileStore.FileRevisionHandler;

using FluentResults;

/// <summary>
/// View model used to manage the files in Filestores
/// </summary>
Expand Down Expand Up @@ -96,8 +98,8 @@ public interface IFileHandlerViewModel : IApplicationBaseViewModel
/// Creates a file into a target folder
/// </summary>
/// <param name="shouldCreate"></param>
/// <returns>A <see cref="Task"/></returns>
Task CreateOrEditFile(bool shouldCreate);
/// <returns>A <see cref="Task"/> containing a <see cref="Result"/></returns>
Task<Result> CreateOrEditFile(bool shouldCreate);

/// <summary>
/// Deletes the current file
Expand Down
13 changes: 12 additions & 1 deletion COMETwebapp/wwwroot/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,15 @@ sub {

.model-editor-details {
flex: 1 1 40% !important;
}
}

.validation-container {
border: dashed 1px red;
padding-top: 1rem;
padding-right: 1rem;
border-radius: 10px;
}

.validation-container:not(:has(li)) {
display: none;
}

0 comments on commit e71a641

Please sign in to comment.