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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-27 23:41:58 +08:00
|
|
|
@GetMapping("/{groupId}")
|
|
|
|
|
public ResponseEntity<ApiResponse<ImGroupEntity>> get(
|
|
|
|
|
@PathVariable String groupId,
|
|
|
|
|
@AuthenticationPrincipal String userId) {
|
|
|
|
|
return ResponseEntity.ok(ApiResponse.success(groupService.get(groupId, userId)));
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-24 11:14:47 +08:00
|
|
|
@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
|
|
|
}
|
|
|
|
|
|
2026-04-27 23:41:58 +08:00
|
|
|
@PutMapping("/{groupId}")
|
|
|
|
|
public ResponseEntity<ApiResponse<ImGroupEntity>> update(
|
|
|
|
|
@PathVariable String groupId,
|
|
|
|
|
@RequestBody UpdateGroupRequest req,
|
|
|
|
|
@AuthenticationPrincipal String userId) {
|
|
|
|
|
return ResponseEntity.ok(ApiResponse.success(
|
|
|
|
|
groupService.update(groupId, userId, req.name(), req.announcement())));
|
|
|
|
|
}
|
|
|
|
|
|
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) {
|
2026-04-27 23:41:58 +08:00
|
|
|
return ResponseEntity.ok(ApiResponse.success(groupService.addMember(groupId, req.userId(), userId)));
|
2026-04-24 11:14:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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)));
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-27 23:41:58 +08:00
|
|
|
@PostMapping("/{groupId}/roles")
|
|
|
|
|
public ResponseEntity<ApiResponse<ImGroupEntity>> setRole(
|
|
|
|
|
@PathVariable String groupId,
|
|
|
|
|
@RequestBody SetRoleRequest req,
|
|
|
|
|
@AuthenticationPrincipal String userId) {
|
|
|
|
|
return ResponseEntity.ok(ApiResponse.success(
|
|
|
|
|
groupService.setRole(groupId, userId, req.userId(), req.role())));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/{groupId}/mute")
|
|
|
|
|
public ResponseEntity<ApiResponse<ImGroupEntity>> muteMember(
|
|
|
|
|
@PathVariable String groupId,
|
|
|
|
|
@RequestBody MuteMemberRequest req,
|
|
|
|
|
@AuthenticationPrincipal String userId) {
|
|
|
|
|
return ResponseEntity.ok(ApiResponse.success(
|
|
|
|
|
groupService.muteMember(groupId, userId, req.userId(), req.minutes())));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@DeleteMapping("/{groupId}")
|
|
|
|
|
public ResponseEntity<ApiResponse<Void>> dismiss(
|
|
|
|
|
@PathVariable String groupId,
|
|
|
|
|
@AuthenticationPrincipal String userId) {
|
|
|
|
|
groupService.dismiss(groupId, userId);
|
|
|
|
|
return ResponseEntity.ok(ApiResponse.ok());
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-24 11:14:47 +08:00
|
|
|
public record CreateGroupRequest(String name, List<String> memberIds) {}
|
2026-04-27 23:41:58 +08:00
|
|
|
public record UpdateGroupRequest(String name, String announcement) {}
|
2026-04-24 11:14:47 +08:00
|
|
|
public record MemberRequest(String userId) {}
|
2026-04-27 23:41:58 +08:00
|
|
|
public record SetRoleRequest(String userId, String role) {}
|
|
|
|
|
public record MuteMemberRequest(String userId, long minutes) {}
|
2026-04-24 11:14:47 +08:00
|
|
|
}
|