feat: Add Create WeChat User Interface API
This commit is contained in:
parent
541b7893da
commit
d11e91ca84
|
|
@ -49,6 +49,11 @@ public interface IBotSharpRepository : IHaveServiceProvider
|
|||
PagedItems<User> GetUsers(UserFilter filter) => throw new NotImplementedException();
|
||||
User? GetUserDetails(string userId, bool includeAgent = false) => throw new NotImplementedException();
|
||||
bool UpdateUser(User user, bool updateUserAgents = false) => throw new NotImplementedException();
|
||||
|
||||
WeChatUser? GetWeChatUser(string openId) => throw new NotImplementedException();
|
||||
WeChatUser? CreateWeChatUser(WeChatUser weChatUser) => throw new NotImplementedException();
|
||||
WeChatUser? UpdateWeChatUser(WeChatUser weChatUser) => throw new NotImplementedException();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Agent
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
using BotSharp.Abstraction.Users.Models;
|
||||
|
||||
namespace BotSharp.Abstraction.Users;
|
||||
|
||||
public interface IWeChatUserService
|
||||
{
|
||||
Task<WeChatUser?> GetWeChatUser(string openId);
|
||||
|
||||
Task<WeChatUser?> CreateWeChatUser(WeChatUser weChatUser);
|
||||
|
||||
Task<WeChatUser?> UpdateWeChatUser(WeChatUser weChatUser);
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
using BotSharp.Abstraction.Users.Models;
|
||||
|
||||
namespace BotSharp.Core.Users.Services;
|
||||
|
||||
public class WeChatUserService : IWeChatUserService
|
||||
{
|
||||
private readonly IServiceProvider _services;
|
||||
public WeChatUserService(IServiceProvider services)
|
||||
{
|
||||
_services = services;
|
||||
}
|
||||
|
||||
public async Task<WeChatUser?> GetWeChatUser(string openId)
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var weChatUser = db.GetWeChatUser(openId);
|
||||
return weChatUser;
|
||||
}
|
||||
|
||||
public async Task<WeChatUser?> CreateWeChatUser(WeChatUser weChatUser)
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
return db.CreateWeChatUser(weChatUser);
|
||||
}
|
||||
|
||||
public async Task<WeChatUser?> UpdateWeChatUser(WeChatUser weChatUser)
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
return db.UpdateWeChatUser(weChatUser);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
using BotSharp.Abstraction.Users.Enums;
|
||||
using BotSharp.Abstraction.Users.Settings;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
|
|
@ -14,17 +13,20 @@ public class UserController : ControllerBase
|
|||
private readonly IUserService _userService;
|
||||
private readonly IUserIdentity _user;
|
||||
private readonly AccountSetting _setting;
|
||||
private readonly IWeChatUserService _weChatUserService;
|
||||
|
||||
public UserController(
|
||||
IUserService userService,
|
||||
IServiceProvider services,
|
||||
IUserIdentity user,
|
||||
AccountSetting setting)
|
||||
AccountSetting setting,
|
||||
IWeChatUserService weChatUserService)
|
||||
{
|
||||
_services = services;
|
||||
_userService = userService;
|
||||
_user = user;
|
||||
_setting = setting;
|
||||
_weChatUserService = weChatUserService;
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
|
|
@ -72,6 +74,16 @@ public class UserController : ControllerBase
|
|||
return UserViewModel.FromUser(createdUser);
|
||||
}
|
||||
|
||||
[HttpPost("/user/wechat")]
|
||||
public async Task CreateWeChatUser(string code)
|
||||
{
|
||||
// Get WeChat User Info
|
||||
|
||||
|
||||
WeChatUser wechatUser = new();
|
||||
var user = await _weChatUserService.CreateWeChatUser(wechatUser);
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost("/user/activate")]
|
||||
public async Task<ActionResult<Token>> ActivateUser(UserActivationModel model)
|
||||
|
|
|
|||
Loading…
Reference in a new issue