Skip to content
This repository was archived by the owner on Aug 1, 2021. It is now read-only.

Commit 91c451b

Browse files
committed
Event Store
1 parent d644eac commit 91c451b

44 files changed

Lines changed: 596 additions & 258 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.

src/Backend/Jp.Application/AutoMapper/DomainToViewModelMappingProfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public DomainToViewModelMappingProfile()
2222
CreateMap<User, UserViewModel>(MemberList.Destination);//.ForMember(x => x.LockoutEnd, opt => opt.MapFrom(src => src.LockoutEnd != null ? src.LockoutEnd.Value.DateTime.ToShortDateString() : string.Empty));
2323
CreateMap<User, UserListViewModel>(MemberList.Destination);
2424

25-
CreateMap<StoredEvent, EventHistoryData>().ConstructUsing(a => new EventHistoryData() { Action = a.Message, Id = a.Id.ToString(), Details = a.Data, When = a.Timestamp.ToString(CultureInfo.InvariantCulture), Who = a.User, Category = a.MessageType });
25+
CreateMap<StoredEvent, EventHistoryData>().ConstructUsing(a => new EventHistoryData(a.Message, a.Id.ToString(), a.Details, a.Timestamp.ToString(CultureInfo.InvariantCulture), a.User, a.MessageType, a.RemoteIpAddress));
2626
CreateMap<Client, ClientListViewModel>(MemberList.Destination);
2727
CreateMap<IdentityServer4.EntityFramework.Entities.Secret, SecretViewModel>(MemberList.Destination);
2828
CreateMap<IdentityServer4.EntityFramework.Entities.ClientProperty, ClientPropertyViewModel>();
Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
namespace Jp.Application.EventSourcedNormalizers
1+
using Jp.Domain.Core.Events;
2+
3+
namespace Jp.Application.EventSourcedNormalizers
24
{
35
public class EventHistoryData
46
{
5-
public string Category { get; set; }
6-
public string Action { get; set; }
7-
public string Id { get; set; }
8-
public string When { get; set; }
9-
public string Who { get; set; }
10-
public string Details { get; set; }
7+
public EventHistoryData(string action, string id, EventDetails details, string when, string who, string category, string ip)
8+
{
9+
Action = action;
10+
Id = id;
11+
When = when;
12+
Who = who;
13+
Category = category;
14+
Ip = ip;
15+
Details = details?.Metadata;
16+
}
17+
18+
public string Category { get; }
19+
public string Ip { get; }
20+
public string Action { get; }
21+
public string Id { get; }
22+
public string When { get; }
23+
public string Who { get; }
24+
public string Details { get; }
1125
}
1226
}

src/Backend/Jp.Application/Interfaces/IUserManageAppService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public interface IUserManageAppService : IDisposable
1717
Task CreatePassword(SetPasswordViewModel model);
1818
Task RemoveAccount(RemoveAccountViewModel model);
1919
Task<bool> HasPassword(Guid userId);
20-
Task<IEnumerable<EventHistoryData>> GetHistoryLogs(string username);
20+
Task<ListOf<EventHistoryData>> GetEvents(string username, PagingViewModel paging);
2121

2222
Task<UserViewModel> GetUserDetails(string username);
2323
Task<UserViewModel> GetUserAsync(Guid value);
@@ -33,6 +33,6 @@ public interface IUserManageAppService : IDisposable
3333
Task RemoveLogin(RemoveUserLoginViewModel model);
3434
Task<IEnumerable<UserListViewModel>> GetUsersInRole(string role);
3535
Task ResetPassword(AdminChangePasswordViewodel model);
36-
Task<ListOfUsersViewModel> GetUsers(PagingViewModel page);
36+
Task<ListOf<UserListViewModel>> GetUsers(PagingViewModel page);
3737
}
3838
}

src/Backend/Jp.Application/Services/UserManagerAppService.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,18 @@ public Task<bool> HasPassword(Guid userId)
8080
return _userService.HasPassword(userId);
8181
}
8282

83-
public async Task<IEnumerable<EventHistoryData>> GetHistoryLogs(string username)
83+
public async Task<ListOf<EventHistoryData>> GetEvents(string username, PagingViewModel paging)
8484
{
85-
var history = await _eventStoreRepository.All(username);
86-
return _mapper.Map<IEnumerable<EventHistoryData>>(history);
85+
var history = await _eventStoreRepository.GetEvents(username, paging);
86+
var total = await _eventStoreRepository.Count(username, paging.Search);
87+
return new ListOf<EventHistoryData>(_mapper.Map<IEnumerable<EventHistoryData>>(history), total);
8788
}
8889

89-
public async Task<ListOfUsersViewModel> GetUsers(PagingViewModel paging)
90+
public async Task<ListOf<UserListViewModel>> GetUsers(PagingViewModel paging)
9091
{
9192
var users = await _userService.GetUsers(paging);
9293
var total = await _userService.Count(paging.Search);
93-
return new ListOfUsersViewModel(_mapper.Map<IEnumerable<UserListViewModel>>(users), total);
94+
return new ListOf<UserListViewModel>(_mapper.Map<IEnumerable<UserListViewModel>>(users), total);
9495
}
9596

9697
public async Task<UserViewModel> GetUserDetails(string username)

src/Backend/Jp.Application/ViewModels/UserViewModels/UserListViewModel.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.ComponentModel.DataAnnotations;
43

54
namespace Jp.Application.ViewModels.UserViewModels
@@ -22,16 +21,4 @@ public class UserListViewModel
2221
public Guid? Id { get; set; }
2322
}
2423

25-
public class ListOfUsersViewModel
26-
{
27-
public ListOfUsersViewModel(IEnumerable<UserListViewModel> collection, int total)
28-
{
29-
Total = total;
30-
Users = collection;
31-
}
32-
33-
public IEnumerable<UserListViewModel> Users { get; set; }
34-
35-
public int Total { get; set; }
36-
}
3724
}

src/Backend/Jp.Domain.Core/Events/Event.cs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,7 @@ public abstract class Event : Message, INotification
1414
public DateTime Timestamp { get; protected set; }
1515

1616
public EventTypes EventType { get; set; }
17-
/// <summary>
18-
/// Gets or sets the local ip address of the current request.
19-
/// </summary>
20-
/// <value>
21-
/// The local ip address.
22-
/// </value>
23-
public string LocalIpAddress { get; set; }
24-
25-
/// <summary>
26-
/// Gets or sets the remote ip address of the current request.
27-
/// </summary>
28-
/// <value>
29-
/// The remote ip address.
30-
/// </value>
31-
public string RemoteIpAddress { get; set; }
32-
17+
3318
/// <summary>
3419
/// Gets or sets the event message.
3520
/// </summary>
@@ -41,7 +26,7 @@ public abstract class Event : Message, INotification
4126
protected Event() { }
4227
protected Event(EventTypes eventType)
4328
{
44-
Timestamp = DateTime.Now;
29+
Timestamp = DateTime.UtcNow;
4530
}
4631
}
4732
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
3+
namespace Jp.Domain.Core.Events
4+
{
5+
public class EventDetails
6+
{
7+
protected EventDetails() { }
8+
public EventDetails(Guid id, string metadata)
9+
{
10+
EventId = id;
11+
Metadata = metadata;
12+
}
13+
14+
public Guid EventId { get; set; }
15+
public string Metadata { get; set; }
16+
public StoredEvent Event { get; set; }
17+
}
18+
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
namespace Jp.Domain.Core.Events
1+
using System.Threading.Tasks;
2+
3+
namespace Jp.Domain.Core.Events
24
{
35
public interface IEventStore
46
{
5-
void Save<T>(T theEvent) where T : Event;
7+
Task Save<T>(T theEvent) where T : Event;
68
}
79
}

src/Backend/Jp.Domain.Core/Events/StoredEvent.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ namespace Jp.Domain.Core.Events
55
public class StoredEvent : Event
66
{
77
public StoredEvent(
8-
string aggregateId,
98
string messageType,
109
EventTypes eventType,
1110
string customMessage,
@@ -14,13 +13,12 @@ public StoredEvent(
1413
string data) : base(eventType)
1514
{
1615
Id = Guid.NewGuid();
17-
AggregateId = aggregateId;
1816
MessageType = messageType;
1917
EventType = eventType;
2018
Message = customMessage;
2119
LocalIpAddress = localIpAddress;
2220
RemoteIpAddress = remoteIpAddress;
23-
Data = data;
21+
Details = new EventDetails(Id, data);
2422
}
2523

2624
public StoredEvent SetUser(string user)
@@ -33,14 +31,36 @@ public StoredEvent SetUser(string user)
3331
protected StoredEvent() { }
3432

3533
public Guid Id { get; private set; }
34+
/// <summary>
35+
/// Gets or sets the local ip address of the current request.
36+
/// </summary>
37+
/// <value>
38+
/// The local ip address.
39+
/// </value>
40+
public string LocalIpAddress { get; set; }
3641

37-
public string Data { get; private set; }
42+
/// <summary>
43+
/// Gets or sets the remote ip address of the current request.
44+
/// </summary>
45+
/// <value>
46+
/// The remote ip address.
47+
/// </value>
48+
public string RemoteIpAddress { get; set; }
3849

3950
public string User { get; private set; }
51+
public EventDetails Details { get; set; }
52+
4053
public StoredEvent ReplaceTimeStamp(in DateTime timeStamp)
4154
{
4255
Timestamp = timeStamp;
4356
return this;
4457
}
58+
59+
public StoredEvent SetAggregate(string aggregateId)
60+
{
61+
AggregateId = aggregateId;
62+
return this;
63+
}
4564
}
65+
4666
}

src/Backend/Jp.Domain.Core/StringUtils/StringExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static bool IsPresent(this string value)
2525
public static string AddSpacesToSentence(this string state)
2626
{
2727
var text = state.ToCharArray();
28-
var chars = new char[text.Length + HowManyCapitalizedChars(text)];
28+
var chars = new char[text.Length + HowManyCapitalizedChars(text)-1];
2929

3030
chars[0] = text[0];
3131
int j = 1;

0 commit comments

Comments
 (0)