Skip to content

Commit

Permalink
wip: adding templates for emails
Browse files Browse the repository at this point in the history
  • Loading branch information
glitchedmob committed Oct 10, 2024
1 parent c40a93c commit 2155856
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Asp.Versioning;
using AutoMapper;
using MethodConf.Cms.Domain;
using MethodConf.Cms.Domain.Errors;
using MethodConf.Cms.Dtos;
using MethodConf.Cms.Services.Interfaces;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -14,15 +16,15 @@ public class ConferenceIssueController(IConferenceIssueService conferenceIssueSe
[HttpPost]
public async Task<ActionResult<CreateIssueResponseDto>> CreateIssue(Guid conferenceId, CreateIssueRequestDto request)
{
await Task.CompletedTask;
return Ok(new CreateIssueResponseDto
var createIssue = mapper.Map<CreateIssue>(request);

var result = await conferenceIssueService.CreateIssue(conferenceId, createIssue);

return result switch
{
Message = request.Message,
Resolution = request.Resolution,
Name = request.Name,
Email = request.Email,
Phone = request.Phone,
ResponseMarkup = """<p>This is some test markup with a <a href="https://google.com">link</a></p>""",
});
{ IsFailed: true } when result.Errors.Any(e => e is InvalidEntityIdError) => NotFound(result.Errors),
{ IsSuccess: true } => Ok(mapper.Map<ConferenceScheduleResponseDto>(result.Value)),
_ => StatusCode(500)
};
}
}
10 changes: 10 additions & 0 deletions backend/src/MethodConf.Cms/Dtos/IssueResponseViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace MethodConf.Cms.Dtos;

public class IssueResponseViewModel
{
public required string Message { get; set; }
public string? Resolution { get; set; }
public string? Name { get; set; }
public string? Email { get; set; }
public string? Phone { get; set; }
}
11 changes: 11 additions & 0 deletions backend/src/MethodConf.Cms/Dtos/NewIssueEmailViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace MethodConf.Cms.Dtos;

public class NewIssueEmailViewModel
{
public string? Title { get; set; }
public required string Message { get; set; }
public string? Resolution { get; set; }
public string? Name { get; set; }
public string? Email { get; set; }
public string? Phone { get; set; }
}
2 changes: 2 additions & 0 deletions backend/src/MethodConf.Cms/Mapping/DefaultProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ public DefaultProfile()
CreateMap<CreateIssueRequestDto, CreateIssue>();
CreateMap<CreateIssue, Issue>();
CreateMap<Issue, CreateIssueResponseDto>();
CreateMap<Issue, NewIssueEmailViewModel>();
CreateMap<Issue, IssueResponseViewModel>();
}
}
1 change: 1 addition & 0 deletions backend/src/MethodConf.Cms/MethodConf.Cms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="RazorLight" Version="2.3.1" />
<PackageReference Include="Umbraco.Cms" Version="14.2.0"/>
<PackageReference Include="Umbraco.Community.DeliveryApiExtensions" Version="14.0.0-beta.1"/>
<PackageReference Include="uSync" Version="14.0.0"/>
Expand Down
40 changes: 39 additions & 1 deletion backend/src/MethodConf.Cms/Services/ConferenceIssueService.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,46 @@
using AutoMapper;
using FluentResults;
using MethodConf.Cms.Domain;
using MethodConf.Cms.Domain.Errors;
using MethodConf.Cms.Infrastructure;
using MethodConf.Cms.Services.Interfaces;
using RazorLight;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Mail;
using Umbraco.Cms.Web.Common.PublishedModels;

namespace MethodConf.Cms.Services;

public class ConferenceIssueService : IConferenceIssueService
public class ConferenceIssueService(
IPublishedContentQuery publishedContentQuery,
AppDbContext dbContext,
IEmailSender emailSender,
IRazorLightEngine razorEngine,
IMapper mapper) : IConferenceIssueService
{
public async Task<Result<Issue>> CreateIssue(Guid conferenceId, CreateIssue createIssue)
{
if (publishedContentQuery.Content(conferenceId) is not Conference conference)
{
return Result.Fail(new InvalidEntityIdError(conferenceId.ToString()));
}

var newIssue = mapper.Map<Issue>(createIssue);
newIssue.ConferenceId = conference.Key;

dbContext.Add(newIssue);
await dbContext.SaveChangesAsync();

return newIssue;
}

private async Task SendOrganizerEmail(Issue issue)
{
var content = razorEngine.

Check failure on line 39 in backend/src/MethodConf.Cms/Services/ConferenceIssueService.cs

View workflow job for this annotation

GitHub Actions / lint-build-test-backend

Identifier expected

Check failure on line 39 in backend/src/MethodConf.Cms/Services/ConferenceIssueService.cs

View workflow job for this annotation

GitHub Actions / lint-build-test-backend

; expected

Check failure on line 39 in backend/src/MethodConf.Cms/Services/ConferenceIssueService.cs

View workflow job for this annotation

GitHub Actions / lint-build-test-backend

Identifier expected

Check failure on line 39 in backend/src/MethodConf.Cms/Services/ConferenceIssueService.cs

View workflow job for this annotation

GitHub Actions / lint-build-test-backend

; expected
}

private async Task SendReporterEmail(Issue issue)
{

}
}
10 changes: 10 additions & 0 deletions backend/src/MethodConf.Cms/Services/DependencyInjection.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
using MethodConf.Cms.Mapping;
using MethodConf.Cms.Services.Interfaces;
using RazorLight;

namespace MethodConf.Cms.Services;

public static class DependencyInjection
{
public static IHostApplicationBuilder AddApplicationServices(this IHostApplicationBuilder builder)
{
builder.Services.AddSingleton<IRazorLightEngine>(_ =>
{
return new RazorLightEngineBuilder()
.UseEmbeddedResourcesProject(typeof(Program))
.SetOperatingAssembly(typeof(Program).Assembly)
.UseMemoryCachingProvider()
.Build();
});

builder.Services.AddScoped<IScheduleGridGenerator, ScheduleGridGenerator>();
builder.Services.AddScoped<IConferenceScheduleService, ConferenceScheduleService>();
builder.Services.AddScoped<ISessionFeedbackService, SessionFeedbackService>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using FluentResults;
using MethodConf.Cms.Domain;

namespace MethodConf.Cms.Services.Interfaces;

public interface IConferenceIssueService
{
public Task<Issue> CreateIssue(Guid conferenceId, CreateIssue createIssue);
public Task<Result<Issue>> CreateIssue(Guid conferenceId, CreateIssue createIssue);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task<Result<SessionFeedback>> Create(Guid sessionId, CreateSessionF
}

var sessionFeedback = mapper.Map<SessionFeedback>(createSessionFeedback);
sessionFeedback.SessionId = sessionId;
sessionFeedback.SessionId = session.Key;

dbContext.SessionFeedback.Add(sessionFeedback);
await dbContext.SaveChangesAsync();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<p>If you added contact information, an organizer will be in touch ASAP.</p>
<p>If you added an email, a copy of your message will be sent to you.</p>
<p>If this is urgent, text or call Levi Zitting <a href="tel:4178080501">417-808-0501</a>. You can also locate another conference organizer or volunteer. who are recognizable by their badges/t-shirts (or as otherwise explained by organizers at the beginning of the conference).</p>
<p>In this is an emergency, please call 911.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@model MethodConf.Cms.Dtos.NewIssueEmailViewModel
@{
Layout = "~/Views/_EmailLayout.cshtml";
}

<p>A new issue for Method Conference has been reported. Here are the details</p>
<p>
<strong>Message:</strong>
<br>
@Model.Message
</p>
<p>
<strong>Resolution:</strong>
<br>
@Model.Resolution
</p>
<p><strong>Name: </strong>@Model.Name</p>
<p><strong>Email: </strong>@Model.Email</p>
<p><strong>Phone: </strong>@Model.Phone</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@model MethodConf.Cms.Dtos.NewIssueEmailViewModel
@{
Layout = "~/Views/_EmailLayout.cshtml";
}

<p>Here's a copy of the issue you reported. An organizer will follow up with you as soon as possible</p>
<p>
<strong>Message:</strong>
<br>
@Model.Message
</p>
<p>
<strong>Resolution:</strong>
<br>
@Model.Resolution
</p>
<p><strong>Name: </strong>@Model.Name</p>
<p><strong>Email: </strong>@Model.Email</p>
<p><strong>Phone: </strong>@Model.Phone</p>
10 changes: 10 additions & 0 deletions backend/src/MethodConf.Cms/Views/_EmailLayout.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>@Model.Title</title>
</head>
<body>
@RenderBody()
</body>
</html>

0 comments on commit 2155856

Please sign in to comment.