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

Commit 6c04846

Browse files
committed
some design changes.
Events are immutables
1 parent 5f940af commit 6c04846

37 files changed

+359
-196
lines changed

build/docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ services:
3131
CUSTOMCONNSTR_DATABASE_CONNECTION: "server=jpdatabase,port=3306;database=jpproject;user=jp;password=10203040"
3232
ASPNETCORE_ENVIRONMENT: "Development"
3333
ASPNETCORE_URLS: http://+:5000
34+
DEFAULT_USER: bruno
35+
DEFAULT_PASS: Pa$$word123
36+
DEFAULT_EMAIL: [email protected]
3437

3538
# #############################
3639
# # Management API

build/jpproject-docker-windows.zip

45 Bytes
Binary file not shown.

docker-compose.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ services:
3030
depends_on:
3131
- jpdatabase
3232
environment:
33-
DATABASE_TYPE: "SqlServer"
34-
CUSTOMCONNSTR_DATABASE_CONNECTION: "Data Source=tcp:capturadb.database.windows.net,1433;Initial Catalog=homolog_jpproject;User Id=bruno@capturadb.database.windows.net;Password=8BIaspVxw1vOgSIDKdIn;"
33+
DATABASE_TYPE: "MySql"
34+
CUSTOMCONNSTR_DATABASE_CONNECTION: "server=jpdatabase,port=3306;database=jpproject;user=jp;password=10203040"
3535
ASPNETCORE_ENVIRONMENT: "Development"
3636
ASPNETCORE_URLS: http://+:5000
37+
DEFAULT_USER: bruno
38+
DEFAULT_PASS: Pa$$word123
39+
DEFAULT_EMAIL: [email protected]
3740

3841
# #############################
3942
# # Management API
@@ -48,8 +51,8 @@ services:
4851
depends_on:
4952
- jpdatabase
5053
environment:
51-
DATABASE_TYPE: "SqlServer"
52-
CUSTOMCONNSTR_DATABASE_CONNECTION: "Data Source=tcp:capturadb.database.windows.net,1433;Initial Catalog=homolog_jpproject;User Id=bruno@capturadb.database.windows.net;Password=8BIaspVxw1vOgSIDKdIn;"
54+
DATABASE_TYPE: "MySql"
55+
CUSTOMCONNSTR_DATABASE_CONNECTION: "server=jpdatabase,port=3306;database=jpproject;user=jp;password=10203040"
5356
ASPNETCORE_ENVIRONMENT: "Development"
5457
AUTHORITY: "http://jpproject:5000"
5558
ASPNETCORE_URLS: http://+

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public ViewModelToDomainMappingProfile()
4040
*/
4141
CreateMap<UserViewModel, UpdateProfileCommand>().ConstructUsing(c => new UpdateProfileCommand(c.Id, c.Url, c.Bio, c.Company, c.JobTitle, c.Name, c.PhoneNumber));
4242
CreateMap<UserViewModel, UpdateUserCommand>().ConstructUsing(c => new UpdateUserCommand(c.Email, c.UserName, c.Name, c.PhoneNumber, c.EmailConfirmed, c.PhoneNumberConfirmed, c.TwoFactorEnabled, c.LockoutEnd, c.LockoutEnabled, c.AccessFailedCount));
43-
CreateMap<ProfilePictureViewModel, UpdateProfilePictureCommand>().ConstructUsing(c => new UpdateProfilePictureCommand(c.Id));
43+
CreateMap<ProfilePictureViewModel, UpdateProfilePictureCommand>().ConstructUsing(c => new UpdateProfilePictureCommand(c.Id, c.Picture));
4444
CreateMap<ChangePasswordViewModel, ChangePasswordCommand>().ConstructUsing(c => new ChangePasswordCommand(c.Id, c.OldPassword, c.NewPassword, c.ConfirmPassword));
4545
CreateMap<SetPasswordViewModel, SetPasswordCommand>().ConstructUsing(c => new SetPasswordCommand(c.Id, c.NewPassword, c.ConfirmPassword));
4646
CreateMap<RemoveAccountViewModel, RemoveAccountCommand>().ConstructUsing(c => new RemoveAccountCommand(c.Id));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public Task UpdateProfile(UserViewModel model)
5252

5353
public async Task UpdateProfilePicture(ProfilePictureViewModel model)
5454
{
55+
model.Picture = await _imageStorage.SaveAsync(model);
5556
var updateCommand = _mapper.Map<UpdateProfilePictureCommand>(model);
56-
updateCommand.Picture = await _imageStorage.SaveAsync(model);
5757
await Bus.SendCommand(updateCommand);
5858
}
5959

src/Backend/Jp.Application/ViewModels/FileUpload.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.ComponentModel.DataAnnotations;
3+
using Newtonsoft.Json;
34

45
namespace Jp.Application.ViewModels
56
{
@@ -13,5 +14,7 @@ public class ProfilePictureViewModel
1314
public string Value { get; set; }
1415

1516
public Guid? Id { get; set; }
17+
[JsonIgnore]
18+
public string Picture { get; set; }
1619
}
1720
}

src/Backend/Jp.Domain/CommandHandlers/UserCommandHandler.cs

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,14 @@ public async Task<bool> Handle(RegisterNewUserCommand request, CancellationToken
3939
return false;
4040
}
4141

42-
var user = new User()
43-
{
44-
Email = request.Email,
45-
Name = request.Name,
46-
UserName = request.Username,
47-
PhoneNumber = request.PhoneNumber,
48-
Picture = request.Picture
49-
};
50-
42+
var user = new User(
43+
id: Guid.NewGuid(),
44+
email: request.Email,
45+
name: request.Name,
46+
userName: request.Username,
47+
phoneNumber: request.PhoneNumber,
48+
picture: request.Picture
49+
);
5150
var id = await _userService.CreateUserWithPass(user, request.Password);
5251
if (id.HasValue)
5352
{
@@ -65,16 +64,14 @@ public async Task<bool> Handle(RegisterNewUserWithoutPassCommand request, Cancel
6564
return false; ;
6665
}
6766

68-
var user = new User()
69-
{
70-
Id = Guid.NewGuid(),
71-
Email = request.Email,
72-
Name = request.Name,
73-
UserName = request.Username,
74-
PhoneNumber = request.PhoneNumber,
75-
Picture = request.Picture
76-
};
77-
67+
var user = new User(
68+
id: Guid.NewGuid(),
69+
email: request.Email,
70+
name: request.Name,
71+
userName: request.Username,
72+
phoneNumber: request.PhoneNumber,
73+
picture: request.Picture
74+
);
7875
var id = await _userService.CreateUserWithProvider(user, request.Provider, request.ProviderId);
7976
if (id.HasValue)
8077
{
@@ -92,14 +89,14 @@ public async Task<bool> Handle(RegisterNewUserWithProviderCommand request, Cance
9289
return false; ;
9390
}
9491

95-
var user = new User()
96-
{
97-
Email = request.Email,
98-
Name = request.Name,
99-
UserName = request.Username,
100-
PhoneNumber = request.PhoneNumber,
101-
Picture = request.Picture
102-
};
92+
var user = new User(
93+
id: Guid.NewGuid(),
94+
email: request.Email,
95+
name: request.Name,
96+
userName: request.Username,
97+
phoneNumber: request.PhoneNumber,
98+
picture: request.Picture);
99+
103100
var id = await _userService.CreateUserWithProviderAndPass(user, request.Password, request.Provider, request.ProviderId);
104101
if (id.HasValue)
105102
{

src/Backend/Jp.Domain/CommandHandlers/UserManagementCommandHandler.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,7 @@ public async Task<bool> Handle(UpdateUserCommand request, CancellationToken canc
140140
await Bus.RaiseEvent(new DomainNotification("1", "User not found"));
141141
return false;
142142
}
143-
user.Email = request.Email;
144-
user.EmailConfirmed = request.EmailConfirmed;
145-
user.AccessFailedCount = request.AccessFailedCount;
146-
user.LockoutEnabled = request.LockoutEnabled;
147-
user.LockoutEnd = request.LockoutEnd;
148-
user.Name = request.Name;
149-
user.TwoFactorEnabled = request.TwoFactorEnabled;
150-
user.PhoneNumber = request.PhoneNumber;
151-
user.PhoneNumberConfirmed = request.PhoneNumberConfirmed;
143+
user.UpdateInfo(request);
152144
await _userService.UpdateUserAsync(user);
153145

154146
return true;

src/Backend/Jp.Domain/Commands/ApiResource/ApiResourceCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Jp.Domain.Commands.ApiResource
77
{
88
public abstract class ApiResourceCommand : Command
99
{
10-
public IdentityServer4.Models.ApiResource Resource { get; set; }
10+
public IdentityServer4.Models.ApiResource Resource { get; protected set; }
1111

1212

1313
}

src/Backend/Jp.Domain/Commands/Client/ApiScopeCommand.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,38 @@ namespace Jp.Domain.Commands.Client
66
{
77
public abstract class ApiScopeCommand : Command
88
{
9-
public int Id { get; set; }
10-
public string ResourceName { get; set; }
9+
public int Id { get; protected set; }
10+
public string ResourceName { get; protected set; }
1111
/// <summary>
1212
/// Name of the scope. This is the value a client will use to request the scope.
1313
/// </summary>
14-
public string Name { get; set; }
14+
public string Name { get; protected set; }
1515

1616
/// <summary>
1717
/// Display name. This value will be used e.g. on the consent screen.
1818
/// </summary>
19-
public string DisplayName { get; set; }
19+
public string DisplayName { get; protected set; }
2020

2121
/// <summary>
2222
/// Description. This value will be used e.g. on the consent screen.
2323
/// </summary>
24-
public string Description { get; set; }
24+
public string Description { get; protected set; }
2525

2626
/// <summary>
2727
/// Specifies whether the user can de-select the scope on the consent screen. Defaults to false.
2828
/// </summary>
29-
public bool Required { get; set; } = false;
29+
public bool Required { get; protected set; } = false;
3030

3131
/// <summary>
3232
/// Specifies whether the consent screen will emphasize this scope. Use this setting for sensitive or important scopes. Defaults to false.
3333
/// </summary>
34-
public bool Emphasize { get; set; } = false;
34+
public bool Emphasize { get; protected set; } = false;
3535

3636
/// <summary>
3737
/// Specifies whether this scope is shown in the discovery document. Defaults to true.
3838
/// </summary>
39-
public bool ShowInDiscoveryDocument { get; set; } = true;
39+
public bool ShowInDiscoveryDocument { get; protected set; } = true;
4040

41-
public IEnumerable<string> UserClaims { get; set; } = new HashSet<string>();
41+
public IEnumerable<string> UserClaims { get; protected set; } = new HashSet<string>();
4242
}
4343
}

0 commit comments

Comments
 (0)