Skip to content

Commit

Permalink
feat(user): add updateUseremailModel (#220)
Browse files Browse the repository at this point in the history
* feat(user): add updateUseremailModel

* refactor:refactor code

* feat(user):upsertUserModel add roleNames

* refactor:refactor code
  • Loading branch information
wuweilaiya authored Aug 29, 2022
1 parent dd29c77 commit 5f53d23
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Enum;

public enum SendMsgCodeTypes
{
VerifiyPhoneNumber = 1,
UpdatePhoneNumber
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model;

public class SendMsgCodeModel
{
public Guid UserId { get; set; }

public string PhoneNumber { get; set; } = "";

public SendMsgCodeTypes SendMsgCodeType { get; set; } = SendMsgCodeTypes.VerifiyPhoneNumber;

public SendMsgCodeModel()
{
}

public SendMsgCodeModel(Guid userId, string phoneNumber, SendMsgCodeTypes sendMsgCodeType)
{
UserId = userId;
PhoneNumber = phoneNumber;
SendMsgCodeType = sendMsgCodeType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ public class UpdateStaffAvatarModel
{
public Guid UserId { get; set; }

public string Avatar { get; set; }
public string Avatar { get; set; } = "";

public UpdateStaffAvatarModel()
{
}

public UpdateStaffAvatarModel(Guid userId, string avatar)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ public class UpdateUserAvatarModel
{
public Guid Id { get; set; }

public string Avatar { get; set; }
public string Avatar { get; set; } = "";

public UpdateUserAvatarModel()
{
}

public UpdateUserAvatarModel(Guid id, string avatar)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model;

public class UpdateUserEmailModel
{
public Guid Id { get; set; }

public string Email { get; set; } = "";

public UpdateUserEmailModel()
{

}

public UpdateUserEmailModel(Guid id, string email)
{
Id = id;
Email = email;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ public class UpdateUserPhoneNumberModel
{
public Guid Id { get; set; }

public string PhoneNumber { get; set; }
public string PhoneNumber { get; set; } = "";

public string VerificationCode { get; set; }
public string VerificationCode { get; set; } = "";

public UpdateUserPhoneNumberModel()
{
}

public UpdateUserPhoneNumberModel(Guid id, string phoneNumber, string verificationCode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model;
public class UpsertUserModel : AddUserModel
{
public Guid Id { get; set; }

public List<string> RoleNames { get; set; } = new();
}

Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,11 @@ public interface IUserService

Task UpdateStaffAvatarAsync(UpdateStaffAvatarModel staff);

Task SendMsgCodeForVerificationAsync(SendMsgCodeForVerificationModel model);
Task SendMsgCodeAsync(SendMsgCodeModel model);

Task<bool> VerifyMsgCodeAsync(VerifyMsgCodeModel model);

Task SendMsgCodeForUpdatePhoneNumberAsync(SendMsgCodeForUpdatePhoneNumberModel model);

Task UpdatePhoneNumberAsync(UpdateUserPhoneNumberModel user);
Task<bool> UpdatePhoneNumberAsync(UpdateUserPhoneNumberModel user);

Task UpdateBasicInfoAsync(UpdateUserBasicInfoModel user);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,13 @@ public async Task<List<UserSimpleModel>> GetListByAccountAsync(IEnumerable<strin
return await _caller.GetAsync<object, List<UserSimpleModel>>(requestUri, new { accounts = string.Join(',', accounts) }) ?? new();
}

public async Task SendMsgCodeForVerificationAsync(SendMsgCodeForVerificationModel model)
public async Task SendMsgCodeAsync(SendMsgCodeModel model)
{
if (model.UserId == Guid.Empty)
{
model.UserId = _userContext.GetUserId<Guid>();
}
var requestUri = $"api/user/sendMsgCodeForVerification";
var requestUri = $"api/user/sendMsgCode";
await _caller.PostAsync(requestUri, model);
}

Expand All @@ -225,24 +225,14 @@ public async Task<bool> VerifyMsgCodeAsync(VerifyMsgCodeModel model)
return await _caller.PostAsync<bool>(requestUri, model);
}

public async Task SendMsgCodeForUpdatePhoneNumberAsync(SendMsgCodeForUpdatePhoneNumberModel model)
{
if (model.UserId == Guid.Empty)
{
model.UserId = _userContext.GetUserId<Guid>();
}
var requestUri = $"api/user/sendMsgCodeForUpdatePhoneNumber";
await _caller.PostAsync(requestUri, model);
}

public async Task UpdatePhoneNumberAsync(UpdateUserPhoneNumberModel user)
public async Task<bool> UpdatePhoneNumberAsync(UpdateUserPhoneNumberModel user)
{
if (user.Id == Guid.Empty)
{
user.Id = _userContext.GetUserId<Guid>();
}
var requestUri = $"api/user/updateUserPhoneNumber";
await _caller.PutAsync(requestUri, user);
var requestUri = $"api/user/updatePhoneNumber";
return await _caller.PutAsync<bool>(requestUri, user);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,15 @@ public async Task TestUpdateStaffAvatarAsync()
}

[TestMethod]
public async Task TestSendMsgCodeForVerificationAsync()
public async Task SendMsgCodeAsync()
{
var code = new SendMsgCodeForVerificationModel(default);
var requestUri = $"api/user/sendMsgCodeForVerification";
var code = new SendMsgCodeModel();
var requestUri = $"api/user/sendMsgCode";
var caller = new Mock<ICaller>();
caller.Setup(provider => provider.PostAsync(requestUri, code, true, default)).Verifiable();
var userContext = new Mock<IUserContext>();
var userService = new UserService(caller.Object, userContext.Object);
await userService.SendMsgCodeForVerificationAsync(code);
await userService.SendMsgCodeAsync(code);
caller.Verify(provider => provider.PostAsync(requestUri, code, true, default), Times.Once);
}

Expand All @@ -354,30 +354,17 @@ public async Task TestVerifyMsgCodeAsync()
caller.Verify(provider => provider.PostAsync<bool>(requestUri, code, default), Times.Once);
}

[TestMethod]
public async Task TestSendMsgCodeForUpdatePhoneNumberAsync()
{
var code = new SendMsgCodeForUpdatePhoneNumberModel(default, "283417");
var requestUri = $"api/user/sendMsgCodeForUpdatePhoneNumber";
var caller = new Mock<ICaller>();
caller.Setup(provider => provider.PostAsync(requestUri, code, true, default)).Verifiable();
var userContext = new Mock<IUserContext>();
var userService = new UserService(caller.Object, userContext.Object);
await userService.SendMsgCodeForUpdatePhoneNumberAsync(code);
caller.Verify(provider => provider.PostAsync(requestUri, code, true, default), Times.Once);
}

[TestMethod]
public async Task TestUpdateUserPhoneNumberAsync()
{
var user = new UpdateUserPhoneNumberModel(Guid.NewGuid(), "15168440403", "123453");
var requestUri = $"api/user/updateUserPhoneNumber";
var requestUri = $"api/user/updatePhoneNumber";
var caller = new Mock<ICaller>();
caller.Setup(provider => provider.PutAsync(requestUri, user, true, default)).Verifiable();
caller.Setup(provider => provider.PutAsync<bool>(requestUri, user, default)).Verifiable();
var userContext = new Mock<IUserContext>();
var userService = new UserService(caller.Object, userContext.Object);
await userService.UpdatePhoneNumberAsync(user);
caller.Verify(provider => provider.PutAsync(requestUri, user, true, default), Times.Once);
caller.Verify(provider => provider.PutAsync<bool>(requestUri, user, default), Times.Once);
}


Expand Down

0 comments on commit 5f53d23

Please sign in to comment.