From cda649d1ce17af24c580e60c46808388782b5b3a Mon Sep 17 00:00:00 2001 From: Jax Young Date: Sat, 11 Mar 2023 00:03:39 +0800 Subject: [PATCH] feat: implement /relation/list interface --- .../controller/RelationController.java | 6 ++++ .../sxrekord/chatting/dao/RelationDao.java | 7 +++++ .../sxrekord/chatting/model/po/Relation.java | 6 ++++ .../chatting/service/RelationService.java | 8 +++++ .../service/impl/RelationServiceImpl.java | 29 +++++++++++++++++++ src/main/resources/mapper/relation-mapper.xml | 12 +++++++- 6 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sxrekord/chatting/controller/RelationController.java b/src/main/java/com/sxrekord/chatting/controller/RelationController.java index 4b2f310..51bb88c 100644 --- a/src/main/java/com/sxrekord/chatting/controller/RelationController.java +++ b/src/main/java/com/sxrekord/chatting/controller/RelationController.java @@ -30,4 +30,10 @@ public ResponseJson add(@RequestBody Relation relation, HttpSession session) { public ResponseJson update(@RequestBody Relation relation, HttpSession session) { return relationService.updateRelation(relation, session); } + + @GetMapping(value = "list") + @ResponseBody + public ResponseJson list(@RequestParam int type, int status, HttpSession session) { + return relationService.listRelation(type, status, session); + } } diff --git a/src/main/java/com/sxrekord/chatting/dao/RelationDao.java b/src/main/java/com/sxrekord/chatting/dao/RelationDao.java index 8fe1ca2..b947e64 100644 --- a/src/main/java/com/sxrekord/chatting/dao/RelationDao.java +++ b/src/main/java/com/sxrekord/chatting/dao/RelationDao.java @@ -46,4 +46,11 @@ public interface RelationDao { * @return */ int updateRelation(Relation relation); + + /** + * 列出关系 + * @param relation + * @return + */ + List listRelation(Relation relation); } diff --git a/src/main/java/com/sxrekord/chatting/model/po/Relation.java b/src/main/java/com/sxrekord/chatting/model/po/Relation.java index 1e912c7..621708e 100644 --- a/src/main/java/com/sxrekord/chatting/model/po/Relation.java +++ b/src/main/java/com/sxrekord/chatting/model/po/Relation.java @@ -15,4 +15,10 @@ public class Relation { private Integer status; public Relation() {} + + public Relation(Long acceptId, Integer type, Integer status) { + this.acceptId = acceptId; + this.type = type; + this.status = status; + } } diff --git a/src/main/java/com/sxrekord/chatting/service/RelationService.java b/src/main/java/com/sxrekord/chatting/service/RelationService.java index a6777d5..b20bddd 100644 --- a/src/main/java/com/sxrekord/chatting/service/RelationService.java +++ b/src/main/java/com/sxrekord/chatting/service/RelationService.java @@ -24,4 +24,12 @@ public interface RelationService { * @return */ ResponseJson updateRelation(Relation relation, HttpSession httpSession); + + /** + * 根据type和status列出所有关系 + * @param type + * @param status + * @return + */ + ResponseJson listRelation(int type, int status, HttpSession session); } diff --git a/src/main/java/com/sxrekord/chatting/service/impl/RelationServiceImpl.java b/src/main/java/com/sxrekord/chatting/service/impl/RelationServiceImpl.java index 48d7842..243240e 100644 --- a/src/main/java/com/sxrekord/chatting/service/impl/RelationServiceImpl.java +++ b/src/main/java/com/sxrekord/chatting/service/impl/RelationServiceImpl.java @@ -2,7 +2,10 @@ import com.sxrekord.chatting.dao.GroupDao; import com.sxrekord.chatting.dao.RelationDao; +import com.sxrekord.chatting.dao.UserDao; +import com.sxrekord.chatting.model.po.Group; import com.sxrekord.chatting.model.po.Relation; +import com.sxrekord.chatting.model.po.User; import com.sxrekord.chatting.model.vo.ResponseJson; import com.sxrekord.chatting.service.RelationService; import com.sxrekord.chatting.util.Constant; @@ -10,6 +13,8 @@ import org.springframework.stereotype.Service; import javax.servlet.http.HttpSession; +import java.util.ArrayList; +import java.util.List; /** * @author Rekord @@ -23,6 +28,9 @@ public class RelationServiceImpl implements RelationService { @Autowired GroupDao groupDao; + @Autowired + UserDao userDao; + @Override public ResponseJson createRelation(Relation relation, HttpSession session) { ResponseJson responseJson = new ResponseJson(); @@ -51,4 +59,25 @@ public ResponseJson updateRelation(Relation relation, HttpSession session) { return responseJson.success(); } + @Override + public ResponseJson listRelation(int type, int status, HttpSession session) { + ResponseJson responseJson = new ResponseJson(); + Object acceptId = session.getAttribute(Constant.USER_TOKEN); + List ids = relationDao.listRelation(new Relation((long)acceptId, type, status)); + if (type == 0) { + List friends = new ArrayList<>(); + for (Long id : ids) { + friends.add(this.userDao.getUserById(id)); + } + responseJson.setData("friends", friends); + } else { + List groups = new ArrayList<>(); + for (Long id : ids) { + groups.add(this.groupDao.getGroupById(id)); + } + responseJson.setData("groups", groups); + } + return responseJson.success(); + } + } diff --git a/src/main/resources/mapper/relation-mapper.xml b/src/main/resources/mapper/relation-mapper.xml index c9e404b..c2d9b09 100644 --- a/src/main/resources/mapper/relation-mapper.xml +++ b/src/main/resources/mapper/relation-mapper.xml @@ -45,4 +45,14 @@ ); - \ No newline at end of file + + +