feat(im-service): 添加群组 HTTP API (GroupController)
- POST /api/im/groups:创建群组(含成员列表)
- GET /api/im/groups:按 appId 列出群组
- POST /api/im/groups/{groupId}/members:添加成员
- DELETE /api/im/groups/{groupId}/members/{targetUserId}:移除成员
ImGroupService 已有实现,仅补充 controller 层
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
这个提交包含在:
父节点
8fe4ae99cc
当前提交
94aa4001d3
@ -0,0 +1,55 @@
|
|||||||
|
package com.xuqm.im.controller;
|
||||||
|
|
||||||
|
import com.xuqm.common.model.ApiResponse;
|
||||||
|
import com.xuqm.im.entity.ImGroupEntity;
|
||||||
|
import com.xuqm.im.service.ImGroupService;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/im/groups")
|
||||||
|
public class GroupController {
|
||||||
|
|
||||||
|
private final ImGroupService groupService;
|
||||||
|
|
||||||
|
public GroupController(ImGroupService groupService) {
|
||||||
|
this.groupService = groupService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public ResponseEntity<ApiResponse<ImGroupEntity>> create(
|
||||||
|
@RequestBody CreateGroupRequest req,
|
||||||
|
@AuthenticationPrincipal String userId,
|
||||||
|
@RequestParam String appId) {
|
||||||
|
return ResponseEntity.ok(ApiResponse.success(
|
||||||
|
groupService.create(appId, req.name(), userId, req.memberIds())));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public ResponseEntity<ApiResponse<List<ImGroupEntity>>> list(
|
||||||
|
@RequestParam String appId) {
|
||||||
|
return ResponseEntity.ok(ApiResponse.success(groupService.listByApp(appId)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/{groupId}/members")
|
||||||
|
public ResponseEntity<ApiResponse<ImGroupEntity>> addMember(
|
||||||
|
@PathVariable String groupId,
|
||||||
|
@RequestBody MemberRequest req,
|
||||||
|
@AuthenticationPrincipal String userId) {
|
||||||
|
return ResponseEntity.ok(ApiResponse.success(groupService.addMember(groupId, req.userId())));
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{groupId}/members/{targetUserId}")
|
||||||
|
public ResponseEntity<ApiResponse<ImGroupEntity>> removeMember(
|
||||||
|
@PathVariable String groupId,
|
||||||
|
@PathVariable String targetUserId,
|
||||||
|
@AuthenticationPrincipal String userId) {
|
||||||
|
return ResponseEntity.ok(ApiResponse.success(groupService.removeMember(groupId, targetUserId, userId)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public record CreateGroupRequest(String name, List<String> memberIds) {}
|
||||||
|
public record MemberRequest(String userId) {}
|
||||||
|
}
|
||||||
正在加载...
在新工单中引用
屏蔽一个用户