Просмотр исходного кода

feat: 组和组成员查询功能

370774330@qq.com 5 лет назад
Родитель
Сommit
33dc3e3cc9

+ 20 - 7
web/src/main/java/seecoder/devcloud/web/controller/user/GroupController.java

@@ -6,14 +6,13 @@ import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import seecoder.devcloud.web.model.vo.Response;
+import seecoder.devcloud.web.model.vo.user.GroupVO;
 import seecoder.devcloud.web.service.user.GroupService;
 
 import javax.validation.constraints.Pattern;
+import java.util.List;
 
 /**
  * @author PuHong Weng
@@ -32,15 +31,29 @@ public class GroupController {
         this.groupService = groupService;
     }
 
+    @ApiOperation(value = "根据组id获取组", httpMethod = "GET")
+    @ApiImplicitParam(name = "groupId",dataType ="string", paramType = "param")
+    @GetMapping
+    public Response<GroupVO> getGroup(@RequestParam("groupId") Integer groupId){
+        return Response.buildSuccess(groupService.getGroup(groupId));
+    }
+
+    @ApiOperation(value = "根据组id获取组成员id列表", httpMethod = "GET")
+    @ApiImplicitParam(name = "groupId",dataType ="string", paramType = "param")
+    @GetMapping("/members")
+    public Response<List<Integer>> getGroupMemberIds(@RequestParam("groupId") Integer groupId){
+        return Response.buildSuccess(groupService.getGroupMemberIds(groupId));
+    }
+
+
     @ApiOperation(value = "创建组", httpMethod = "POST")
     @ApiImplicitParam(name = "userId",dataType ="string", paramType = "param")
     @PostMapping()
-    public Response createGroup(@RequestParam("name")
+    public Response<GroupVO> createGroup(@RequestParam("name")
                                     @Validated
                                     @Pattern(regexp = "^\\w{3,20}$", message = "组名称只能为长度为3-20且由数字、26个英文字母或者下划线组成的字符串")
                                             String name){
-        groupService.createGroup(name);
-        return Response.buildSuccess();
+        return Response.buildSuccess(groupService.createGroup(name));
     }
 
     @ApiOperation(value = "添加组成员", httpMethod = "POST")

+ 11 - 1
web/src/main/java/seecoder/devcloud/web/service/impl/user/GroupServiceImpl.java

@@ -39,6 +39,16 @@ public class GroupServiceImpl implements GroupService {
         this.seecoderGitlabApi = seecoderGitlabApi;
     }
 
+    @Override
+    public GroupVO getGroup(Integer groupId) {
+        return new GroupVO(groupMapper.findGroupById(groupId));
+    }
+
+    @Override
+    public List<Integer> getGroupMemberIds(Integer groupId) {
+        return groupMemberMapper.selectUserIdsByGroupId(groupId);
+    }
+
     @Override
     @Transactional
     public GroupVO createGroup(String name) throws ServiceException {
@@ -64,7 +74,7 @@ public class GroupServiceImpl implements GroupService {
 
 
     @Override
-    //@Transactional
+    @Transactional
     public void addMember(Integer invitedUserId, Integer groupId) throws EntityNotFoundException {
         //当前登陆的用户id
         int userId = UserService.loginUser().getId();

+ 7 - 1
web/src/main/java/seecoder/devcloud/web/service/user/GroupService.java

@@ -1,12 +1,13 @@
 package seecoder.devcloud.web.service.user;
 
 
-
 import org.springframework.stereotype.Service;
 import seecoder.devcloud.common.exceptions.EntityNotFoundException;
 import seecoder.devcloud.common.exceptions.ServiceException;
 import seecoder.devcloud.web.model.vo.user.GroupVO;
 
+import java.util.List;
+
 /**
  * @InterfaceName GroupService
  * @PackageName com.moekr.moocoder.logic.service.impl
@@ -18,6 +19,11 @@ import seecoder.devcloud.web.model.vo.user.GroupVO;
 @Service
 public interface GroupService {
 
+    GroupVO getGroup(Integer groupId);
+
+    List<Integer> getGroupMemberIds(Integer groupId);
+
+
     /**
      * 创建组,组的名字前面会加上 GROUP_NAME_PREFIX = "DEVCLOUD_" 的前缀
      */