add torrent upload(finished) and tracker announce(unimplemnt)
Change-Id: I017c03df2bc1c40c4a080837821d56dfe58d6eb6
diff --git a/src/main/resources/mapper/TorrentMapper.xml b/src/main/resources/mapper/TorrentMapper.xml
new file mode 100644
index 0000000..9b53d29
--- /dev/null
+++ b/src/main/resources/mapper/TorrentMapper.xml
@@ -0,0 +1,32 @@
+<?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.example.g8backend.mapper.TorrentMapper">
+ <insert id="insertTorrent" >
+ INSERT INTO torrents (user_id, torrent_name, info_hash, file_size)
+ VALUES (#{userId}, #{torrentName}, UNHEX(#{infoHash}), #{fileSize})
+ </insert>
+
+ <select id="getTorrentByInfoHash" resultType="com.example.g8backend.entity.Torrent">
+ SELECT
+ torrent_id,
+ user_id,
+ torrent_name,
+ HEX(info_hash) AS infoHash,
+ file_size
+ FROM torrents
+ WHERE info_hash = UNHEX(#{infoHash})
+ </select>
+
+ <select id="getTorrentByTorrentId" resultType="com.example.g8backend.entity.Torrent">
+ SELECT
+ torrent_id,
+ user_id,
+ torrent_name,
+ HEX(info_hash) AS infoHash,
+ file_size
+ FROM torrents
+ WHERE torrent_id = #{torrentId}
+ </select>
+</mapper>
\ No newline at end of file
diff --git a/src/main/resources/mapper/UserMapper.xml b/src/main/resources/mapper/UserMapper.xml
index 314c087..9627647 100644
--- a/src/main/resources/mapper/UserMapper.xml
+++ b/src/main/resources/mapper/UserMapper.xml
@@ -9,4 +9,7 @@
<select id="getUserByEmail" resultType="com.example.g8backend.entity.User">
SELECT * FROM users WHERE email = #{email}
</select>
+ <select id="getUserByPasskey" resultType="com.example.g8backend.entity.User">
+ SELECT * FROM users WHERE passkey = #{passkey}
+ </select>
</mapper>
\ No newline at end of file
diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql
index 2018117..365f9e7 100644
--- a/src/main/resources/schema.sql
+++ b/src/main/resources/schema.sql
@@ -2,7 +2,8 @@
user_id INT AUTO_INCREMENT PRIMARY KEY,
user_name VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
- email VARCHAR(255) NOT NULL UNIQUE
+ email VARCHAR(255) NOT NULL UNIQUE,
+ passkey VARCHAR(255) NOT NULL UNIQUE
);
CREATE TABLE IF NOT EXISTS `torrents` (
@@ -15,7 +16,7 @@
);
CREATE TABLE IF NOT EXISTS `peers` (
- user_id INT NOT NULL,
+ passkey VARCHAR(255) NOT NULL,
info_hash BINARY(20) NOT NULL,
peer_id VARCHAR(20) NOT NULL,
ip_address VARCHAR(128) NOT NULL,
@@ -23,6 +24,6 @@
uploaded FLOAT NOT NULL,
downloaded FLOAT NOT NULL,
last_seen TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
- FOREIGN KEY (user_id) REFERENCES users(user_id),
- PRIMARY KEY (user_id, info_hash, peer_id)
+ FOREIGN KEY (passkey) REFERENCES users(passkey),
+ PRIMARY KEY (passkey, info_hash, peer_id)
);