<?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.microservices.system.mapper.ForgeUserMapper">
    <resultMap type="com.microservices.system.domain.ForgeUser" id="ForgeUserResult">
        <result property="id" column="id"/>
        <result property="login" column="login"/>
        <result property="hashedPassword" column="hashed_password"/>
        <result property="firstname" column="firstname"/>
        <result property="lastname" column="lastname"/>
        <result property="mail" column="mail"/>
        <result property="admin" column="admin"/>
        <result property="status" column="status"/>
        <result property="lastLoginOn" column="last_login_on"/>
        <result property="createdOn" column="created_on"/>
        <result property="updatedOn" column="updated_on"/>
        <result property="type" column="type"/>
        <result property="mailNotification" column="mail_notification"/>
        <result property="phone" column="phone"/>
        <result property="nickname" column="nickname"/>
    </resultMap>
    <sql id="selectGitLinkUserVo"> select id,
                                          login,
                                          hashed_password,
                                          firstname,
                                          lastname,
                                          mail,
                                          admin,
                                          status,
                                          last_login_on,
                                          created_on,
                                          updated_on,
                                          type,
                                          mail_notification,
                                          phone,
                                          nickname
                                   from users </sql>
    <select id="selectUserIdByGitLinkToken" resultType="java.lang.Long">
        SELECT user_id
        FROM tokens
        WHERE `value` = #{gitLinkToken}
          AND `action` = 'autologin'
    </select>
    <select id="selectGitLinkUserById" parameterType="Long" resultMap="ForgeUserResult">
        <include refid="selectGitLinkUserVo"/>
        where id = #{id}
    </select>
    <select id="selectGitLinkTokenByUserId" resultType="java.lang.String">
        SELECT value
        FROM tokens
        WHERE `user_id` = #{gitLinkUserId}
          AND `action` = 'autologin'
    </select>
</mapper> 