GithubHelp home page GithubHelp logo

databaseproject112backend's Introduction

Database Project 112 Backend

This repository contains the backend code for DatabaseProject112.

Installation

  1. Clone the repository and install dependencies:

    git clone --depth 1 https://github.com/Slope86/DatabaseProject112Backend
    cd DatabaseProject112Backend
    pip install -r requirements.txt

    This will clone the repository and install all the required dependencies specified in the requirements.txt file.

  2. Set up Database Connection

    • Rename the file .env.example to .env.
    • Fill in the necessary database connection information within the .env file.
  3. Initialize the Database

    Run the following SQL queries ( SQL version: MySQL Community Server 8.0.17 ) in your chosen database management system to initialize the required structure:

    -- mySQL Query to create database fit_lohas
    CREATE DATABASE IF NOT EXISTS `fit_lohas`;
    
    -- mySQL Query to use database fit_lohas
    USE `fit_lohas`;
    
    -- mySQL Query to create table users
    CREATE TABLE users (
        UserID INT AUTO_INCREMENT PRIMARY KEY,
        Username VARCHAR(50) NOT NULL,
        Email VARCHAR(100) UNIQUE NOT NULL,
        PasswordHash VARCHAR(200) NOT NULL,
        AvatarPath VARCHAR(200) DEFAULT '/assets/images/avatars/000-default.png ',
        FullName VARCHAR(100),
        UserRole VARCHAR(50) DEFAULT 'STUDENT',
        PhoneNumber VARCHAR(20),
        Address VARCHAR(200),
        Gender ENUM('Male', 'Female', 'Other'),
        CreatedDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        ModifyDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
    );
    
    -- mySQL Query to insert data into table users
    INSERT INTO users (
        UserID,
        Username, 
        Email, 
        PasswordHash, 
        AvatarPath, 
        FullName, 
        UserRole, 
        Address, 
        Gender
    ) VALUES (
        1,
        'admin', 
        '[email protected]', 
        '9e37a8d2e30bb3c7a36f2e1646c0154c835f56175307445146b9bb0f80fdb1d6',  -- Password: dummyPass
        '/assets/images/face-0.png', 
        'Super user', 
        'ADMIN', 
        'Taiwan NCHU', 
        'Male'
    );
    
    INSERT INTO users(
        UserID,
        Username,
        Email,
        PasswordHash,
        UserRole
    ) VALUES (
        2,
        'teacher01', 
        '[email protected]',
        '9e37a8d2e30bb3c7a36f2e1646c0154c835f56175307445146b9bb0f80fdb1d6',  -- Password: dummyPass
        'TEACHER'
    ),
    ( 
        3,
        'teacher02', 
        '[email protected]',
        '9e37a8d2e30bb3c7a36f2e1646c0154c835f56175307445146b9bb0f80fdb1d6',  -- Password: dummyPass
        'TEACHER'
    );
    
    INSERT INTO users(
        UserID,
        Username,
        Email,
        PasswordHash
    ) VALUES ( 
        4,
        'student01', 
        '[email protected]',
        '9e37a8d2e30bb3c7a36f2e1646c0154c835f56175307445146b9bb0f80fdb1d6'  -- Password: dummyPass
    ),
    (
        5,
        'student02', 
        '[email protected]',
        '9e37a8d2e30bb3c7a36f2e1646c0154c835f56175307445146b9bb0f80fdb1d6'  -- Password: dummyPass
    );
    
    -- mySQL Query to create table teachers with two attributes: TeacherID and Salary, where TeacherID is a foreign key referencing to UserID in table users
    CREATE TABLE teachers (
        TeacherID INT AUTO_INCREMENT PRIMARY KEY,
        UserID INT,
        Salary DECIMAL(10, 2),
        CreatedDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        ModifyDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
        FOREIGN KEY (UserID) REFERENCES users(UserID)
    );
    
    -- mySQL Query to insert data into table teachers
    INSERT INTO teachers (
        UserID, 
        Salary
    ) VALUES (
        2, 
        100000
    ),
    (
        3, 
        200000
    );
    
    -- mySQL Query to create table courses  with four attributes: CourseID, TeacherID, CreatedDate, ModifyDate
    CREATE TABLE courses  (
        CourseID INT AUTO_INCREMENT PRIMARY KEY,
        CourseName VARCHAR(100) NOT NULL,
        CourseDescription VARCHAR(200) NOT NULL,
        Category VARCHAR(50),
        TeacherID INT,
        CreatedDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        ModifyDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
        FOREIGN KEY (TeacherID) REFERENCES teachers(TeacherID)
    );
    
    -- Inserting course 1: Cardio Kickboxing
    INSERT INTO courses (CourseName, CourseDescription, Category, TeacherID)
    VALUES (
        'Cardio Kickboxing',
        'High-energy workout combining martial arts techniques and heart-pumping cardio.',
        'Kickboxing',
        1
    ),
    (
        'Strength Training 101',
        'Introduction to basic strength exercises focusing on building muscle and strength.',
        'Strength Training',
        2
    ),
    (
        'Yoga for Flexibility',
        'Gentle yoga practice aimed at improving flexibility and reducing stress.',
        'Yoga',
        2
    ),
    (
        'Advanced Kickboxing Techniques',
        'Advanced techniques and combinations for experienced practitioners.',
        'Kickboxing',
        1
    ),
    (
        'Powerlifting Essentials',
        'Focus on powerlifting exercises for building maximum strength.',
        'Strength Training',
        2
    ),
    (
        'Mindful Meditation through Yoga',
        'Learn mindfulness and meditation practices through yoga poses.',
        'Yoga',
        2
    );
    
    -- CourseEnter (CourseID, UserID, CreatedDate, ModifyDate)
    CREATE TABLE CourseEnter (
        CourseID INT,
        UserID INT,
        CreatedDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        ModifyDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
        FOREIGN KEY (CourseID) REFERENCES courses(CourseID),
        FOREIGN KEY (UserID) REFERENCES users(UserID),
        PRIMARY KEY (CourseID, UserID)
    );
    
    -- Inserting CourseEnter 1: Cardio Kickboxing
    INSERT INTO CourseEnter (CourseID, UserID)
    VALUES (1, 4), (2, 4), (3, 5);

    Ensure these queries create the tables, relationships, or any initial data required for the project to function properly.

  4. Run the Backend

    Run the following command to start the backend:

    python app.py

    The backend should now be running on http://localhost:5000.

Contributing

Feel free to contribute by creating issues or pull requests.

License

This project is licensed under the MIT License.

databaseproject112backend's People

Contributors

slope86 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.