Skip to content

Commit b2cdaf8

Browse files
committed
TD-5477: Change in folder structure
1 parent f2144fe commit b2cdaf8

File tree

17 files changed

+363
-12
lines changed

17 files changed

+363
-12
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,5 @@ obj
5353
/AdminUI/LearningHub.Nhs.AdminUI/LearningHub.Nhs.AdminUI.csproj.user
5454
/WebAPI/LearningHub.Nhs.API/LearningHub.Nhs.Api.csproj.user
5555
/ReportAPI/LearningHub.Nhs.ReportApi/web.config
56+
/MessageQueueing/LearningHub.Nhs.MessageQueueing.Database/LearningHub.Nhs.MessageQueueing.Database.dbmdl
57+
/MessageQueueing/LearningHub.Nhs.MessageQueueing.Database/LearningHub.Nhs.MessageQueueing.Database.jfm

LearningHub.Nhs.WebUI.sln

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LearningHub.Nhs.WebUI.Autom
8383
EndProject
8484
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MessagingService", "MessagingService", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
8585
EndProject
86-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LearningHub.Nhs.MessagingService", "LearningHub.Nhs.MessagingService\LearningHub.Nhs.MessagingService.csproj", "{713B0099-60E3-4D28-980F-448FC68BC7EE}"
86+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MessageQueueing", "MessageQueueing", "{FC592E2B-861F-4C9A-BD1A-95CB97D36285}"
87+
EndProject
88+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LearningHub.Nhs.MessageQueueing", "MessageQueueing\LearningHub.Nhs.MessageQueueing\LearningHub.Nhs.MessageQueueing.csproj", "{534A145F-1FE4-B601-48FF-979744373E4B}"
89+
EndProject
90+
Project("{00D1A9C2-B5F0-4AF3-8072-F6C62B433612}") = "LearningHub.Nhs.MessageQueueing.Database", "MessageQueueing\LearningHub.Nhs.MessageQueueing.Database\LearningHub.Nhs.MessageQueueing.Database.sqlproj", "{AFC1A740-BBA1-44BC-8A52-A65D2E506E69}"
91+
EndProject
92+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LearningHub.Nhs.MessagingService", "MessagingService\LearningHub.Nhs.MessagingService\LearningHub.Nhs.MessagingService.csproj", "{CCB52C7C-47B6-1AE7-7578-7A26B3FFEB71}"
8793
EndProject
8894
Global
8995
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -349,14 +355,34 @@ Global
349355
{A84EC50B-2B01-4819-A2B1-BD867B7595CA}.Release|Any CPU.Build.0 = Release|Any CPU
350356
{A84EC50B-2B01-4819-A2B1-BD867B7595CA}.Release|x64.ActiveCfg = Release|Any CPU
351357
{A84EC50B-2B01-4819-A2B1-BD867B7595CA}.Release|x64.Build.0 = Release|Any CPU
352-
{713B0099-60E3-4D28-980F-448FC68BC7EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
353-
{713B0099-60E3-4D28-980F-448FC68BC7EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
354-
{713B0099-60E3-4D28-980F-448FC68BC7EE}.Debug|x64.ActiveCfg = Debug|Any CPU
355-
{713B0099-60E3-4D28-980F-448FC68BC7EE}.Debug|x64.Build.0 = Debug|Any CPU
356-
{713B0099-60E3-4D28-980F-448FC68BC7EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
357-
{713B0099-60E3-4D28-980F-448FC68BC7EE}.Release|Any CPU.Build.0 = Release|Any CPU
358-
{713B0099-60E3-4D28-980F-448FC68BC7EE}.Release|x64.ActiveCfg = Release|Any CPU
359-
{713B0099-60E3-4D28-980F-448FC68BC7EE}.Release|x64.Build.0 = Release|Any CPU
358+
{534A145F-1FE4-B601-48FF-979744373E4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
359+
{534A145F-1FE4-B601-48FF-979744373E4B}.Debug|Any CPU.Build.0 = Debug|Any CPU
360+
{534A145F-1FE4-B601-48FF-979744373E4B}.Debug|x64.ActiveCfg = Debug|Any CPU
361+
{534A145F-1FE4-B601-48FF-979744373E4B}.Debug|x64.Build.0 = Debug|Any CPU
362+
{534A145F-1FE4-B601-48FF-979744373E4B}.Release|Any CPU.ActiveCfg = Release|Any CPU
363+
{534A145F-1FE4-B601-48FF-979744373E4B}.Release|Any CPU.Build.0 = Release|Any CPU
364+
{534A145F-1FE4-B601-48FF-979744373E4B}.Release|x64.ActiveCfg = Release|Any CPU
365+
{534A145F-1FE4-B601-48FF-979744373E4B}.Release|x64.Build.0 = Release|Any CPU
366+
{AFC1A740-BBA1-44BC-8A52-A65D2E506E69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
367+
{AFC1A740-BBA1-44BC-8A52-A65D2E506E69}.Debug|Any CPU.Build.0 = Debug|Any CPU
368+
{AFC1A740-BBA1-44BC-8A52-A65D2E506E69}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
369+
{AFC1A740-BBA1-44BC-8A52-A65D2E506E69}.Debug|x64.ActiveCfg = Debug|Any CPU
370+
{AFC1A740-BBA1-44BC-8A52-A65D2E506E69}.Debug|x64.Build.0 = Debug|Any CPU
371+
{AFC1A740-BBA1-44BC-8A52-A65D2E506E69}.Debug|x64.Deploy.0 = Debug|Any CPU
372+
{AFC1A740-BBA1-44BC-8A52-A65D2E506E69}.Release|Any CPU.ActiveCfg = Release|Any CPU
373+
{AFC1A740-BBA1-44BC-8A52-A65D2E506E69}.Release|Any CPU.Build.0 = Release|Any CPU
374+
{AFC1A740-BBA1-44BC-8A52-A65D2E506E69}.Release|Any CPU.Deploy.0 = Release|Any CPU
375+
{AFC1A740-BBA1-44BC-8A52-A65D2E506E69}.Release|x64.ActiveCfg = Release|Any CPU
376+
{AFC1A740-BBA1-44BC-8A52-A65D2E506E69}.Release|x64.Build.0 = Release|Any CPU
377+
{AFC1A740-BBA1-44BC-8A52-A65D2E506E69}.Release|x64.Deploy.0 = Release|Any CPU
378+
{CCB52C7C-47B6-1AE7-7578-7A26B3FFEB71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
379+
{CCB52C7C-47B6-1AE7-7578-7A26B3FFEB71}.Debug|Any CPU.Build.0 = Debug|Any CPU
380+
{CCB52C7C-47B6-1AE7-7578-7A26B3FFEB71}.Debug|x64.ActiveCfg = Debug|Any CPU
381+
{CCB52C7C-47B6-1AE7-7578-7A26B3FFEB71}.Debug|x64.Build.0 = Debug|Any CPU
382+
{CCB52C7C-47B6-1AE7-7578-7A26B3FFEB71}.Release|Any CPU.ActiveCfg = Release|Any CPU
383+
{CCB52C7C-47B6-1AE7-7578-7A26B3FFEB71}.Release|Any CPU.Build.0 = Release|Any CPU
384+
{CCB52C7C-47B6-1AE7-7578-7A26B3FFEB71}.Release|x64.ActiveCfg = Release|Any CPU
385+
{CCB52C7C-47B6-1AE7-7578-7A26B3FFEB71}.Release|x64.Build.0 = Release|Any CPU
360386
EndGlobalSection
361387
GlobalSection(SolutionProperties) = preSolution
362388
HideSolutionNode = FALSE
@@ -392,7 +418,9 @@ Global
392418
{E585A74A-F358-4446-B10E-0FF07B4FF601} = {A4209011-1740-4902-B889-2F2FAF98383F}
393419
{AAC8306E-1DEB-460D-84C7-40166D189B88} = {A4209011-1740-4902-B889-2F2FAF98383F}
394420
{6167F037-166C-4C5A-81BE-55618E77D4E8} = {A4209011-1740-4902-B889-2F2FAF98383F}
395-
{713B0099-60E3-4D28-980F-448FC68BC7EE} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
421+
{534A145F-1FE4-B601-48FF-979744373E4B} = {FC592E2B-861F-4C9A-BD1A-95CB97D36285}
422+
{AFC1A740-BBA1-44BC-8A52-A65D2E506E69} = {FC592E2B-861F-4C9A-BD1A-95CB97D36285}
423+
{CCB52C7C-47B6-1AE7-7578-7A26B3FFEB71} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
396424
EndGlobalSection
397425
GlobalSection(ExtensibilityGlobals) = postSolution
398426
SolutionGuid = {1ECA38C8-7C69-4DE6-8293-852C603F4217}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<Name>LearningHub.Nhs.MessageQueueing.Database</Name>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectVersion>4.1</ProjectVersion>
9+
<ProjectGuid>{afc1a740-bba1-44bc-8a52-a65d2e506e69}</ProjectGuid>
10+
<DSP>Microsoft.Data.Tools.Schema.Sql.Sql160DatabaseSchemaProvider</DSP>
11+
<OutputType>Database</OutputType>
12+
<RootPath>
13+
</RootPath>
14+
<RootNamespace>LearningHub.Nhs.MessageQueueing.Database</RootNamespace>
15+
<AssemblyName>LearningHub.Nhs.MessageQueueing.Database</AssemblyName>
16+
<ModelCollation>1033, CI</ModelCollation>
17+
<DefaultFileStructure>BySchemaAndSchemaType</DefaultFileStructure>
18+
<DeployToDatabase>True</DeployToDatabase>
19+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
20+
<TargetLanguage>CS</TargetLanguage>
21+
<AppDesignerFolder>Properties</AppDesignerFolder>
22+
<SqlServerVerification>False</SqlServerVerification>
23+
<IncludeCompositeObjects>True</IncludeCompositeObjects>
24+
<TargetDatabaseSet>True</TargetDatabaseSet>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<OutputPath>bin\Release\</OutputPath>
28+
<BuildScriptName>$(MSBuildProjectName).sql</BuildScriptName>
29+
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>true</Optimize>
32+
<DefineDebug>false</DefineDebug>
33+
<DefineTrace>true</DefineTrace>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
38+
<OutputPath>bin\Debug\</OutputPath>
39+
<BuildScriptName>$(MSBuildProjectName).sql</BuildScriptName>
40+
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
41+
<DebugSymbols>true</DebugSymbols>
42+
<DebugType>full</DebugType>
43+
<Optimize>false</Optimize>
44+
<DefineDebug>true</DefineDebug>
45+
<DefineTrace>true</DefineTrace>
46+
<ErrorReport>prompt</ErrorReport>
47+
<WarningLevel>4</WarningLevel>
48+
</PropertyGroup>
49+
<PropertyGroup>
50+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">11.0</VisualStudioVersion>
51+
<!-- Default to the v11.0 targets path if the targets file for the current VS version is not found -->
52+
<SSDTExists Condition="Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets')">True</SSDTExists>
53+
<VisualStudioVersion Condition="'$(SSDTExists)' == ''">11.0</VisualStudioVersion>
54+
</PropertyGroup>
55+
<Import Condition="'$(SQLDBExtensionsRefPath)' != ''" Project="$(SQLDBExtensionsRefPath)\Microsoft.Data.Tools.Schema.SqlTasks.targets" />
56+
<Import Condition="'$(SQLDBExtensionsRefPath)' == ''" Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" />
57+
<ItemGroup>
58+
<Folder Include="Properties" />
59+
<Folder Include="Tables" />
60+
</ItemGroup>
61+
</Project>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
</Project>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
namespace LearningHub.Nhs.MessageQueueing.Entities
2+
{
3+
using System;
4+
using System.ComponentModel.DataAnnotations;
5+
6+
/// <summary>
7+
/// The Email Queue.
8+
/// </summary>
9+
public class EmailQueue
10+
{
11+
/// <summary>
12+
/// Gets or sets the id.
13+
/// </summary>
14+
[Key]
15+
public Guid Id { get; set; }
16+
17+
/// <summary>
18+
/// Gets or sets the Recipient.
19+
/// </summary>
20+
public string Recipient { get; set; }
21+
22+
/// <summary>
23+
/// Gets or sets the Subject.
24+
/// </summary>
25+
public string Subject { get; set; }
26+
27+
/// <summary>
28+
/// Gets or sets the Body.
29+
/// </summary>
30+
public string? Body { get; set; }
31+
32+
/// <summary>
33+
/// Gets or sets the TemplateId.
34+
/// </summary>
35+
public string TemplateId { get; set; }
36+
37+
/// <summary>
38+
/// Gets or sets the Personalisation.
39+
/// </summary>
40+
public string? Personalisation { get; set; }
41+
42+
/// <summary>
43+
/// Gets or sets the Status.
44+
/// </summary>
45+
public string Status { get; set; }
46+
47+
/// <summary>
48+
/// Gets or sets the NotificationId.
49+
/// </summary>
50+
public string? NotificationId { get; set; }
51+
52+
/// <summary>
53+
/// Gets or sets the RetryCount.
54+
/// </summary>
55+
public int RetryCount { get; set; }
56+
57+
/// <summary>
58+
/// Gets or sets the CreatedAt.
59+
/// </summary>
60+
public DateTimeOffset CreatedAt { get; set; }
61+
62+
/// <summary>
63+
/// Gets or sets the DeliverAfter.
64+
/// </summary>
65+
public DateTimeOffset? DeliverAfter { get; set; }
66+
67+
/// <summary>
68+
/// Gets or sets the SentAt.
69+
/// </summary>
70+
public DateTimeOffset? SentAt { get; set; }
71+
72+
/// <summary>
73+
/// Gets or sets the LastAttemptAt.
74+
/// </summary>
75+
public DateTimeOffset? LastAttemptAt { get; set; }
76+
77+
/// <summary>
78+
/// Gets or sets the ErrorMessage.
79+
/// </summary>
80+
public string? ErrorMessage { get; set; }
81+
}
82+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
namespace LearningHub.Nhs.MessageQueueing.EntityFramework
2+
{
3+
using LearningHub.Nhs.MessageQueueing.Entities;
4+
using Microsoft.EntityFrameworkCore;
5+
6+
/// <summary>
7+
/// The Message Queue Db Context.
8+
/// </summary>
9+
public class MessageQueueDbContext : DbContext
10+
{
11+
/// <summary>
12+
/// Initializes a new instance of the <see cref="MessageQueueDbContext"/> class.
13+
/// </summary>
14+
/// <param name="options">The options.</param>
15+
public MessageQueueDbContext(DbContextOptions<MessageQueueDbContext> options)
16+
: base(options)
17+
{
18+
}
19+
20+
/// <summary>
21+
/// Gets or sets the EmailQueues.
22+
/// </summary>
23+
public virtual DbSet<EmailQueue> EmailQueues { get; set; }
24+
}
25+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.20" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
namespace LearningHub.Nhs.MessageQueueing.Repositories
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using LearningHub.Nhs.MessageQueueing.Entities;
8+
using LearningHub.Nhs.MessageQueueing.EntityFramework;
9+
using Microsoft.EntityFrameworkCore;
10+
11+
/// <summary>
12+
/// The EmailQueueRepository.
13+
/// </summary>
14+
public class EmailQueueRepository : IEmailQueueRepository
15+
{
16+
private readonly MessageQueueDbContext dbContext;
17+
18+
/// <summary>
19+
/// Initializes a new instance of the <see cref="EmailQueueRepository"/> class.
20+
/// </summary>
21+
/// <param name="dbContext">The context.</param>
22+
public EmailQueueRepository(MessageQueueDbContext dbContext)
23+
{
24+
this.dbContext = dbContext;
25+
}
26+
27+
/// <summary>
28+
/// The QueueEmailsAsync.
29+
/// </summary>
30+
/// <param name="emails">The emails.</param>
31+
/// <returns>The <see cref="Task"/>.</returns>
32+
public async Task QueueEmailsAsync(IEnumerable<EmailQueue> emails)
33+
{
34+
await this.dbContext.EmailQueues.AddRangeAsync(emails);
35+
await this.dbContext.SaveChangesAsync();
36+
}
37+
38+
/// <summary>
39+
/// The GetPendingEmailsAsync.
40+
/// </summary>
41+
/// <returns>The <see cref="Task"/>.</returns>
42+
public async Task<IEnumerable<EmailQueue>> GetPendingEmailsAsync()
43+
{
44+
return await this.dbContext.EmailQueues
45+
.Where(e => e.Status == "Pending" && e.RetryCount < 3)
46+
.OrderBy(e => e.CreatedAt)
47+
.ToListAsync();
48+
}
49+
50+
/// <summary>
51+
/// The UpdateEmailStatusAsync.
52+
/// </summary>
53+
/// <param name="id">The Id.</param>
54+
/// <param name="status">The status.</param>
55+
/// <param name="errorMessage">The error message.</param>
56+
/// <returns>The <see cref="Task"/>.</returns>
57+
public async Task UpdateEmailStatusAsync(Guid id, string status, string errorMessage = null)
58+
{
59+
var email = await this.dbContext.EmailQueues.FindAsync(id);
60+
if (email != null)
61+
{
62+
email.Status = status;
63+
email.ErrorMessage = errorMessage;
64+
email.SentAt = status == "Sent" ? DateTime.UtcNow : null;
65+
66+
await this.dbContext.SaveChangesAsync();
67+
}
68+
}
69+
70+
/// <summary>
71+
/// The IncrementRetryAsync.
72+
/// </summary>
73+
/// <param name="id">The id.</param>
74+
/// <param name="errorMessage">The errorMessage.</param>
75+
/// <returns>The <see cref="Task"/>.</returns>
76+
public async Task IncrementRetryAsync(Guid id, string errorMessage)
77+
{
78+
var email = await this.dbContext.EmailQueues.FindAsync(id);
79+
if (email != null)
80+
{
81+
email.RetryCount++;
82+
email.LastAttemptAt = DateTime.UtcNow;
83+
email.ErrorMessage = errorMessage;
84+
85+
if (email.RetryCount >= 3)
86+
{
87+
email.Status = "Failed";
88+
}
89+
90+
await this.dbContext.SaveChangesAsync();
91+
}
92+
}
93+
}
94+
}

0 commit comments

Comments
 (0)