Skip to content

Commit 2e566be

Browse files
committed
Upgrade to ServiceStack with Endpoints
1 parent d3625c6 commit 2e566be

File tree

211 files changed

+18190
-2490
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

211 files changed

+18190
-2490
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
11
using System;
22
using System.Threading.Tasks;
3+
using Microsoft.AspNetCore.Identity;
4+
using Microsoft.Extensions.Configuration;
35
using ServiceStack;
46
using ServiceStack.Configuration;
57
using ServiceStack.OrmLite;
68
using ServiceStack.Script;
9+
using TechStacks.Data;
710
using TechStacks.ServiceInterface.Notifications;
811
using TechStacks.ServiceModel.Types;
912

1013
namespace TechStacks.ServiceInterface.Admin;
1114

15+
[ValidateIsAdmin]
1216
[Route("/email/post/{PostId}")]
13-
public class EmailTest : IReturn<EmailTestRespoonse>
17+
public class EmailTest : IReturn<EmailTestResponse>
1418
{
1519
public int? PostId { get; set; }
1620
}
1721

18-
public class EmailTestRespoonse
22+
public class EmailTestResponse
1923
{
2024
public ResponseStatus ResponseStatus { get; set; }
2125
}
2226

23-
[Authenticate]
24-
[RequiredRole("Admin")]
25-
public class EmailServices : Service
27+
public class EmailServices(EmailProvider email, IConfiguration configuration, UserManager<ApplicationUser> userManager) : Service
2628
{
27-
public EmailProvider Email { get; set; }
28-
29-
public IAppSettings AppSettings { get; set; }
30-
31-
public async Task<EmailTestRespoonse> Any(EmailTest request)
29+
public async Task<EmailTestResponse> Any(EmailTest request)
3230
{
3331
if (request.PostId == null)
3432
throw new ArgumentNullException(nameof(request.PostId));
@@ -43,33 +41,34 @@ public async Task<EmailTestRespoonse> Any(EmailTest request)
4341
var page = context.GetPage("emails/post-new");
4442
var result = new PageResult(page) {
4543
Args = {
46-
["baseUrl"] = AppSettings.GetString("PublicBaseUrl"),
44+
["baseUrl"] = configuration["PublicBaseUrl"],
4745
["post"] = post,
4846
["organization"] = org,
4947
}
5048
};
5149
var html = await result.RenderToStringAsync();
5250

53-
var user = Db.SingleById<CustomUserAuth>(post.UserId);
51+
var user = await userManager.FindByIdAsync($"{post.UserId}")
52+
?? throw HttpError.NotFound($"User {post.UserId} not found");
5453

55-
Email.Send(new EmailMessage {
54+
email.Send(new EmailMessage {
5655
To = new MailTo {
57-
Email = AppSettings.GetString("NotificationsFromEmail"),
56+
Email = configuration["NotificationsFromEmail"],
5857
Name = "Demis"
5958
},
6059
From = new MailTo {
61-
Email = AppSettings.GetString("NotificationsFromEmail"),
60+
Email = configuration["NotificationsFromEmail"],
6261
Name = user.DisplayName ?? user.UserName
6362
},
6463
Cc = new MailTo {
65-
Email = AppSettings.GetString("NotificationsCcEmail"),
64+
Email = configuration["NotificationsCcEmail"],
6665
Name = org.Name + " Subscribed"
6766
},
6867
Subject = $"[{post.Type}] {post.Title}",
6968
BodyHtml = html,
7069
});
7170

72-
return new EmailTestRespoonse();
71+
return new EmailTestResponse();
7372
}
7473

7574
}

TechStacks.ServiceInterface/Admin/ImportServices.cs

-267
This file was deleted.

0 commit comments

Comments
 (0)