A
Anonymous

Document Sharing App - Copy this React, Tailwind Component to your project

-- Sử dụng cơ sở dữ liệu ptit_documents USE ptit_documents; -- Bảng users: Lưu thông tin người dùng CREATE TABLE users ( id INT AUTO_INCREMENT PRIMARY KEY, username VARCHAR(50) NOT NULL UNIQUE, email VARCHAR(100) NOT NULL UNIQUE, password_hash VARCHAR(255) NOT NULL, role ENUM('student', 'admin') DEFAULT 'student', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); -- Chèn dữ liệu mẫu vào bảng users INSERT INTO users (username, email, password_hash, role) VALUES ('nguyenvanA', 'nguyenvana@example.com', '12345678', 'student'); -- Bảng categories: Lưu thông tin chuyên ngành/môn học CREATE TABLE categories ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100) NOT NULL UNIQUE, description TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); -- Chèn dữ liệu mẫu vào bảng categories INSERT INTO categories (name, description) VALUES ('Toán cao cấp', 'Tài liệu về toán cao cấp'), ('Lập trình C', 'Tài liệu môn lập trình C'); -- Bảng documents: Lưu thông tin tài liệu CREATE TABLE documents ( id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(200) NOT NULL, description TEXT, file_path VARCHAR(255) NOT NULL, image_path VARCHAR(255) DEFAULT NULL, -- Thêm cột lưu đường dẫn ảnh category_id INT NOT NULL, user_id INT NOT NULL, views INT DEFAULT 0, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE CASCADE, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE ); -- Chèn dữ liệu mẫu vào bảng documents INSERT INTO documents (title, description, file_path, image_path, category_id, user_id) VALUES ('Bài giảng Toán cao cấp', 'Bài giảng chương 1', '/uploads/toan.pdf', '/uploads/images/toan.jpg', 1, 1), ('Tài liệu lập trình C', 'Hướng dẫn chương 1', '/uploads/c_programming.pdf', '/uploads/images/c_programming.jpg', 2, 1); -- Bảng comments: Lưu bình luận của người dùng CREATE TABLE comments ( id INT AUTO_INCREMENT PRIMARY KEY, document_id INT NOT NULL, user_id INT NOT NULL, comment TEXT NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE CASCADE, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE ); -- Bảng ratings: Lưu thông tin đánh giá CREATE TABLE ratings ( id INT AUTO_INCREMENT PRIMARY KEY, document_id INT NOT NULL, user_id INT NOT NULL, rating INT CHECK (rating BETWEEN 1 AND 5), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE CASCADE, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE ); đây là csdl hãy tích hơpj api

Prompt
Component Preview

About

DocumentSharingApp - Share and manage documents with user roles, categories, comments, and ratings, professionally built with React and Tailwind. Start coding now!

Share

Last updated 1 month ago