<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.campus.activity.mapper.ReviewMapper">

    <select id="selectActivityReviews" resultType="com.campus.activity.vo.ReviewVO">
        SELECT r.id,
               r.user_id as userId,
               r.activity_id as activityId,
               r.rating,
               r.content,
               r.created_at as createdAt,
               u.name as userName,
               u.avatar as userAvatar
        FROM review r
        LEFT JOIN user u ON r.user_id = u.id
        WHERE r.activity_id = #{activityId}
        ORDER BY r.created_at DESC
    </select>

    <select id="selectMyReviews" resultType="com.campus.activity.vo.ReviewVO">
        SELECT r.id,
               r.user_id as userId,
               r.activity_id as activityId,
               r.rating,
               r.content,
               r.created_at as createdAt,
               a.title as activityTitle
        FROM review r
        LEFT JOIN activity a ON r.activity_id = a.id
        WHERE r.user_id = #{userId}
        ORDER BY r.created_at DESC
    </select>

</mapper>