Skip to content

NTUEEInfoDep/NTUEECourseWebsite2020

Repository files navigation

NTUEECourse2020

2020 年新版臺大電機系預選網站 (https://course.ntuee.org/)

Usage

Contributors

前端:朱哲廣, email: [email protected]

後端:劉奇聖, email: [email protected]

Quick Start (Development mode)

After cloning this repo, put students.json into ./server/database/private-data/, and then execute the following commands.

For the format and generation of students.json, see password generation.

$ npm install
$ sudo docker-compose up -d    # This will watch backend code changes
$ npm run develop-client       # This will open webpack-dev-server for frontend

Goto http://localhost:8000 to see the website.

Development

Type the following command to see server logs:

$ sudo docker-compose logs -f course2020

Type the following command to go into docker container.

$ sudo docker-compose exec course2020 bash

And then you can use /app/server/database/database.js to control database.

Type node database.js --help for help.

Directory Structure

.
├── assets/                    - static assets
├── client/                    - frontend code
    ├── html                   - html template
    └── src                    - js source code
        ├── actions            - Redux actions
        ├── components         - React components
        ├── constants          - actionTypes and initial state
        ├── reducers           - Redux reducers
        ├── routes             - React router
        ├── store              - Redux store
        └── theme              - color theme
├── server/                    - backend code
    ├── routes/                - express routers
    └── database               - database-related codes
        ├── data/              - Non-secret data, e.g. course names
        ├── private-data/      - Secret data, e.g. student names and passwords
        ├── mongo/             - MongoDB-related codes
        ├── redis/             - RedisDB-related codes
        ├── database.js        - CLI for database operations
        └── gen_password.py    - Script for generating student passwords
├── Dockerfile                 - For deploy
└── docker-compose.yml         - For development

預選 SOP

1. Password generation

  1. 跟學術部拿學生名單(students.csv),放到./server/database/private-data/裡 格式如下:
    id,grade,name
    B07901XXX,3,劉奇聖
    B07901XXX,3,朱哲廣
    ...
    
    註:id 是學號,grade 是年級,name 是姓名
  2. 進到./server/database/,跑
    python gen_password.py
    會生成兩個檔案students.jsonstudents_password.csvprivate-data/裡。
  3. students_password.csv給學術部
  4. students.json的格式如下:
    [
      {
        "userID": "B07901XXX",
        "grade": 3,
        "password": "abcdefg"
      },
      ...
    ]
    

2. Prepare data

準備好./server/database/data/資料夾裡的資料,格式請自己看repo 上的檔案

註:courses.json 還可參考course_history資料夾裡的過往資料

3. Reset database

去系學會伺服器的/home/ntuee/production資料夾下跑

docker-compose exec course2020-admin npm run reset-db

4. Export data

預選結束之後,去系學會伺服器的/home/ntuee/production資料夾下跑

docker-compose exec course2020-admin bash
cd server/database
node database.js export

然後把系學會伺服器的/home/ntuee/production/NTUEECourseWebsite2020/server/database/private-data/selections.json拿去跑分發程式

Backend Api

課程種類: "0"(實驗), "1"(大一必修), "2"(大二必修), "3"(大三必修)

註:沒在開放日期內 request api 都會發 503 status code, 且 response body 會給開放日期,格式如下 (value 為 ISOString):

{
  "start": "2020-07-19T16:00:00.000Z",
  "end": "2020-07-21T19:00:00.000Z"
}
Method Route Request Body Response Description
GET /api/session Success: 200
JSON Response:
{
  userID: 學號(String)
}
Failed:
403: 沒登入
Get user session data
POST /api/session type: x-www-form-urlencoded
content:
KEY VALUE
userID 學號(String)
password 密碼(String)
Success: 201
JSON Response:
{
  userID: 學號(String)
}
Failed:
400: Request body格式錯誤
401: 密碼錯誤
Login
DELETE /api/session Success: 204 Logout
GET /api/courses Success: 200
{
  type(String, 課程種類):[
    {
      courseID: 課程 ID(String),
      name: 課程名稱(String),
    },
    ...
  ],
  ...
}
Failed:
403: 沒登入
Get all courses
GET /api/selections/:courseID Success: 200
JSON Response:
{
  name: 課程名稱(String),
  type: 課程種類,
  description: 課程描述(String),
  selected(String, 選的選項照志願序順序): [選項名稱(String), ...],
  unselected(String, 沒選的選項無排序): [選項名稱(String), ...],
}
Failed:
403: 沒登入
404: 不合法的courseID
Get course selection
PUT /api/selections/:courseID type: json
content:
(一條Array裡面都是選項名稱,照志願序排序)
[選項名稱(String)]
Success: 204
Failed:
403: 沒登入
404: 不合法的courseID
400: Request body 格式錯誤
Update course selection

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •