package com.custom.webui.controller; import com.custom.webui.dto.req.ChatGroupRequest; import com.custom.webui.dto.resp.ChatGroupDTO; import com.custom.webui.dto.resp.Result; import com.custom.webui.security.CurrentUser; import com.custom.webui.service.ChatGroupService; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; import java.util.Map; /** * 对话分组接口,对应侧边栏「分组」区块里的增删改。 * *
把会话放进去 / 拿出来不在这里,而在
* {@code PUT /api/chats/{id}/group} —— 分组是会话的属性,
* 从会话那一侧改更自然,也避免这个控制器要依赖会话服务。
*/
@RestController
@RequestMapping("/api/chat-groups")
@RequiredArgsConstructor
public class ChatGroupController {
private final ChatGroupService chatGroupService;
/** 当前用户的全部分组 */
@GetMapping
public Result 返回 {@code movedChats}(被移出分组、回到未分组的会话数),
* 让前端能明确告诉用户「分组删了,里面的 3 条对话已回到未分组」——
* 只说「已删除」会让人担心对话是否也一起没了。
*/
@DeleteMapping("/{id}")
public Result> list() {
return Result.success(chatGroupService.listByUser(CurrentUser.requireUserId()));
}
/** 新建分组 */
@PostMapping
public Result