SHA256
StayExportTracking - Changes to Models
- Added new fields to track stay export uploading. - Added methods in EntityServices to update this fields. - Show new fields in UI (with required locale).
This commit is contained in:
1 parent
34b61e7fde
commit
2f0062b313
20 files changed
+586
-8
No files matched your search
@@ -1,3 +1,4 @@
|
||||
using Somnia.GuestLog.Enums.Models;
|
||||
using Somnia.GuestLog.Models.DTOs;
|
||||
using Somnia.GuestLog.Models.QueryConfigs;
|
||||
|
||||
@@ -10,6 +11,13 @@ public interface IStayEntryEntityService
|
||||
public Task<Result> DeleteEntryAsync(StayEntryDTO dto);
|
||||
public Task<Result> DeleteEntryAsync(long id);
|
||||
|
||||
/// <summary>
|
||||
/// Update StayEntry Upload Status.
|
||||
/// </summary>
|
||||
/// <param name="id">StayEntry ID to update</param>
|
||||
/// <param name="newStatus">New Upload Status</param>
|
||||
public Task<Result> UpdateEntryUploadStatusAsync(long id, UploadStatus newStatus);
|
||||
|
||||
public Task<StayEntryDTO?> GetDtoByIdAsync(long id, StayEntryQueryConfig? queryConfig = null);
|
||||
public Task<IEnumerable<StayEntryDTO>> GetDtoListAsync(StayEntryQueryConfig? queryConfig = null);
|
||||
public Task<IEnumerable<StayEntryDTO>> GetDtoListByFilterAsync(StayEntryFilterDTO filter, int limit = 0, StayEntryQueryConfig? queryConfig = null);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Somnia.GuestLog.Enums.Models;
|
||||
using Somnia.GuestLog.Models.DTOs;
|
||||
|
||||
namespace Somnia.GuestLog.Services.Entity;
|
||||
@@ -5,7 +6,6 @@ namespace Somnia.GuestLog.Services.Entity;
|
||||
public interface IStayExportFileEntityService
|
||||
{
|
||||
public Task<Result> CreateStayExportAsync(StayExportFileDTO dto);
|
||||
public Task<Result> UpdateStayExportAsync(StayExportFileDTO dto);
|
||||
|
||||
/// <summary>
|
||||
/// Delete StayExport entry from DB.
|
||||
@@ -13,6 +13,15 @@ public interface IStayExportFileEntityService
|
||||
/// </summary>
|
||||
public Task<Result> DeleteStayExportAsync(StayExportFileDTO dto);
|
||||
|
||||
/// <summary>
|
||||
/// Update StayExport FileUploadStatus and execute required operations.
|
||||
/// Only StayExport with UploadStatus "Pending" can be updated.
|
||||
/// </summary>
|
||||
/// <param name="id">ID of the StayExportFile to update</param>
|
||||
/// <param name="newStatus">New UploadStatus</param>
|
||||
public Task<Result> UpdateStayExportUploadStatusAsync(long id, UploadStatus newStatus);
|
||||
|
||||
|
||||
public Task<StayExportFileDTO?> GetDtoByIdAsync(long id);
|
||||
//public Task<IEnumerable<StayExportFileDTO>> GetDtoListByFilterAsync(StayExportFileFilterDTO filter, int limit = 0);
|
||||
public Task<IEnumerable<StayExportFileDTO>> GetDtoListAsync(int limit = 0);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using FluentValidation;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Somnia.GuestLog.Enums.Models;
|
||||
using Somnia.GuestLog.Enums.Services;
|
||||
using Somnia.GuestLog.Infrastructure;
|
||||
using Somnia.GuestLog.Models;
|
||||
@@ -35,6 +36,8 @@ public class StayEntryEntityService(
|
||||
RoomCount = dto.RoomCount!.Value,
|
||||
RoomNumber = dto.RoomNumber,
|
||||
PaymentMethod = dto.PaymentMethod!,
|
||||
StayUploadStatus = UploadStatus.Pending,
|
||||
StayUploadStatusTime = null,
|
||||
CreateTime = createTime,
|
||||
UpdateTime = createTime,
|
||||
};
|
||||
@@ -101,6 +104,11 @@ public class StayEntryEntityService(
|
||||
return Result.Fail(ResultCode.NotFound);
|
||||
}
|
||||
|
||||
if (dbItem.StayUploadStatus == UploadStatus.Uploaded)
|
||||
{
|
||||
return Result.Fail(ResultCode.DataIsFinal);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
dbContext.StayEntries.Remove(dbItem);
|
||||
@@ -116,6 +124,42 @@ public class StayEntryEntityService(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<Result> UpdateEntryUploadStatusAsync(long id, UploadStatus newStatus)
|
||||
{
|
||||
using var dbContext = contextFactory.CreateDbContext();
|
||||
StayEntry? dbItem = await dbContext.StayEntries.FindAsync(id);
|
||||
|
||||
if (dbItem == null)
|
||||
{
|
||||
return Result.Fail(ResultCode.NotFound);
|
||||
}
|
||||
|
||||
if (dbItem.StayUploadStatus == newStatus)
|
||||
{
|
||||
return Result.Fail(ResultCode.NoPendingChanges);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
//Update Status
|
||||
dbItem.StayUploadStatus = newStatus;
|
||||
dbItem.StayUploadStatusTime = DateTime.UtcNow;
|
||||
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
logger.LogInformation("StayEntryService - UpdateEntryUploadStatusAsync: StayEntry ('{id}') UploadStatus updated to '{status}'",
|
||||
dbItem.GetFullKey(), newStatus);
|
||||
return Result.Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "StayEntryService - UpdateEntryUploadStatusAsync: Error updating StayEntry UploadStatus");
|
||||
return Result.FailUnknownError();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<StayEntryDTO?> GetDtoByIdAsync(long id, StayEntryQueryConfig? queryConfig = null)
|
||||
{
|
||||
using var dbContext = contextFactory.CreateDbContext();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using FluentValidation;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Somnia.GuestLog.Enums.Models;
|
||||
using Somnia.GuestLog.Enums.Services;
|
||||
using Somnia.GuestLog.Infrastructure;
|
||||
using Somnia.GuestLog.Models;
|
||||
@@ -38,6 +39,8 @@ public class StayExportFileEntityService(
|
||||
ExportedPath = dto.ExportedPath,
|
||||
ExportDetails = dto.ExportDetails,
|
||||
ExportTime = dto.ExportTime?.ToUniversalTime() ?? DateTime.UtcNow,
|
||||
FileUploadStatus = UploadStatus.Pending,
|
||||
FileUploadStatusTime = null
|
||||
};
|
||||
|
||||
try
|
||||
@@ -58,13 +61,13 @@ public class StayExportFileEntityService(
|
||||
}
|
||||
}
|
||||
|
||||
public Task<Result> UpdateStayExportAsync(StayExportFileDTO dto)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<Result> DeleteStayExportAsync(StayExportFileDTO dto)
|
||||
{
|
||||
if (dto.FileUploadStatus == UploadStatus.Uploaded)
|
||||
{
|
||||
return Result.Fail(ResultCode.DataIsFinal);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using var dbContext = contextFactory.CreateDbContext();
|
||||
@@ -91,6 +94,50 @@ public class StayExportFileEntityService(
|
||||
}
|
||||
|
||||
|
||||
public async Task<Result> UpdateStayExportUploadStatusAsync(long id, UploadStatus newStatus)
|
||||
{
|
||||
//Try get StayExport
|
||||
using var dbContext = contextFactory.CreateDbContext();
|
||||
StayExportFile? dbItem = await dbContext.StayExportFiles
|
||||
.Where(e => e.Id == id)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (dbItem == null)
|
||||
{
|
||||
return Result.Fail(ResultCode.NotFound);
|
||||
}
|
||||
|
||||
if (dbItem.FileUploadStatus == newStatus)
|
||||
{
|
||||
return Result.Fail(ResultCode.NoPendingChanges);
|
||||
}
|
||||
|
||||
//Status can be updated only when current status is "Pending"
|
||||
if (dbItem.FileUploadStatus != UploadStatus.Pending)
|
||||
{
|
||||
return Result.FailWithContext(ResultCode.UploadStatusIsFinal, context: dbItem.FileUploadStatus);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
//Update Status
|
||||
dbItem.FileUploadStatus = newStatus;
|
||||
dbItem.FileUploadStatusTime = DateTime.UtcNow;
|
||||
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
logger.LogInformation("StayExportFileService - UpdateStayExportUploadStatusAsync: StayExport ('{id}') UploadStatus updated to '{status}'",
|
||||
dbItem.GetFullKey(), newStatus);
|
||||
return Result.Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "StayExportFileService - UpdateStayExportUploadStatusAsync: Error updating StayExport UploadStatus");
|
||||
return Result.FailUnknownError();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<StayExportFileDTO?> GetDtoByIdAsync(long id)
|
||||
{
|
||||
using var dbContext = contextFactory.CreateDbContext();
|
||||
|
||||
Reference in new issue
Block a user