2026-04-24 11:14:47 +08:00
|
|
|
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(
|
2026-04-27 11:57:46 +08:00
|
|
|
@RequestParam String appId,
|
|
|
|
|
@AuthenticationPrincipal String userId) {
|
|
|
|
|
return ResponseEntity.ok(ApiResponse.success(groupService.listUserGroups(appId, userId)));
|
2026-04-24 11:14:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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) {}
|
|
|
|
|
}
|