Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,6 @@ FodyWeavers.xsd

appsettings.json
appsettings.*.json
!appsettings.example.json
!appsettings.example.json
# Docker compose override
SnakeAid.dockercompose.yml
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<PackageVersion Include="Serilog.UI" Version="3.2.0" />
<PackageVersion Include="Serilog.UI.SqliteProvider" Version="1.1.0" />
<PackageVersion Include="SQLitePCLRaw.bundle_e_sqlite3" Version="3.0.2" />
<PackageVersion Include="Stateless" Version="5.20.0" />
<PackageVersion Include="VietQRHelper" Version="1.0.2" />
<PackageVersion Include="Scrutor" Version="7.0.0" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="8.1.4" />
Expand All @@ -50,4 +51,4 @@
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="8.0.2" />
<PackageVersion Include="Microsoft.AspNetCore.SignalR" Version="1.2.9" />
</ItemGroup>
</Project>
</Project>
12 changes: 12 additions & 0 deletions SnakeAid.Core/Domains/SnakebiteIncident.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,16 @@ public enum SnakebiteIncidentStatus
Disputed = 6,
Completed = 7
}

public enum SnakebiteIncidentTrigger
{
Pending = 0,
Assigned = 1,
Finished = 2,
Cancelled = 3,
NoRescuerFound = 4,
Paid = 5,
Disputed = 6,
Completed = 7
}
}
13 changes: 13 additions & 0 deletions SnakeAid.Core/StateMachines/IncidentStateMachine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SnakeAid.Core.StateMachines
{
public class IncidentStateMachine
{

}
}
26 changes: 23 additions & 3 deletions SnakeAid.Service/Implements/Email/EmailTemplateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,30 @@ public EmailTemplateService(
_emailProvider = emailProvider;

// Initialize RazorLight engine
// Find template root in source code location, not bin output
// Handle both local development and Docker container paths
var baseDir = AppContext.BaseDirectory;
var projectRoot = Directory.GetParent(baseDir)?.Parent?.Parent?.Parent?.Parent?.FullName;
_templateRoot = Path.Combine(projectRoot!, "SnakeAid.Service", "Implements", "Email", "Templates");
string? projectRoot = null;

// Try to find project root by going up from bin directory (local development)
var currentDir = new DirectoryInfo(baseDir);
while (currentDir != null && projectRoot == null)
{
// Look for solution file or specific project marker
if (Directory.Exists(Path.Combine(currentDir.FullName, "SnakeAid.Service")))
{
projectRoot = currentDir.FullName;
break;
}
currentDir = currentDir.Parent;
}

// If not found (Docker container), use /src path
if (string.IsNullOrEmpty(projectRoot))
{
projectRoot = "/src";
}

_templateRoot = Path.Combine(projectRoot, "SnakeAid.Service", "Implements", "Email", "Templates");

// Create directory if it doesn't exist
if (!Directory.Exists(_templateRoot))
Expand Down
32 changes: 32 additions & 0 deletions SnakeAid.Service/Implements/SnakebiteIncidentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,38 @@ public SnakebiteIncidentService(IUnitOfWork<SnakeAidDbContext> unitOfWork, ILogg
_configuration = configuration;
}

public async Task<ApiResponse<CreateIncidentResponse>> CancelIncidentAsync(Guid incidentId)
{
try
{
return await _unitOfWork.ExecuteInTransactionAsync(async () =>
{
var existingIncident = await _unitOfWork.GetRepository<SnakebiteIncident>().FirstOrDefaultAsync(
predicate: s => s.Id == incidentId
);
if (existingIncident == null)
{
throw new NotFoundException("Snakebite incident not found.");
}
// Validate incident status - only allow cancelling for Pending incidents
if (existingIncident.Status != SnakebiteIncidentStatus.Pending && existingIncident.Status != SnakebiteIncidentStatus.Assigned)
{
throw new BadRequestException($"Cannot cancel incident with status: {existingIncident.Status}");
}
existingIncident.Status = SnakebiteIncidentStatus.Cancelled;
_unitOfWork.GetRepository<SnakebiteIncident>().Update(existingIncident);
await _unitOfWork.CommitAsync();
var responseData = existingIncident.Adapt<CreateIncidentResponse>();
return ApiResponseBuilder.BuildSuccessResponse(responseData, "Snakebite Incident cancelled successfully!");
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Error cancelling snakebite incident: {Message}", ex.Message);
throw;
}
}

public async Task<ApiResponse<CreateIncidentResponse>> CreateIncidentAsync(CreateIncidentRequest request, Guid userId)
{
try
Expand Down
2 changes: 1 addition & 1 deletion SnakeAid.Service/Interfaces/ISnakebiteIncidentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public interface ISnakebiteIncidentService

Task<ApiResponse<UpdateSymptomReportResponse>> UpdateSymptomReportAsync(Guid incidentId, UpdateSymptomReportRequest request);


Task<ApiResponse<CreateIncidentResponse>> CancelIncidentAsync(Guid incidentId);
}
}
1 change: 1 addition & 0 deletions SnakeAid.Service/SnakeAid.Service.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<PackageReference Include="RazorLight" />
<PackageReference Include="Refit" />
<PackageReference Include="Refit.HttpClientFactory" />
<PackageReference Include="Stateless" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" />
<PackageReference Include="VietQRHelper" />
</ItemGroup>
Expand Down