Skip to content

Commit

Permalink
Switch User MarkAsRead to use Jobs.UserId
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Aug 21, 2024
1 parent 343872c commit b9c2431
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion MyApp.ServiceInterface/App/MarkAsReadCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class MarkAsReadCommand(AppConfig appConfig, IDbConnection db) : SyncComm
{
protected override void Run(MarkAsRead request)
{
var userName = request.UserName;
var userName = Request.GetClaimsPrincipal().GetRequiredUserName();
if (request.AllNotifications == true)
{
db.UpdateOnly(() => new Notification { Read = true }, x => x.UserName == userName);
Expand Down
9 changes: 4 additions & 5 deletions MyApp.ServiceInterface/UserServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,11 @@ FROM Achievement A LEFT JOIN Post P on (A.PostId = P.Id)
};
}

public async Task<object> Any(MarkAsRead request)
public object Any(MarkAsRead request)
{
request.UserName = Request.GetClaimsPrincipal().GetUserName()
?? throw new ArgumentNullException(nameof(MarkAsRead.UserName));

jobs.RunCommand<MarkAsReadCommand>(request);
jobs.RunCommand<MarkAsReadCommand>(request, new() {
UserId = Request.GetClaimsPrincipal().GetUserId()
});
return new EmptyResponse();
}

Expand Down
2 changes: 0 additions & 2 deletions MyApp.ServiceModel/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ public class GetLatestAchievementsResponse
[ValidateIsAuthenticated]
public class MarkAsRead : IPost, IReturn<EmptyResponse>
{
[IgnoreDataMember]
public string UserName { get; set; }
public List<int>? NotificationIds { get; set; }
public bool? AllNotifications { get; set; }
public List<int>? AchievementIds { get; set; }
Expand Down
5 changes: 2 additions & 3 deletions MyApp/Configure.Auth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ namespace MyApp;
public class ConfigureAuth : IHostingStartup
{
public void Configure(IWebHostBuilder builder) => builder
.ConfigureAppHost(appHost =>
{
appHost.Plugins.Add(new AuthFeature(IdentityAuth.For<ApplicationUser>(options => {
.ConfigureServices(services => {
services.AddPlugin(new AuthFeature(IdentityAuth.For<ApplicationUser>(options => {
options.SessionFactory = () => new CustomUserSession();
options.CredentialsAuth();
options.AdminUsersFeature(feature =>
Expand Down
1 change: 0 additions & 1 deletion MyApp/Configure.BackgroundJobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public void Configure(IWebHostBuilder builder) => builder
});
jobs.RecurringCommand<SendWatchedTagEmailsCommand>(Schedule.Hourly);
});
}

Expand Down

0 comments on commit b9c2431

Please sign in to comment.