diff --git a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs index 61982cc4..da5b2f3f 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs @@ -49,6 +49,11 @@ public interface IBotSharpRepository : IHaveServiceProvider PagedItems 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 diff --git a/src/Infrastructure/BotSharp.Abstraction/Users/IWeChatUserService.cs b/src/Infrastructure/BotSharp.Abstraction/Users/IWeChatUserService.cs new file mode 100644 index 00000000..b25ba73d --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Users/IWeChatUserService.cs @@ -0,0 +1,12 @@ +using BotSharp.Abstraction.Users.Models; + +namespace BotSharp.Abstraction.Users; + +public interface IWeChatUserService +{ + Task GetWeChatUser(string openId); + + Task CreateWeChatUser(WeChatUser weChatUser); + + Task UpdateWeChatUser(WeChatUser weChatUser); +} diff --git a/src/Infrastructure/BotSharp.Core/Users/Services/WeChatUserService.cs b/src/Infrastructure/BotSharp.Core/Users/Services/WeChatUserService.cs new file mode 100644 index 00000000..ab776b28 --- /dev/null +++ b/src/Infrastructure/BotSharp.Core/Users/Services/WeChatUserService.cs @@ -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 GetWeChatUser(string openId) + { + var db = _services.GetRequiredService(); + var weChatUser = db.GetWeChatUser(openId); + return weChatUser; + } + + public async Task CreateWeChatUser(WeChatUser weChatUser) + { + var db = _services.GetRequiredService(); + return db.CreateWeChatUser(weChatUser); + } + + public async Task UpdateWeChatUser(WeChatUser weChatUser) + { + var db = _services.GetRequiredService(); + return db.UpdateWeChatUser(weChatUser); + } +} diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/UserController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/UserController.cs index 9d652a3e..b72888f3 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/UserController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/UserController.cs @@ -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> ActivateUser(UserActivationModel model)