用户

Change-Id: I33150cf6ffdea3bf582023bf540394075d081af9
diff --git a/src/main/java/com/example/myproject/controller/GroupController.java b/src/main/java/com/example/myproject/controller/GroupController.java
new file mode 100644
index 0000000..a0830b6
--- /dev/null
+++ b/src/main/java/com/example/myproject/controller/GroupController.java
@@ -0,0 +1,105 @@
+package com.example.myproject.controller;
+
+import com.example.myproject.entity.Group;
+import com.example.myproject.entity.GroupComments;
+import com.example.myproject.service.GroupService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/echo/groups")
+public class GroupController {
+
+    @Autowired
+    private GroupService groupService;
+
+    @PostMapping("/createGroup")
+    public ResponseEntity<Map<String, Object>> createGroup(@RequestBody Group groupRequest) {
+        // 调用服务层方法创建小组
+        System.out.println("Received group name: " + groupRequest.getGroupName());
+        return groupService.createGroup(groupRequest);
+    }
+
+
+    // 加入小组接口
+    @PostMapping("/{group_id}/join")
+    public ResponseEntity<Map<String, Object>> joinGroup(@PathVariable("group_id") Long groupId,
+                                                         @RequestBody Map<String, Long> requestBody) {
+        Long userId = requestBody.get("user_id");
+        return groupService.joinGroup(groupId, userId);
+    }
+
+    // 退出小组接口
+    @PostMapping("/{group_id}/leave")
+    public ResponseEntity<Map<String, Object>> leaveGroup(@PathVariable("group_id") Long groupId,
+                                                          @RequestBody Map<String, Long> requestBody) {
+        Long userId = requestBody.get("user_id");
+        return groupService.leaveGroup(groupId, userId);
+    }
+
+    // 获取小组成员接口
+    @GetMapping("/{group_id}/members")
+    public ResponseEntity<Map<String, Object>> getGroupMembers(@PathVariable("group_id") Long groupId) {
+        return groupService.getGroupMembers(groupId);
+    }
+
+    //发布帖子
+    @PostMapping("/{group_id}/createPost")
+    public ResponseEntity<Map<String, Object>> createPost(
+            @PathVariable("group_id") Long groupId,
+            @RequestParam("user_id") Long userId,
+            @RequestParam("content") String content,
+            @RequestParam("title") String title,
+            @RequestParam(value = "images", required = false) MultipartFile[] imageFiles) {
+
+        Map<String, Object> response = groupService.createPost(groupId, userId, content, title, imageFiles);
+        return ResponseEntity.ok(response);
+    }
+
+    //获取某个小组内的所有帖子
+    @GetMapping("/{group_id}/getAllPosts")
+    public ResponseEntity<Map<String, Object>> getAllPosts(@PathVariable("group_id") Long groupId) {
+        Map<String, Object> response = groupService.getAllPosts(groupId);
+        return ResponseEntity.ok(response);
+    }
+
+    //获取所有小组名称
+    @PostMapping("/getAllGroups")
+    public ResponseEntity<Map<String, Object>> searchGroups(@RequestBody Map<String, Object> params) {
+        Map<String, Object> response = groupService.searchGroups(params);
+        return ResponseEntity.ok(response);
+    }
+
+    // 点赞帖子
+    @PostMapping("/{group_post_id}/like")
+    public ResponseEntity<Map<String, Object>> likePost(
+            @PathVariable("group_post_id") Long groupPostId) {
+        Map<String, Object> response = groupService.likePost(groupPostId);
+        return ResponseEntity.ok(response);
+    }
+
+    // 取消点赞
+    @PostMapping("/{group_post_id}/unlike")
+    public ResponseEntity<Map<String, Object>> unlikePost(
+            @PathVariable("group_post_id") Long groupPostId) {
+        Map<String, Object> response = groupService.unlikePost(groupPostId);
+        return ResponseEntity.ok(response);
+    }
+
+    // 添加评论接口
+    @PostMapping("/{group_post_id}/comment")
+    public ResponseEntity<Map<String, Object>> addComment(
+
+            @PathVariable("group_post_id") Long postId,
+            @RequestBody GroupComments comment) {
+
+        Map<String, Object> response = groupService.addComment(postId, comment);
+        return ResponseEntity.ok(response);
+    }
+
+}