follow+sendMessage

Change-Id: I3e9bbcc89dfc53b9651fd8722da1b445a597629a
diff --git a/src/main/java/com/example/g8backend/mapper/FollowMapper.java b/src/main/java/com/example/g8backend/mapper/FollowMapper.java
new file mode 100644
index 0000000..f1d03af
--- /dev/null
+++ b/src/main/java/com/example/g8backend/mapper/FollowMapper.java
@@ -0,0 +1,22 @@
+package com.example.g8backend.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.example.g8backend.entity.Follow;
+import org.apache.ibatis.annotations.Delete;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
+
+@Mapper
+public interface FollowMapper extends BaseMapper<Follow> {
+    @Delete("DELETE FROM user_follows WHERE follower_id=#{followerId} AND followed_id=#{followedId}")
+    int deleteByPair(@Param("followerId") Long followerId, @Param("followedId") Long followedId);
+
+    @Select("SELECT followed_id FROM user_follows WHERE follower_id = #{userId}")
+    List<Long> selectFollowings(Long userId);
+
+    @Select("SELECT follower_id FROM user_follows WHERE followed_id = #{userId}")
+    List<Long> selectFollowers(Long userId);
+}
diff --git a/src/main/java/com/example/g8backend/mapper/MessageMapper.java b/src/main/java/com/example/g8backend/mapper/MessageMapper.java
new file mode 100644
index 0000000..3f2caf4
--- /dev/null
+++ b/src/main/java/com/example/g8backend/mapper/MessageMapper.java
@@ -0,0 +1,23 @@
+package com.example.g8backend.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.example.g8backend.entity.Message;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
+
+@Mapper
+public interface MessageMapper extends BaseMapper<Message> {
+    @Select("SELECT * FROM private_messages " +
+            "WHERE (sender_id=#{userId1} AND receiver_id=#{userId2}) " +
+            "OR (sender_id=#{userId2} AND receiver_id=#{userId1}) " +
+            "ORDER BY sent_at")
+    List<Message> selectConversation(@Param("userId1") Long userId1, @Param("userId2") Long userId2);
+
+    @Select("SELECT * FROM private_messages " +
+            "WHERE sender_id=#{userId} OR receiver_id=#{userId} " +
+            "ORDER BY sent_at DESC")
+    List<Message> selectUserMessages(Long userId);
+}
\ No newline at end of file