Skip to content

Commit 1e37cb6

Browse files
authored
Merge pull request #91 from Virtual-Finland-Development/feat/analytics-update-events
Analytics update events
2 parents 28a1ec7 + 1e1e52c commit 1e37cb6

63 files changed

Lines changed: 1724 additions & 232 deletions

File tree

Some content is hidden

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

Docs/README.adminfunction.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ dotnet run --project ./VirtualFinland.UsersAPI.AdminFunction.CLI migrate
4242
- `update-terms-of-service`:
4343
- lambda function payload: `{"Action": "UpdateTermsOfService"}`
4444
- cli command: `dotnet run --project ./VirtualFinland.UsersAPI.AdminFunction.CLI update-terms-of-service`
45+
- `update-analytics`:
46+
- lambda function payload: `{"Action": "UpdateAnalytics"}`

VirtualFinland.UserAPI/src/VirtualFinland.UsersAPI/Activities/Identity/Operations/VerifyIdentityPerson.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using MediatR;
22
using Swashbuckle.AspNetCore.Annotations;
3-
using VirtualFinland.UserAPI.Helpers.Extensions;
3+
using VirtualFinland.UserAPI.Helpers;
44
using VirtualFinland.UserAPI.Helpers.Services;
55
using VirtualFinland.UserAPI.Security.Models;
66

@@ -22,18 +22,18 @@ public Query(HttpContext context)
2222
public class Handler : IRequestHandler<Query, User>
2323
{
2424
private readonly AuthenticationService _authenticationService;
25-
private readonly ILogger<Handler> _logger;
25+
private readonly AnalyticsLogger<Handler> _logger;
2626

27-
public Handler(AuthenticationService authenticationService, ILogger<Handler> logger)
27+
public Handler(AuthenticationService authenticationService, AnalyticsLoggerFactory loggerFactory)
2828
{
2929
_authenticationService = authenticationService;
30-
_logger = logger;
30+
_logger = loggerFactory.CreateAnalyticsLogger<Handler>();
3131
}
3232

3333
public async Task<User> Handle(Query request, CancellationToken cancellationToken)
3434
{
3535
var person = await _authenticationService.AuthenticateAndGetOrRegisterAndGetPerson(request.Context, cancellationToken);
36-
_logger.LogAuditLogEvent(AuditLogEvent.Read, "Identity", request.Context.Items["User"] as RequestAuthenticatedUser ?? throw new Exception("Unknown error occurred on verifying identity"));
36+
await _logger.LogAuditLogEvent(AuditLogEvent.Read, request.Context.Items["User"] as RequestAuthenticatedUser ?? throw new Exception("Unknown error occurred on verifying identity"));
3737
return new User(person.Id, person.Created, person.Modified);
3838
}
3939
}

VirtualFinland.UserAPI/src/VirtualFinland.UsersAPI/Activities/Productizer/Operations/BasicInformation/GetPersonBasicInformation.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Swashbuckle.AspNetCore.Annotations;
44
using VirtualFinland.UserAPI.Data;
55
using VirtualFinland.UserAPI.Helpers;
6-
using VirtualFinland.UserAPI.Helpers.Extensions;
6+
using VirtualFinland.UserAPI.Helpers.Services;
77
using VirtualFinland.UserAPI.Security.Models;
88

99
namespace VirtualFinland.UserAPI.Activities.Productizer.Operations.BasicInformation;
@@ -21,19 +21,19 @@ public Query(RequestAuthenticatedUser RequestAuthenticatedUser) : base(RequestAu
2121
public class Handler : IRequestHandler<Query, GetPersonBasicInformationResponse>
2222
{
2323
private readonly UsersDbContext _context;
24-
private readonly ILogger<Handler> _logger;
24+
private readonly AnalyticsLogger<Handler> _logger;
2525

26-
public Handler(UsersDbContext context, ILogger<Handler> logger)
26+
public Handler(UsersDbContext context, AnalyticsLoggerFactory loggerFactory)
2727
{
2828
_context = context;
29-
_logger = logger;
29+
_logger = loggerFactory.CreateAnalyticsLogger<Handler>();
3030
}
3131

3232
public async Task<GetPersonBasicInformationResponse> Handle(Query request, CancellationToken cancellationToken)
3333
{
3434
var person = await _context.Persons.SingleAsync(p => p.Id == request.User.PersonId, cancellationToken);
3535

36-
_logger.LogAuditLogEvent(AuditLogEvent.Read, "Person", request.User);
36+
await _logger.LogAuditLogEvent(AuditLogEvent.Read, request.User);
3737

3838
return new GetPersonBasicInformationResponse(
3939
person.GivenName,

VirtualFinland.UserAPI/src/VirtualFinland.UsersAPI/Activities/Productizer/Operations/BasicInformation/UpdatePersonBasicInformation.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using VirtualFinland.UserAPI.Data;
55
using VirtualFinland.UserAPI.Exceptions;
66
using VirtualFinland.UserAPI.Helpers;
7-
using VirtualFinland.UserAPI.Helpers.Extensions;
7+
using VirtualFinland.UserAPI.Helpers.Services;
88
using VirtualFinland.UserAPI.Security.Models;
99

1010
namespace VirtualFinland.UserAPI.Activities.Productizer.Operations.BasicInformation;
@@ -32,12 +32,12 @@ public Command(string? givenName, string? lastName, string email, string? phoneN
3232
public class Handler : IRequestHandler<Command, UpdatePersonBasicInformationResponse>
3333
{
3434
private readonly UsersDbContext _context;
35-
private readonly ILogger<Handler> _logger;
35+
private readonly AnalyticsLogger<Handler> _logger;
3636

37-
public Handler(UsersDbContext context, ILogger<Handler> logger)
37+
public Handler(UsersDbContext context, AnalyticsLoggerFactory loggerFactory)
3838
{
3939
_context = context;
40-
_logger = logger;
40+
_logger = loggerFactory.CreateAnalyticsLogger<Handler>();
4141
}
4242

4343
public async Task<UpdatePersonBasicInformationResponse> Handle(Command request,
@@ -60,7 +60,7 @@ public async Task<UpdatePersonBasicInformationResponse> Handle(Command request,
6060
throw new BadRequestException(e.InnerException?.Message ?? e.Message);
6161
}
6262

63-
_logger.LogAuditLogEvent(AuditLogEvent.Update, "Person", request.User);
63+
await _logger.LogAuditLogEvent(AuditLogEvent.Update, request.User);
6464

6565
return new UpdatePersonBasicInformationResponse
6666
(

VirtualFinland.UserAPI/src/VirtualFinland.UsersAPI/Activities/Productizer/Operations/JobApplicantProfile/GetJobApplicantProfile.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using Swashbuckle.AspNetCore.Annotations;
55
using VirtualFinland.UserAPI.Data;
66
using VirtualFinland.UserAPI.Helpers;
7-
using VirtualFinland.UserAPI.Helpers.Extensions;
7+
using VirtualFinland.UserAPI.Helpers.Services;
88
using VirtualFinland.UserAPI.Security.Models;
99

1010
namespace VirtualFinland.UserAPI.Activities.Productizer.Operations.JobApplicantProfile;
@@ -21,12 +21,12 @@ public Query(RequestAuthenticatedUser RequestAuthenticatedUser) : base(RequestAu
2121
public class Handler : IRequestHandler<Query, PersonJobApplicantProfileResponse>
2222
{
2323
private readonly UsersDbContext _context;
24-
private readonly ILogger<Handler> _logger;
24+
private readonly AnalyticsLogger<Handler> _logger;
2525

26-
public Handler(UsersDbContext context, ILogger<Handler> logger)
26+
public Handler(UsersDbContext context, AnalyticsLoggerFactory loggerFactory)
2727
{
2828
_context = context;
29-
_logger = logger;
29+
_logger = loggerFactory.CreateAnalyticsLogger<Handler>();
3030
}
3131

3232
public async Task<PersonJobApplicantProfileResponse> Handle(Query request, CancellationToken cancellationToken)
@@ -41,7 +41,7 @@ public async Task<PersonJobApplicantProfileResponse> Handle(Query request, Cance
4141
.Include(p => p.WorkPreferences)
4242
.SingleAsync(p => p.Id == request.User.PersonId, cancellationToken);
4343

44-
_logger.LogAuditLogEvent(AuditLogEvent.Read, "JobApplicantProfile", request.User);
44+
await _logger.LogAuditLogEvent(AuditLogEvent.Read, request.User);
4545

4646
return new PersonJobApplicantProfileResponse
4747
{

VirtualFinland.UserAPI/src/VirtualFinland.UsersAPI/Activities/Productizer/Operations/JobApplicantProfile/UpdateJobApplicantProfile.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using VirtualFinland.UserAPI.Data.Repositories;
88
using VirtualFinland.UserAPI.Exceptions;
99
using VirtualFinland.UserAPI.Helpers;
10+
using VirtualFinland.UserAPI.Helpers.Services;
1011
using VirtualFinland.UserAPI.Helpers.Extensions;
1112
using VirtualFinland.UserAPI.Models.Shared;
1213
using VirtualFinland.UserAPI.Models.UsersDatabase;
@@ -103,14 +104,13 @@ public CommandValidator()
103104
public class Handler : IRequestHandler<Command, Request>
104105
{
105106
private readonly UsersDbContext _context;
106-
private readonly ILogger<Handler> _logger;
107+
private readonly AnalyticsLogger<Handler> _logger;
107108
private readonly IOccupationsFlatRepository _occupationsFlatRepository;
108109

109-
110-
public Handler(UsersDbContext context, ILogger<Handler> logger, IOccupationsFlatRepository occupationsFlatRepository)
110+
public Handler(UsersDbContext context, AnalyticsLoggerFactory loggerFactory, IOccupationsFlatRepository occupationsFlatRepository)
111111
{
112112
_context = context;
113-
_logger = logger;
113+
_logger = loggerFactory.CreateAnalyticsLogger<Handler>();
114114
_occupationsFlatRepository = occupationsFlatRepository;
115115
}
116116

@@ -203,7 +203,7 @@ public async Task<Request> Handle(Command command, CancellationToken cancellatio
203203
throw new BadRequestException(e.InnerException?.Message ?? e.Message);
204204
}
205205

206-
_logger.LogAuditLogEvent(AuditLogEvent.Update, "JobApplicantProfile", command.User);
206+
await _logger.LogAuditLogEvent(AuditLogEvent.Update, command.User);
207207

208208
return new Response
209209
{

VirtualFinland.UserAPI/src/VirtualFinland.UsersAPI/Activities/Productizer/Operations/User/GetUserProfile.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using Swashbuckle.AspNetCore.Annotations;
66
using VirtualFinland.UserAPI.Data;
77
using VirtualFinland.UserAPI.Helpers;
8-
using VirtualFinland.UserAPI.Helpers.Extensions;
8+
using VirtualFinland.UserAPI.Helpers.Services;
99
using VirtualFinland.UserAPI.Models.Shared;
1010
using VirtualFinland.UserAPI.Security.Models;
1111

@@ -32,12 +32,12 @@ public QueryValidator()
3232
public class Handler : IRequestHandler<Query, User>
3333
{
3434
private readonly UsersDbContext _usersDbContext;
35-
private readonly ILogger<Handler> _logger;
35+
private readonly AnalyticsLogger<Handler> _logger;
3636

37-
public Handler(UsersDbContext usersDbContext, ILogger<Handler> logger)
37+
public Handler(UsersDbContext usersDbContext, AnalyticsLoggerFactory loggerFactory)
3838
{
3939
_usersDbContext = usersDbContext;
40-
_logger = logger;
40+
_logger = loggerFactory.CreateAnalyticsLogger<Handler>();
4141
}
4242

4343
public async Task<User> Handle(Query request, CancellationToken cancellationToken)
@@ -79,7 +79,7 @@ public async Task<User> Handle(Query request, CancellationToken cancellationToke
7979
);
8080
}
8181

82-
_logger.LogAuditLogEvent(AuditLogEvent.Read, "Person", request.User);
82+
await _logger.LogAuditLogEvent(AuditLogEvent.Read, request.User);
8383

8484
return new User
8585
{

VirtualFinland.UserAPI/src/VirtualFinland.UsersAPI/Activities/Productizer/Operations/User/UpdateUserProfile.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using VirtualFinland.UserAPI.Data.Repositories;
88
using VirtualFinland.UserAPI.Exceptions;
99
using VirtualFinland.UserAPI.Helpers;
10-
using VirtualFinland.UserAPI.Helpers.Extensions;
10+
using VirtualFinland.UserAPI.Helpers.Services;
1111
using VirtualFinland.UserAPI.Models.Repositories;
1212
using VirtualFinland.UserAPI.Models.UsersDatabase;
1313
using VirtualFinland.UserAPI.Security.Models;
@@ -89,19 +89,19 @@ public CommandValidator()
8989
public class Handler : IRequestHandler<Command, User>
9090
{
9191
private readonly UsersDbContext _usersDbContext;
92-
private readonly ILogger<Handler> _logger;
92+
private readonly AnalyticsLogger<Handler> _logger;
9393
private readonly ILanguageRepository _languageRepository;
9494
private readonly ICountriesRepository _countriesRepository;
9595
private readonly IOccupationsFlatRepository _occupationsFlatRepository;
9696

9797
public Handler(UsersDbContext usersDbContext,
98-
ILogger<Handler> logger,
98+
AnalyticsLoggerFactory loggerFactory,
9999
ILanguageRepository languageRepository,
100100
ICountriesRepository countriesRepository,
101101
IOccupationsFlatRepository occupationsFlatRepository)
102102
{
103103
_usersDbContext = usersDbContext;
104-
_logger = logger;
104+
_logger = loggerFactory.CreateAnalyticsLogger<Handler>();
105105
_languageRepository = languageRepository;
106106
_countriesRepository = countriesRepository;
107107
_occupationsFlatRepository = occupationsFlatRepository;
@@ -120,7 +120,7 @@ public async Task<User> Handle(Command request, CancellationToken cancellationTo
120120

121121
await _usersDbContext.SaveChangesAsync(request.User, cancellationToken);
122122

123-
_logger.LogAuditLogEvent(AuditLogEvent.Update, "Person", request.User);
123+
await _logger.LogAuditLogEvent(AuditLogEvent.Update, request.User);
124124

125125
return new User
126126
{

VirtualFinland.UserAPI/src/VirtualFinland.UsersAPI/Activities/User/Occupations/Operations/AddOccupations.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using Swashbuckle.AspNetCore.Annotations;
55
using VirtualFinland.UserAPI.Data;
66
using VirtualFinland.UserAPI.Helpers;
7-
using VirtualFinland.UserAPI.Helpers.Extensions;
7+
using VirtualFinland.UserAPI.Helpers.Services;
88
using VirtualFinland.UserAPI.Security.Models;
99

1010
namespace VirtualFinland.UserAPI.Activities.User.Occupations.Operations;
@@ -24,12 +24,12 @@ public Command(List<AddOccupationsRequest> occupations)
2424
public class Handler : IRequestHandler<Command, List<AddOccupationsResponse>>
2525
{
2626
private readonly UsersDbContext _usersDbContext;
27-
private readonly ILogger<Handler> _logger;
27+
private readonly AnalyticsLogger<Handler> _logger;
2828

29-
public Handler(UsersDbContext usersDbContext, ILogger<Handler> logger)
29+
public Handler(UsersDbContext usersDbContext, AnalyticsLoggerFactory loggerFactory)
3030
{
3131
_usersDbContext = usersDbContext;
32-
_logger = logger;
32+
_logger = loggerFactory.CreateAnalyticsLogger<Handler>();
3333
}
3434

3535
public async Task<List<AddOccupationsResponse>> Handle(Command request, CancellationToken cancellationToken)
@@ -56,7 +56,7 @@ public async Task<List<AddOccupationsResponse>> Handle(Command request, Cancella
5656
.ToList();
5757

5858
await _usersDbContext.SaveChangesAsync(request.User, cancellationToken);
59-
_logger.LogAuditLogEvent(AuditLogEvent.Update, "Occupations", request.User);
59+
await _logger.LogAuditLogEvent(AuditLogEvent.Update, request.User);
6060

6161
var addedOccupations = new List<AddOccupationsResponse>();
6262
foreach (Models.UsersDatabase.Occupation entry in addedEntries)

VirtualFinland.UserAPI/src/VirtualFinland.UsersAPI/Activities/User/Occupations/Operations/DeleteOccupations.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using MediatR;
22
using VirtualFinland.UserAPI.Data;
33
using VirtualFinland.UserAPI.Helpers;
4-
using VirtualFinland.UserAPI.Helpers.Extensions;
4+
using VirtualFinland.UserAPI.Helpers.Services;
55
using VirtualFinland.UserAPI.Security.Models;
66

77
namespace VirtualFinland.UserAPI.Activities.User.Occupations.Operations;
@@ -25,12 +25,12 @@ public Command(List<Guid> ids)
2525
public class Handler : IRequestHandler<Command>
2626
{
2727
private readonly UsersDbContext _usersDbContext;
28-
private readonly ILogger<Handler> _logger;
28+
private readonly AnalyticsLogger<Handler> _logger;
2929

30-
public Handler(UsersDbContext usersDbContext, ILogger<Handler> logger)
30+
public Handler(UsersDbContext usersDbContext, AnalyticsLoggerFactory loggerFactory)
3131
{
3232
_usersDbContext = usersDbContext;
33-
_logger = logger;
33+
_logger = loggerFactory.CreateAnalyticsLogger<Handler>();
3434
}
3535

3636
public async Task<Unit> Handle(Command request, CancellationToken cancellationToken)
@@ -48,7 +48,7 @@ public async Task<Unit> Handle(Command request, CancellationToken cancellationTo
4848

4949
_usersDbContext.Occupations.RemoveRange(occupationsToRemove);
5050
await _usersDbContext.SaveChangesAsync(request.User, cancellationToken);
51-
_logger.LogAuditLogEvent(AuditLogEvent.Update, "Occupations", request.User);
51+
await _logger.LogAuditLogEvent(AuditLogEvent.Update, request.User);
5252

5353
return Unit.Value;
5454
}

0 commit comments

Comments
 (0)