diff --git a/backend/IMTest/.gitignore b/backend/IMTest/.gitignore new file mode 100644 index 0000000..3e16852 --- /dev/null +++ b/backend/IMTest/.gitignore @@ -0,0 +1,3 @@ +bin/ +obj/ +.vs/ \ No newline at end of file diff --git a/backend/IMTest/obj/Debug/net8.0/IMTest.AssemblyInfo.cs b/backend/IMTest/obj/Debug/net8.0/IMTest.AssemblyInfo.cs index 392f7ac..9319c84 100644 --- a/backend/IMTest/obj/Debug/net8.0/IMTest.AssemblyInfo.cs +++ b/backend/IMTest/obj/Debug/net8.0/IMTest.AssemblyInfo.cs @@ -14,7 +14,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("IMTest")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+1df3a0f30e469671b3e81d88574871d99c98af1a")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+7ebf23ddd8a0d5536167313c4cf37af1552a5057")] [assembly: System.Reflection.AssemblyProductAttribute("IMTest")] [assembly: System.Reflection.AssemblyTitleAttribute("IMTest")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/backend/IMTest/obj/Debug/net8.0/IMTest.AssemblyInfoInputs.cache b/backend/IMTest/obj/Debug/net8.0/IMTest.AssemblyInfoInputs.cache index 3a83419..8fe6643 100644 --- a/backend/IMTest/obj/Debug/net8.0/IMTest.AssemblyInfoInputs.cache +++ b/backend/IMTest/obj/Debug/net8.0/IMTest.AssemblyInfoInputs.cache @@ -1 +1 @@ -9546071857f1b0fa09bedf887ca476b7ecfa579752230651321c2a145e579c92 +ca0390a4d5773daae2e747d7512c190701a7a942186c769e42327a4864733f0b diff --git a/backend/IMTest/obj/Debug/net8.0/IMTest.csproj.AssemblyReference.cache b/backend/IMTest/obj/Debug/net8.0/IMTest.csproj.AssemblyReference.cache index 0eb737b..c202171 100644 Binary files a/backend/IMTest/obj/Debug/net8.0/IMTest.csproj.AssemblyReference.cache and b/backend/IMTest/obj/Debug/net8.0/IMTest.csproj.AssemblyReference.cache differ diff --git a/backend/IM_API/Application/EventHandlers/FriendAddHandler/FriendAddSignalRHandler.cs b/backend/IM_API/Application/EventHandlers/FriendAddHandler/FriendAddSignalRHandler.cs index 5bf323e..31cb723 100644 --- a/backend/IM_API/Application/EventHandlers/FriendAddHandler/FriendAddSignalRHandler.cs +++ b/backend/IM_API/Application/EventHandlers/FriendAddHandler/FriendAddSignalRHandler.cs @@ -1,4 +1,5 @@ using IM_API.Domain.Events; +using IM_API.Interface.Services; using IM_API.Models; using MassTransit; @@ -6,26 +7,22 @@ namespace IM_API.Application.EventHandlers.FriendAddHandler { public class FriendAddSignalRHandler : IConsumer { - private readonly ImContext _context; - public FriendAddSignalRHandler(ImContext context) + private readonly IFriendSerivce _friendService; + public FriendAddSignalRHandler(IFriendSerivce friendSerivce) { - _context = context; + _friendService = friendSerivce; } - public Task Consume(ConsumeContext context) + public async Task Consume(ConsumeContext context) { - throw new NotImplementedException(); var @event = context.Message; + //为请求发起人添加好友记录 + await _friendService.MakeFriendshipAsync( + @event.RequestUser.Id, @event.ResponseUser.Id, @event.RequestInfo.RemarkName); + //为接收人添加好友记录 + await _friendService.MakeFriendshipAsync( + @event.ResponseUser.Id, @event.RequestUser.Id, @event.requestUserRemarkname); - var RequestfriendShip = new Friend() - { - Avatar = @event.ResponseUser.Avatar, - UserId = @event.RequestUser.Id, - RemarkName = @event.RequestInfo.NickName, - Created = @event.RequestInfo.Created, - - - }; } } } diff --git a/backend/IM_API/Configs/MapperConfig.cs b/backend/IM_API/Configs/MapperConfig.cs index 4475c94..e196430 100644 --- a/backend/IM_API/Configs/MapperConfig.cs +++ b/backend/IM_API/Configs/MapperConfig.cs @@ -28,6 +28,7 @@ namespace IM_API.Configs //好友信息模型转换 CreateMap() .ForMember(dest => dest.UserInfo, opt => opt.MapFrom(src => src.FriendNavigation)) + .ForMember(dest => dest.Avatar, opt => opt.MapFrom(src => src.FriendNavigation.Avatar)) ; //好友请求通过后新增好友关系 CreateMap() diff --git a/backend/IM_API/Domain/Events/FriendAddEvent.cs b/backend/IM_API/Domain/Events/FriendAddEvent.cs index 044ac16..fefce14 100644 --- a/backend/IM_API/Domain/Events/FriendAddEvent.cs +++ b/backend/IM_API/Domain/Events/FriendAddEvent.cs @@ -8,17 +8,18 @@ namespace IM_API.Domain.Events /// /// 发起请求用户 /// - public UserInfoDto RequestUser { get; set; } + public UserInfoDto RequestUser { get; init; } + public string? requestUserRemarkname { get; init; } /// /// 接受请求用户 /// - public UserInfoDto ResponseUser { get; set; } + public UserInfoDto ResponseUser { get; init; } - public FriendRequestResDto RequestInfo { get; set; } + public FriendRequestDto RequestInfo { get; init; } /// /// 好友关系创建时间 /// - public DateTime Created { get; set; } + public DateTime Created { get; init; } } } diff --git a/backend/IM_API/Interface/Services/IFriendSerivce.cs b/backend/IM_API/Interface/Services/IFriendSerivce.cs index 16aa4c5..b4d96a8 100644 --- a/backend/IM_API/Interface/Services/IFriendSerivce.cs +++ b/backend/IM_API/Interface/Services/IFriendSerivce.cs @@ -60,5 +60,12 @@ namespace IM_API.Interface.Services /// 好友关系id /// Task BlockeFriendAsync(int friendId); + /// + /// 创建好友关系 + /// + /// + /// + /// + Task MakeFriendshipAsync(int userAId, int userBId, string? remarkName); } } diff --git a/backend/IM_API/Services/FriendService.cs b/backend/IM_API/Services/FriendService.cs index eae08d8..a372be8 100644 --- a/backend/IM_API/Services/FriendService.cs +++ b/backend/IM_API/Services/FriendService.cs @@ -175,5 +175,28 @@ namespace IM_API.Services return true; } #endregion + + #region 创建好友关系 + public async Task MakeFriendshipAsync(int userAId, int userBId, string? remarkName) + { + bool userAexist = await _context.Friends.AnyAsync(x => x.UserId == userAId && x.FriendId == userBId); + if (!userAexist) + { + User? userbInfo = await _context.Users.FirstOrDefaultAsync(x => x.Id == userBId); + if (userbInfo is null) throw new BaseException(CodeDefine.USER_NOT_FOUND); + Friend friendA = new Friend() + { + Avatar = userbInfo.Avatar, + Created = DateTime.UtcNow, + FriendId = userbInfo.Id, + RemarkName = remarkName ?? userbInfo.NickName, + StatusEnum = FriendStatus.Added, + UserId = userAId + }; + _context.Friends.Add(friendA); + await _context.SaveChangesAsync(); + } + } + #endregion } } diff --git a/docs/测试环境文档.md b/docs/测试环境文档.md new file mode 100644 index 0000000..bfae500 --- /dev/null +++ b/docs/测试环境文档.md @@ -0,0 +1,55 @@ +# 🧪 测试环境自动化构建使用手册 + +本手册用于指导测试人员如何通过 Jenkins 快速部署指定分支的代码,并访问对应的测试地址。 + +--- + +### 1. 环境准备 + +| 平台名称 | 地址 | +| ---------------------- | ------------------------------------------------------------ | +| Jenkins IM前端构建任务 | [Jenkins](http://192.168.5.100:8100/job/IM前端/build?delay=0sec) | +| Jenkins IM后端构建任务 | [IM后端 - Jenkins](http://192.168.5.100:8100/job/IM后端/) | +| 前端分支列表 | https://im.test.nxsir.cn | + +在开始构建前,请确认: + +* 已拥有 **Jenkins 登录权限**。 +* **前置环境wireguard**已启动。 +* 已获取需要测试的 **Git 分支名称**(例如:`feature/order-page`)。 + +--- + +### 2. 构建操作步骤流程 + +1. **登录 Jenkins**:访问 [此处输入你的Jenkins地址] 并登录。 +2. **进入任务**:在项目列表中点击进入对应的测试项目。 +3. **参数化构建**: + * 点击左侧菜单栏的 **Build with Parameters**(带参数构建)。 + * 在 **`BRANCH_NAME`** 输入框中,填入或选择你的 Git 分支名。 +4. **开始构建**:点击下方的 **Build** 按钮。 + +> ⚠️ **提示**:建议直接从代码仓库复制分支名,避免手动输入导致拼写错误。 + +--- + +### 3. 查看构建状态与结果 + +* **观察状态**:在左下角 **Build History** 看到圆形图标变为 **蓝色/绿色**,表示构建成功。 +* **访问网页**: + * 构建成功后,点击该次构建编号(如 `#10`)。 + * 在详情页中点击 **[访问测试环境]** 链接(通常位于页面显著位置)。 + * 或者直接访问:`https://im.test.nxsir.cn/[分支名]` + +--- + +### 4. 常见问题排查 + +| 现象 | 可能原因 | 解决方法 | +| :-------------------------- | :--------------------- | :----------------------------------------------------------- | +| **构建显示红色(Failure)** | 分支名不存在或代码冲突 | 检查分支名是否已推送到远端仓库。 | +| **点击链接显示 404** | 部署尚未完全完成 | 构建完成后通常有几秒延迟,请稍后刷新。 | +| **页面依然显示旧内容** | 浏览器缓存 | 请使用 `Ctrl + F5` (Windows) 或 `Cmd + Shift + R` (Mac) 强制刷新。 | + +--- +**💡 运维备注**:如遇 Jenkins 无法登录或构建按钮置灰,请联系管理员。 \ No newline at end of file diff --git a/frontend/web/.env b/frontend/web/.env index 33374ce..c7dcb08 100644 --- a/frontend/web/.env +++ b/frontend/web/.env @@ -1,4 +1,4 @@ #VITE_API_BASE_URL = http://localhost:5202/api #VITE_SIGNALR_BASE_URL = http://localhost:5202/chat VITE_API_BASE_URL = https://im.test.nxsir.cn/api -VITE_SIGNALR_BASE_URL = https://im.test.nxsir.cn/chat \ No newline at end of file +VITE_SIGNALR_BASE_URL = https://im.test.nxsir.cn/chat/ \ No newline at end of file diff --git a/frontend/web/src/stores/signalr.js b/frontend/web/src/stores/signalr.js index a5a2288..8570905 100644 --- a/frontend/web/src/stores/signalr.js +++ b/frontend/web/src/stores/signalr.js @@ -18,9 +18,11 @@ export const useSignalRStore = defineStore('signalr', { async initSignalR() { const message = useMessage() const authStore = useAuthStore() - const url = import.meta.env.VITE_SIGNALR_BASE_URL || 'http://localhost:5202/chat'; + const url = import.meta.env.VITE_SIGNALR_BASE_URL || 'http://localhost:5202/chat/'; this.connection = new signalR.HubConnectionBuilder() - .withUrl(url, { + .withUrl(url, + { + accessTokenFactory: async () => { if (authStore.isTokenExpired) { const res = await authService.refresh(authStore.refreshToken) @@ -61,8 +63,8 @@ export const useSignalRStore = defineStore('signalr', { }, /** * 通过signalr发送消息 - * @param {*} msg - * @returns + * @param {*} msg + * @returns */ async sendMsg(msg) { const message = useMessage() @@ -97,4 +99,4 @@ export const useSignalRStore = defineStore('signalr', { await this.connection.invoke("ClearUnreadCount", conversationId) } } -}) \ No newline at end of file +})