Compare commits
13 Commits
941c5be8f3
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 6da9e5d12a | |||
| ce31822f97 | |||
| f8a792ce7b | |||
| ba81f91189 | |||
| bf9e6364b9 | |||
| c941ac2022 | |||
| 2229e75644 | |||
| f71e97b6ff | |||
| 3679f641e5 | |||
| 5702bdce4d | |||
| c8787ad1f7 | |||
| 302fd36c34 | |||
| 9feddb6bac |
@@ -15,7 +15,7 @@ module.exports = {
|
||||
}]
|
||||
],
|
||||
port: 3030,
|
||||
base: '/edu-dis-labs/',
|
||||
base: '/edu-dis-labs-private/',
|
||||
theme: 'cool',
|
||||
// dest: 'dist',
|
||||
head: [
|
||||
@@ -66,11 +66,6 @@ module.exports = {
|
||||
title: 'Висновки',
|
||||
path:"/conclusion/"
|
||||
},
|
||||
|
||||
{
|
||||
title: 'API',
|
||||
path:"/api/"
|
||||
}
|
||||
|
||||
],
|
||||
sidebarDepth: 2,
|
||||
@@ -83,7 +78,7 @@ module.exports = {
|
||||
|
||||
lastUpdated: 'Останнє оновлення', // string | boolean
|
||||
// Assumes GitHub. Can also be a full GitLab url.
|
||||
repo: 'http://139.162.162.130:3000/hasslesstech/edu-dis-labs',
|
||||
repo: 'http://139.162.162.130:3000/hasslesstech/edu-dis-labs-private',
|
||||
// Customising the header label
|
||||
// Defaults to "GitHub"/"GitLab"/"Bitbucket" depending on `themeConfig.repo`
|
||||
repoLabel: 'Gitea',
|
||||
@@ -102,8 +97,8 @@ module.exports = {
|
||||
// editLinkText: 'Ви можете покращити цю сторінку'
|
||||
|
||||
},
|
||||
title: 'Expertise',
|
||||
description: 'Лабораторні роботи з дисципліни "Розподілені інформаційні системи"',
|
||||
title: 'Xpertise',
|
||||
description: 'Лабораторні роботи з дисципліни "Організація баз даних"',
|
||||
configureWebpack: {
|
||||
resolve: {
|
||||
alias: {
|
||||
|
||||
@@ -6,23 +6,11 @@ actionLink: /intro/
|
||||
footer: "ECL 2.0 Licensed | Copyright © 2024 [Your Name]"
|
||||
---
|
||||
|
||||
**Виконали:**
|
||||
**Виконав:**
|
||||
|
||||
*студенти 2-го курсу, групи ІО-23:*
|
||||
*студент 2-го курсу, групи ІО-23:*
|
||||
|
||||
*Олег ШМУЛЯР [shmuliar1@ukr.net, [@dmytrofiot23](https://t.me/dmytrofiot23)]*
|
||||
|
||||
*Андрій БОДНАР [bodnarandrew123@gmail.com, [@andrux4](https://t.me/andrux4)]*
|
||||
|
||||
*Андрій ШВЕД [andreyfrog26@gmail.com, [@Rhinemann](https://t.me/Rhinemann)]*
|
||||
|
||||
*Євгеній ГОЛОВАТЕНКО [ievgeniigol@gmail.com, [@yevholova](https://t.me/yevholova)]*
|
||||
|
||||
*Вікторія ВОДЯНА [vodyanayaviktoria@gmail.com, [@victoriavodyana](https://t.me/victoriavodyana)]*
|
||||
|
||||
*Михайло КОРБУТ [korbutmykhailo@gmail.com, [@misha1tigr](https://t.me/misha1tigr)]*
|
||||
|
||||
*Олександр ГУРАНЕЦЬ [bacant150@gmail.com, [@Bacant150](https://t.me/Bacant150)]*
|
||||
*Олег ШМУЛЯР [shmuliar1@ukr.net], [@dmytrofiot23](https://t.me/dmytrofiot23)*
|
||||
|
||||
|
||||
**Керівник**
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
# Висновки
|
||||
|
||||
У висновках наводять оцінку отриманих результатів, можливі галузі його використання. Висновки повинні містити в собі коротку узагальнену оцінку результатів розробки, у
|
||||
тому числі і з погляду на їх технічно-економічну ефективність. Необхідно порівняти
|
||||
отримані результати усіх характеристик об’єкта проєктування із завданням і з основними показниками сучасних аналогічних об’єктів.
|
||||
В результаті проведеної роботи ми розробили модель бази даних, яку можна використовувати для реалізації систем проведення експертних опитувань. В рамках цього відгалуження розробив серверну частину, що надає RESTFUL-інтерфейс для доступу до бази даних. Вона може використовуватися для взаємодії з будь-якою з таблиць, проте я приділив окрему увагу розширенню гнучкості інтерфейсу взаємодії з таблицею опитувань (survey).
|
||||
|
||||
Необхідно вказати яке нове технічне рішення покладене в основу проєкту і у чому її
|
||||
переваги, що нового було запропоновано самим студентом.
|
||||
Проєкт мав на меті реалізацію двох ключових особливостей:
|
||||
- оптимальність використання мережі
|
||||
- гнучкість у застосуванні
|
||||
|
||||
На базі отриманих висновків можуть надаватися рекомендації по використанню розробки. Вони повинні
|
||||
мати конкретний характер і бути цілком підтверджені проєктом.
|
||||
Оптимальність використання мережі досягається використанням протоколу HTTP без домішок у вигляді додаткових бібліотек, фреймворків, аналітики, відстеження дій користувачів тощо. Завдяки цьому середній обсяг повідомлення становить до 100 байтів, тому сервер, за використання з'єднання з пропускною здатністю 1 Gb/s, зможе обробляти до 1.34 млн повідомлень щосекунди, а це дозволить обслуговувати близько 400 тис. користувачів одночасно. В свою чергу, користувачі зможуть отримувати обслуговування від сервера навіть за умов поганого мережевого з'єднання, що дуже актуально в сучасних реаліях (вимкнення електропостачання, перебої зі зв'язком тощо).
|
||||
|
||||
Гнучкість проєкту досягається завдяки простій архітектурі, що не прив'язана до визначених ролей. Натомість, кожен зареєстрований користувач може використовувати можливості системи в повному обсязі, що робить її універсальною для виконання багатьох завдань: від збору думок вузького кола співробітників до проведення масштабних статистичних досліджень із залученням мільйонів користувачів.
|
||||
|
||||
Отже, наша розробка досягла поставленої мети й є особливо актуальною в умовах сьогодення.
|
||||
@@ -28,11 +28,11 @@ entity Responce <<ENTITY>>
|
||||
entity Responce.value <<TEXT>>
|
||||
|
||||
entity Link <<ENTITY>>
|
||||
entity Link.usageLimit
|
||||
entity Link.responceLimit
|
||||
entity Link.uses
|
||||
entity Link.responces
|
||||
entity Link.path
|
||||
entity Link.usageLimit <<INT>>
|
||||
entity Link.responceLimit <<INT>>
|
||||
entity Link.uses <<INT>>
|
||||
entity Link.responces <<INT>>
|
||||
entity Link.path <<TEXT>>
|
||||
|
||||
Account.username --* Account
|
||||
Account.password --* Account
|
||||
@@ -115,3 +115,16 @@ Responce "0,*" --> "0,1" Account
|
||||
@enduml
|
||||
|
||||
</center>
|
||||
|
||||
## Реляційна схема
|
||||
|
||||
<center style="
|
||||
border-radius:4px;
|
||||
border: 1px solid #cfd7e6;
|
||||
box-shadow: 0 1px 3px 0 rgba(89,105,129,.05), 0 1px 1px 0 rgba(0,0,0,.025);
|
||||
padding: 1em;"
|
||||
>
|
||||
|
||||

|
||||
|
||||
</center>
|
||||
|
||||
BIN
docs/design/relational_scheme.png
Normal file
BIN
docs/design/relational_scheme.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 49 KiB |
@@ -1,3 +1,334 @@
|
||||
# Реалізація інформаційного та програмного забезпечення
|
||||
|
||||
## SQL-скрипт для створення та початкового наповнення бази даних
|
||||
|
||||
```sql
|
||||
-- MySQL Workbench Forward Engineering
|
||||
|
||||
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
|
||||
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
|
||||
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Schema mydb
|
||||
-- -----------------------------------------------------
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Schema mydb
|
||||
-- -----------------------------------------------------
|
||||
CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 ;
|
||||
USE `mydb` ;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `mydb`.`Account`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `mydb`.`Account` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`username` CHAR(255) NOT NULL,
|
||||
`password` CHAR(255) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE INDEX `id_UNIQUE` (`id` ASC) VISIBLE,
|
||||
UNIQUE INDEX `username_UNIQUE` (`username` ASC) VISIBLE)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `mydb`.`Survey`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `mydb`.`Survey` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`isPaused` TINYINT UNSIGNED NOT NULL,
|
||||
`isNamed` TINYINT UNSIGNED NOT NULL,
|
||||
`name` CHAR(255) NULL,
|
||||
`duration` CHAR(255) NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE INDEX `id_UNIQUE` (`id` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_Survey_Account1`
|
||||
FOREIGN KEY (`id`)
|
||||
REFERENCES `mydb`.`Account` (`id`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `mydb`.`Question`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `mydb`.`Question` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`Text` CHAR(255) NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE INDEX `id_UNIQUE` (`id` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_Question_Survey1`
|
||||
FOREIGN KEY (`id`)
|
||||
REFERENCES `mydb`.`Survey` (`id`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `mydb`.`Response`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `mydb`.`Response` (
|
||||
`id` INT UNSIGNED NULL AUTO_INCREMENT,
|
||||
`Value` VARCHAR(16384) NULL,
|
||||
UNIQUE INDEX `id_UNIQUE` (`id` ASC) VISIBLE,
|
||||
PRIMARY KEY (`id`),
|
||||
CONSTRAINT `fk_Response_Question`
|
||||
FOREIGN KEY (`id`)
|
||||
REFERENCES `mydb`.`Question` (`id`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `fk_Response_Account1`
|
||||
FOREIGN KEY (`id`)
|
||||
REFERENCES `mydb`.`Account` (`id`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `mydb`.`Link`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `mydb`.`Link` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`uses` INT NOT NULL,
|
||||
`responces` INT NOT NULL,
|
||||
`usageLimit` INT NULL,
|
||||
`responceLimit` INT NULL,
|
||||
`path` CHAR(32) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
CONSTRAINT `fk_Link_Survey1`
|
||||
FOREIGN KEY (`id`)
|
||||
REFERENCES `mydb`.`Survey` (`id`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
SET SQL_MODE=@OLD_SQL_MODE;
|
||||
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
|
||||
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
|
||||
```
|
||||
|
||||
## RESTfull-сервіс для керування опитуваннями
|
||||
|
||||
Код серверу (Python, Flask):
|
||||
```python
|
||||
from flask import Flask, request
|
||||
import mariadb as mdb
|
||||
import json
|
||||
import sys
|
||||
|
||||
def init_db():
|
||||
return mdb.connect(host="127.0.0.1", port=3306, user="user", password="testing432")
|
||||
|
||||
c = 0
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route("/api/<endpoint>", methods = ["GET", "POST", "PUT", "DELETE"])
|
||||
def api_test(endpoint):
|
||||
se = endpoint
|
||||
|
||||
match se:
|
||||
case "counter":
|
||||
global c
|
||||
c += 1
|
||||
case "account":
|
||||
c = init_db()
|
||||
cur = c.cursor()
|
||||
|
||||
match request.method:
|
||||
case "GET":
|
||||
cur.execute("SELECT id, username FROM odb.account;")
|
||||
r = [{"id": i, "username": j} for i, j in cur]
|
||||
c.close()
|
||||
return json.dumps(r)
|
||||
case "POST":
|
||||
d = request.get_json()
|
||||
cur.execute(f"INSERT INTO odb.account (username, password) VALUES (\"{d['username']}\", \"{d['password']}\");")
|
||||
c.commit()
|
||||
c.close()
|
||||
return '{"success": true}\n'
|
||||
case "PUT":
|
||||
d = request.get_json()
|
||||
cur.execute(f"UPDATE odb.account SET username = \"{d['username']}\", password = \"{d['password']}\" WHERE id = {d['id']};")
|
||||
c.commit()
|
||||
c.close()
|
||||
return '{"success": true}\n'
|
||||
case "DELETE":
|
||||
d = request.get_json()
|
||||
cur.execute(f"SELECT id, username FROM odb.account WHERE id = {d['id']};")
|
||||
r = [{"id": i, "username": j} for i, j in cur]
|
||||
cur.execute(f"DELETE FROM odb.account WHERE id = {d['id']};")
|
||||
c.commit()
|
||||
c.close()
|
||||
return f'{r}\n'
|
||||
case "survey":
|
||||
c = init_db()
|
||||
cur = c.cursor()
|
||||
|
||||
match request.method:
|
||||
case "GET":
|
||||
cur.execute("SELECT id, isPaused, isNamed, name, duration, account_id FROM odb.survey;")
|
||||
r = [{"id": i[0], "isPaused": i[1], "isNamed": i[2], "name": i[3], "duration": i[4], "account_id": i[5]} for i in cur]
|
||||
c.close()
|
||||
return json.dumps(r)
|
||||
|
||||
case "POST":
|
||||
d = request.get_json()
|
||||
cur.execute(f"INSERT INTO odb.survey (isPaused, isNamed, name, duration, account_id) VALUES ({d['isPaused']}, {d['isNamed']}, \"{d['name']}\", \"{d['duration']}\", {d['account_id']});")
|
||||
c.commit()
|
||||
c.close()
|
||||
return '{"success": true}\n'
|
||||
|
||||
case "PUT":
|
||||
d = request.get_json()
|
||||
cur.execute(f"UPDATE odb.survey SET isPaused = {d['isPaused']}, isNamed = {d['isNamed']}, name = \"{d['name']}\", duration = \"{d['duration']}\" WHERE id = {d['id']};")
|
||||
c.commit()
|
||||
c.close()
|
||||
return '{"success": true}\n'
|
||||
|
||||
case "DELETE":
|
||||
d = request.get_json()
|
||||
cur.execute(f"SELECT id, isPaused, isNamed, name, duration, account_id FROM odb.survey WHERE id = {d['id']};")
|
||||
r = [{"id": i[0], "isPaused": i[1], "isNamed": i[2], "name": i[3], "duration": i[4], "account_id": i[5]} for i in cur]
|
||||
cur.execute(f"DELETE FROM odb.survey WHERE id = {d['id']};")
|
||||
c.commit()
|
||||
c.close()
|
||||
return f'{r}\n'
|
||||
|
||||
case "link":
|
||||
c = init_db()
|
||||
cur = c.cursor()
|
||||
|
||||
match request.method:
|
||||
case "GET":
|
||||
cur.execute("SELECT id, uses, responces, usageLimit, responceLimit, path, survey_id FROM odb.link;")
|
||||
r = [{"id": i[0], "uses": i[1], "responces": i[2], "usageLimit": i[3], "responceLimit": i[4], "path": i[5], "survey_id": i[6]} for i in cur]
|
||||
c.close()
|
||||
return json.dumps(r)
|
||||
|
||||
case "POST":
|
||||
d = request.get_json()
|
||||
cur.execute(f"INSERT INTO odb.link (usageLimit, responceLimit, path, survey_id) VALUES ({d['usageLimit']}, {d['responceLimit']}, \"{d['path']}\", {d['survey_id']});")
|
||||
c.commit()
|
||||
c.close()
|
||||
return '{"success": true}\n'
|
||||
|
||||
case "PUT":
|
||||
d = request.get_json()
|
||||
cur.execute(f"UPDATE odb.link SET uses = {d['uses']}, responces = {d['responces']}, usageLimit = \"{d['usageLimit']}\", responceLimit = \"{d['responceLimit']}\", path = \"{d['path']}\", survey_id = {d['survey_id']} WHERE id = {d['id']};")
|
||||
c.commit()
|
||||
c.close()
|
||||
return '{"success": true}\n'
|
||||
|
||||
case "DELETE":
|
||||
d = request.get_json()
|
||||
cur.execute(f"SELECT id, uses, responces, usageLimit, responceLimit, path, survey_id FROM odb.survey WHERE id = {d['id']};")
|
||||
r = [{"id": i[0], "uses": i[1], "responces": i[2], "usageLimit": i[3], "responceLimit": i[4], "path": i[5], "survey_id": i[6]} for i in cur]
|
||||
cur.execute(f"DELETE FROM odb.link WHERE id = {d['id']};")
|
||||
c.commit()
|
||||
c.close()
|
||||
return f'{r}\n'
|
||||
|
||||
case "question":
|
||||
c = init_db()
|
||||
cur = c.cursor()
|
||||
|
||||
match request.method:
|
||||
case "GET":
|
||||
cur.execute("SELECT id, text, survey_id FROM odb.question;")
|
||||
r = [{"id": i[0], "text": i[1], "survey_id": i[2]} for i in cur]
|
||||
c.close()
|
||||
return json.dumps(r)
|
||||
|
||||
case "POST":
|
||||
d = request.get_json()
|
||||
cur.execute(f"INSERT INTO odb.question (text, survey_id) VALUES (\"{d['text']}\", {d['survey_id']});")
|
||||
c.commit()
|
||||
c.close()
|
||||
return '{"success": true}\n'
|
||||
|
||||
case "PUT":
|
||||
d = request.get_json()
|
||||
cur.execute(f"UPDATE odb.question SET text = \"{d['text']}\", survey_id = {d['survey_id']} WHERE id = {d['id']};")
|
||||
c.commit()
|
||||
c.close()
|
||||
return '{"success": true}\n'
|
||||
|
||||
case "DELETE":
|
||||
d = request.get_json()
|
||||
cur.execute(f"SELECT id, text, survey_id FROM odb.question WHERE id = {d['id']};")
|
||||
r = [{"id": i[0], "text": i[1], "survey_id": i[2]} for i in cur]
|
||||
cur.execute(f"DELETE FROM odb.question WHERE id = {d['id']};")
|
||||
c.commit()
|
||||
c.close()
|
||||
return f'{r}\n'
|
||||
|
||||
case "responce":
|
||||
c = init_db()
|
||||
cur = c.cursor()
|
||||
|
||||
match request.method:
|
||||
case "GET":
|
||||
cur.execute("SELECT id, value, question_id, account_id FROM odb.responce;")
|
||||
r = [{"id": i[0], "value": i[1], "question_id": i[2], "account_id": i[3]} for i in cur]
|
||||
c.close()
|
||||
return json.dumps(r)
|
||||
|
||||
case "POST":
|
||||
d = request.get_json()
|
||||
cur.execute(f"INSERT INTO odb.responce (text, question_id, account_id) VALUES (\"{d['value']}\", {d['question_id']}, {d['account_id']});")
|
||||
c.commit()
|
||||
c.close()
|
||||
return '{"success": true}\n'
|
||||
|
||||
case "PUT":
|
||||
d = request.get_json()
|
||||
cur.execute(f"UPDATE odb.responce SET value = \"{d['value']}\", question_id = {d['question_id']}, account_id = {d['account_id']} WHERE id = {d['id']};")
|
||||
c.commit()
|
||||
c.close()
|
||||
return '{"success": true}\n'
|
||||
|
||||
case "DELETE":
|
||||
d = request.get_json()
|
||||
cur.execute(f"SELECT id, value, question_id, account_id FROM odb.responce WHERE id = {d['id']};")
|
||||
r = [{"id": i[0], "value": i[1], "question_id": i[2], "account_id": i[3]} for i in cur]
|
||||
cur.execute(f"DELETE FROM odb.responce WHERE id = {d['id']};")
|
||||
c.commit()
|
||||
c.close()
|
||||
return f'{r}\n'
|
||||
case _:
|
||||
return f"work {c}\n"
|
||||
|
||||
@app.route("/api/survey/<no>", methods = ["GET", "PUT", "DELETE"])
|
||||
def api_numbered(no):
|
||||
c = init_db()
|
||||
cur = c.cursor()
|
||||
|
||||
match request.method:
|
||||
case "GET":
|
||||
cur.execute(f"SELECT id, isPaused, isNamed, name, duration, account_id FROM odb.survey WHERE id = {no};")
|
||||
r = [{"id": i[0], "isPaused": i[1], "isNamed": i[2], "name": i[3], "duration": i[4], "account_id": i[5]} for i in cur]
|
||||
c.close()
|
||||
return json.dumps(r)
|
||||
|
||||
case "PUT":
|
||||
d = request.get_json()
|
||||
cur.execute(f"UPDATE odb.survey SET isPaused = {d['isPaused']}, isNamed = {d['isNamed']}, name = \"{d['name']}\", duration = \"{d['duration']}\" WHERE id = {no};")
|
||||
c.commit()
|
||||
c.close()
|
||||
return '{"success": true}\n'
|
||||
|
||||
case "DELETE":
|
||||
cur.execute(f"SELECT id, isPaused, isNamed, name, duration, account_id FROM odb.survey WHERE id = {no};")
|
||||
r = [{"id": i[0], "isPaused": i[1], "isNamed": i[2], "name": i[3], "duration": i[4], "account_id": i[5]} for i in cur]
|
||||
cur.execute(f"DELETE FROM odb.survey WHERE id = {no};")
|
||||
c.commit()
|
||||
c.close()
|
||||
return f'{r}\n'
|
||||
|
||||
```
|
||||
@@ -1,4 +1,197 @@
|
||||
# Тестування працездатності системи
|
||||
|
||||
*В цьому розділі необхідно вказати засоби тестування, навести вихідні коди тестів та результати тестування.*
|
||||
## Передумови
|
||||
1. Налаштування віртуального середовища
|
||||
```bash
|
||||
python3 -m venv .
|
||||
source bin/activate.fish
|
||||
pip3 install flask mariadb
|
||||
```
|
||||
|
||||
2. Запуск сервера:
|
||||
```bash
|
||||
flask --app server run
|
||||
```
|
||||
|
||||
## Тестування компонентів
|
||||
|
||||
Система має два варіанти передачі індексів: у рядку шляху або в тілі запиту. Перевіримо, як працюють обидва варіанти.
|
||||
|
||||
### /api/survey
|
||||
|
||||
Цей шлях дозволяє використовувати всі 4 HTTP-методи, що використовуються в домовленості REST (GET, POST, PUT, DELETE).
|
||||
Протестуємо кожен з них на практичному прикладі:
|
||||
|
||||
<pre style="
|
||||
color: #ffffff;
|
||||
font-size: 10pt;"
|
||||
>
|
||||
<span style="filter: contrast(70%) brightness(190%);color:lime;">user</span>@debian-laptop <span style="color:lime;">~/D/f/t/f/d/m/e/s/demo</span> (master)> <span style="color:#3333FF;">curl</span><span style="color:dimgray;"></span> <span style="color:aqua;">-s</span><span style="color:dimgray;"></span> <span style="color:aqua;">http://127.0.0.1:5000/api/survey</span><span style="color:dimgray;"></span> <span style="color:lime;">|</span><span style="color:dimgray;"></span> <span style="color:#3333FF;">jq</span><span style="color:dimgray;"></span> <span style="color:aqua;">.</span>
|
||||
<span style="font-weight:bold;">[
|
||||
{
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"id"</span><span style="font-weight:bold;">: </span>1<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isPaused"</span><span style="font-weight:bold;">: </span>0<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isNamed"</span><span style="font-weight:bold;">: </span>0<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"name"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"Test 1"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"duration"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"1w"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"account_id"</span><span style="font-weight:bold;">: </span>10<span style="font-weight:bold;">
|
||||
}</span><span style="font-weight:bold;">,
|
||||
{
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"id"</span><span style="font-weight:bold;">: </span>4<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isPaused"</span><span style="font-weight:bold;">: </span>0<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isNamed"</span><span style="font-weight:bold;">: </span>0<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"name"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"Test 2"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"duration"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"1w"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"account_id"</span><span style="font-weight:bold;">: </span>5<span style="font-weight:bold;">
|
||||
}</span><span style="font-weight:bold;">
|
||||
]</span>
|
||||
<span style="color:dimgray;"></span><span style="filter: contrast(70%) brightness(190%);color:lime;">user</span>@debian-laptop <span style="color:lime;">~/D/f/t/f/d/m/e/s/demo</span> (master)> <span style="color:#3333FF;">curl</span><span style="color:dimgray;"></span> <span style="color:aqua;">-X</span><span style="color:dimgray;"></span> <span style="color:aqua;">POST</span><span style="color:dimgray;"></span> <span style="color:aqua;">-d</span><span style="color:dimgray;"></span> <span style="color:yellow;">'{"isPaused": false, "isNamed": true, "name": "Test 3", "duration": "1w", "account_id": 2}'</span><span style="color:dimgray;"></span> <span style="color:aqua;">--header</span><span style="color:dimgray;"></span> <span style="color:yellow;">"Content-Type: application/json"</span><span style="color:dimgray;"></span> <span style="color:aqua;">http://127.0.0.1:5000/api/survey</span>
|
||||
{"success": true}
|
||||
<span style="color:dimgray;"></span><span style="filter: contrast(70%) brightness(190%);color:lime;">user</span>@debian-laptop <span style="color:lime;">~/D/f/t/f/d/m/e/s/demo</span> (master)> <span style="color:#3333FF;">curl</span><span style="color:dimgray;"></span> <span style="color:aqua;">-s</span><span style="color:dimgray;"></span> <span style="color:aqua;">http://127.0.0.1:5000/api/survey</span><span style="color:dimgray;"></span> <span style="color:lime;">|</span><span style="color:dimgray;"></span> <span style="color:#3333FF;">jq</span><span style="color:dimgray;"></span> <span style="color:aqua;">.</span>
|
||||
<span style="font-weight:bold;">[
|
||||
{
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"id"</span><span style="font-weight:bold;">: </span>1<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isPaused"</span><span style="font-weight:bold;">: </span>0<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isNamed"</span><span style="font-weight:bold;">: </span>0<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"name"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"Test 1"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"duration"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"1w"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"account_id"</span><span style="font-weight:bold;">: </span>10<span style="font-weight:bold;">
|
||||
}</span><span style="font-weight:bold;">,
|
||||
{
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"id"</span><span style="font-weight:bold;">: </span>4<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isPaused"</span><span style="font-weight:bold;">: </span>0<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isNamed"</span><span style="font-weight:bold;">: </span>0<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"name"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"Test 2"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"duration"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"1w"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"account_id"</span><span style="font-weight:bold;">: </span>5<span style="font-weight:bold;">
|
||||
}</span><span style="font-weight:bold;">,
|
||||
{
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"id"</span><span style="font-weight:bold;">: </span>12<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isPaused"</span><span style="font-weight:bold;">: </span>0<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isNamed"</span><span style="font-weight:bold;">: </span>1<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"name"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"Test 3"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"duration"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"1w"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"account_id"</span><span style="font-weight:bold;">: </span>2<span style="font-weight:bold;">
|
||||
}</span><span style="font-weight:bold;">
|
||||
]</span>
|
||||
<span style="color:dimgray;"></span><span style="filter: contrast(70%) brightness(190%);color:lime;">user</span>@debian-laptop <span style="color:lime;">~/D/f/t/f/d/m/e/s/demo</span> (master)> <span style="color:#3333FF;">curl</span><span style="color:dimgray;"></span> <span style="color:aqua;">-X</span><span style="color:dimgray;"></span> <span style="color:aqua;">PUT</span><span style="color:dimgray;"></span> <span style="color:aqua;">-d</span><span style="color:dimgray;"></span> <span style="color:yellow;">'{"id": 8, "isPaused": true, "isNamed": true, "name": "Test 3", "duration": "4w", "account_id": 2}'</span><span style="color:dimgray;"></span> <span style="color:aqua;">--header</span><span style="color:dimgray;"></span> <span style="color:yellow;">"Content-Type: application/json"</span><span style="color:dimgray;"></span> <span style="color:aqua;">http://127.0.0.1:5000/api/survey</span>
|
||||
{"success": true}
|
||||
<span style="color:dimgray;"></span><span style="filter: contrast(70%) brightness(190%);color:lime;">user</span>@debian-laptop <span style="color:lime;">~/D/f/t/f/d/m/e/s/demo</span> (master)> <span style="color:#3333FF;">curl</span><span style="color:dimgray;"></span> <span style="color:aqua;">-s</span><span style="color:dimgray;"></span> <span style="color:aqua;">http://127.0.0.1:5000/api/survey</span><span style="color:dimgray;"></span> <span style="color:lime;">|</span><span style="color:dimgray;"></span> <span style="color:#3333FF;">jq</span><span style="color:dimgray;"></span> <span style="color:aqua;">.</span>
|
||||
<span style="font-weight:bold;">[
|
||||
{
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"id"</span><span style="font-weight:bold;">: </span>1<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isPaused"</span><span style="font-weight:bold;">: </span>0<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isNamed"</span><span style="font-weight:bold;">: </span>0<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"name"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"Test 1"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"duration"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"1w"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"account_id"</span><span style="font-weight:bold;">: </span>10<span style="font-weight:bold;">
|
||||
}</span><span style="font-weight:bold;">,
|
||||
{
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"id"</span><span style="font-weight:bold;">: </span>4<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isPaused"</span><span style="font-weight:bold;">: </span>0<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isNamed"</span><span style="font-weight:bold;">: </span>0<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"name"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"Test 2"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"duration"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"1w"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"account_id"</span><span style="font-weight:bold;">: </span>5<span style="font-weight:bold;">
|
||||
}</span><span style="font-weight:bold;">,
|
||||
{
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"id"</span><span style="font-weight:bold;">: </span>12<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isPaused"</span><span style="font-weight:bold;">: </span>1<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isNamed"</span><span style="font-weight:bold;">: </span>1<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"name"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"Test 3"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"duration"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"4w"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"account_id"</span><span style="font-weight:bold;">: </span>2<span style="font-weight:bold;">
|
||||
}</span><span style="font-weight:bold;">
|
||||
]</span>
|
||||
<span style="color:dimgray;"></span><span style="filter: contrast(70%) brightness(190%);color:lime;">user</span>@debian-laptop <span style="color:lime;">~/D/f/t/f/d/m/e/s/demo</span> (master)> <span style="color:#3333FF;">curl</span><span style="color:dimgray;"></span> <span style="color:aqua;">-X</span><span style="color:dimgray;"></span> <span style="color:aqua;">DELETE</span><span style="color:dimgray;"></span> <span style="color:aqua;">-d</span><span style="color:dimgray;"></span> <span style="color:yellow;">'{"id": 12}'</span><span style="color:dimgray;"></span> <span style="color:aqua;">--header</span><span style="color:dimgray;"></span> <span style="color:yellow;">"Content-Type: application/json"</span><span style="color:dimgray;"></span> <span style="color:aqua;">http://127.0.0.1:5000/api/survey</span>
|
||||
[{'id': 12, 'isPaused': 1, 'isNamed': 1, 'name': 'Test 3', 'duration': '4w', 'account_id': 2}]
|
||||
<span style="color:dimgray;"></span><span style="filter: contrast(70%) brightness(190%);color:lime;">user</span>@debian-laptop <span style="color:lime;">~/D/f/t/f/d/m/e/s/demo</span> (master)> <span style="color:#3333FF;">curl</span><span style="color:dimgray;"></span> <span style="color:aqua;">-s</span><span style="color:dimgray;"></span> <span style="color:aqua;">http://127.0.0.1:5000/api/survey</span><span style="color:dimgray;"></span> <span style="color:lime;">|</span><span style="color:dimgray;"></span> <span style="color:#3333FF;">jq</span><span style="color:dimgray;"></span> <span style="color:aqua;">.</span>
|
||||
<span style="font-weight:bold;">[
|
||||
{
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"id"</span><span style="font-weight:bold;">: </span>1<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isPaused"</span><span style="font-weight:bold;">: </span>0<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isNamed"</span><span style="font-weight:bold;">: </span>0<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"name"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"Test 1"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"duration"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"1w"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"account_id"</span><span style="font-weight:bold;">: </span>10<span style="font-weight:bold;">
|
||||
}</span><span style="font-weight:bold;">,
|
||||
{
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"id"</span><span style="font-weight:bold;">: </span>4<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isPaused"</span><span style="font-weight:bold;">: </span>0<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isNamed"</span><span style="font-weight:bold;">: </span>0<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"name"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"Test 2"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"duration"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"1w"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"account_id"</span><span style="font-weight:bold;">: </span>5<span style="font-weight:bold;">
|
||||
}</span><span style="font-weight:bold;">
|
||||
]</span>
|
||||
</pre>
|
||||
|
||||
### /api/survey/\<id\>
|
||||
|
||||
У цьому випадку доступні лише 3 методи (GET, PUT, DELETE), оскільки під час створення нового опитування його ідентифікатор визначається безпосередньо базою даних.
|
||||
|
||||
<pre style="
|
||||
color: #ffffff;
|
||||
font-size: 10pt;"
|
||||
>
|
||||
<span style="filter: contrast(70%) brightness(190%);color:lime;">user</span>@debian-laptop <span style="color:lime;">~/D/f/t/f/d/m/e/s/restful-server</span> (master)> <span style="color:#3333FF;">curl</span><span style="color:dimgray;"></span> <span style="color:aqua;">-s</span><span style="color:dimgray;"></span> <span style="color:aqua;">http://127.0.0.1:5000/api/survey</span><span style="color:dimgray;"></span> <span style="color:lime;">|</span><span style="color:dimgray;"></span> <span style="color:#3333FF;">jq</span><span style="color:dimgray;"></span> <span style="color:aqua;">.</span>
|
||||
<span style="font-weight:bold;">[
|
||||
{
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"id"</span><span style="font-weight:bold;">: </span>1<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isPaused"</span><span style="font-weight:bold;">: </span>0<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isNamed"</span><span style="font-weight:bold;">: </span>0<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"name"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"Test 1"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"duration"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"1w"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"account_id"</span><span style="font-weight:bold;">: </span>10<span style="font-weight:bold;">
|
||||
}</span><span style="font-weight:bold;">,
|
||||
{
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"id"</span><span style="font-weight:bold;">: </span>4<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isPaused"</span><span style="font-weight:bold;">: </span>0<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isNamed"</span><span style="font-weight:bold;">: </span>1<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"name"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"Test 3"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"duration"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"1w"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"account_id"</span><span style="font-weight:bold;">: </span>5<span style="font-weight:bold;">
|
||||
}</span><span style="font-weight:bold;">
|
||||
]</span>
|
||||
<span style="color:dimgray;"></span><span style="filter: contrast(70%) brightness(190%);color:lime;">user</span>@debian-laptop <span style="color:lime;">~/D/f/t/f/d/m/e/s/restful-server</span> (master)> <span style="color:#3333FF;">curl</span><span style="color:dimgray;"></span> <span style="color:aqua;">-X</span><span style="color:dimgray;"></span> <span style="color:aqua;">PUT</span><span style="color:dimgray;"></span> \
|
||||
<span style="color:aqua;">-d</span><span style="color:dimgray;"></span> <span style="color:yellow;">'{"isPaused": true,
|
||||
"isNamed": true,
|
||||
"name": "Test 4",
|
||||
"duration": "2w"}'</span><span style="color:dimgray;"></span> \
|
||||
<span style="color:aqua;">--header</span><span style="color:dimgray;"></span> <span style="color:yellow;">"Content-Type: application/json"</span><span style="color:dimgray;"></span> \
|
||||
<span style="color:aqua;">-s</span><span style="color:dimgray;"></span> <span style="color:aqua;">http://127.0.0.1:5000/api/survey/4 </span>
|
||||
{"success": true}
|
||||
<span style="color:dimgray;"></span><span style="filter: contrast(70%) brightness(190%);color:lime;">user</span>@debian-laptop <span style="color:lime;">~/D/f/t/f/d/m/e/s/restful-server</span> (master)> </span><span style="color:#3333FF;">curl</span><span style="color:dimgray;"></span> <span style="color:aqua;">-s</span><span style="color:dimgray;"></span> <span style="color:aqua;">http://127.0.0.1:5000/api/survey/4</span><span style="color:dimgray;"></span> <span style="color:lime;">|</span><span style="color:dimgray;"></span> <span style="color:#3333FF;">jq</span><span style="color:dimgray;"></span> <span style="color:aqua;">.</span><span style="color:dimgray;"></span>
|
||||
<span style="font-weight:bold;">[
|
||||
{
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"id"</span><span style="font-weight:bold;">: </span>4<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isPaused"</span><span style="font-weight:bold;">: </span>1<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"isNamed"</span><span style="font-weight:bold;">: </span>1<span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"name"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"Test 4"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"duration"</span><span style="font-weight:bold;">: </span><span style="color:lime;">"2w"</span><span style="font-weight:bold;">,
|
||||
</span><span style="font-weight:bold;color:#3333FF;">"account_id"</span><span style="font-weight:bold;">: </span>5<span style="font-weight:bold;">
|
||||
}</span><span style="font-weight:bold;">
|
||||
]</span>
|
||||
<span style="color:dimgray;"></span><span style="filter: contrast(70%) brightness(190%);color:lime;">user</span>@debian-laptop <span style="color:lime;">~/D/f/t/f/d/m/e/s/restful-server</span> (master)> <span style="color:#3333FF;">curl</span><span style="color:dimgray;"></span> <span style="color:aqua;">-v</span><span style="color:dimgray;"></span> <span style="color:aqua;">-X</span><span style="color:dimgray;"></span> <span style="color:aqua;">DELETE</span><span style="color:dimgray;"></span> <span style="color:aqua;">--header</span><span style="color:dimgray;"></span> <span style="color:yellow;">"Content-Type: application/json"</span><span style="color:dimgray;"></span> <span style="color:aqua;">-d</span><span style="color:dimgray;"></span> <span style="color:yellow;">'{}'</span><span style="color:dimgray;"></span> <span style="color:aqua;">http://127.0.0.1:5000/api/survey/4 </span>
|
||||
* Trying 127.0.0.1:5000...
|
||||
* Connected to 127.0.0.1 (127.0.0.1) port 5000 (#0)
|
||||
> DELETE /api/survey/4 HTTP/1.1
|
||||
> Host: 127.0.0.1:5000
|
||||
> User-Agent: curl/7.88.1
|
||||
> Accept: */*
|
||||
> Content-Type: application/json
|
||||
> Content-Length: 2
|
||||
>
|
||||
< HTTP/1.1 200 OK
|
||||
< Server: Werkzeug/3.0.3 Python/3.11.2
|
||||
< Date: Tue, 21 May 2024 14:45:09 GMT
|
||||
< Content-Type: text/html; charset=utf-8
|
||||
< Content-Length: 94
|
||||
< Connection: close
|
||||
<
|
||||
[{'id': 4, 'isPaused': 1, 'isNamed': 1, 'name': 'Test 4', 'duration': '2w', 'account_id': 5}]
|
||||
* Closing connection 0
|
||||
<span style="color:dimgray;"></span><span style="filter: contrast(70%) brightness(190%);color:lime;">user</span>@debian-laptop <span style="color:lime;">~/D/f/t/f/d/m/e/s/restful-server</span> (master)>
|
||||
</pre>
|
||||
|
||||
Бачимо, що ми можемо отримувати інформацію про окремі опитування, змінювати та видаляти їх.
|
||||
@@ -20,6 +20,6 @@ git commit -m '[automated]: pushing regenerated documentation'
|
||||
# git push -f git@github.com:boldak/<USERNAME>.github.io.git master
|
||||
|
||||
# if you are deploying to https://<USERNAME>.github.io/<REPO>
|
||||
git push -f http://10.1.1.1:3000/hasslesstech/edu-dis-labs master:gh-pages
|
||||
git push -f http://10.1.1.1:3000/hasslesstech/edu-dis-labs-private master:gh-pages
|
||||
|
||||
cd -
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
# програмні коди
|
||||
В цьому розділі розміщені програмні коди.
|
||||
# JS-скрипти
|
||||
|
||||
В цьому розділі розміщені програмні коди javascript.
|
||||
214
src/restful-server/server.py
Normal file
214
src/restful-server/server.py
Normal file
@@ -0,0 +1,214 @@
|
||||
from flask import Flask, request
|
||||
import mariadb as mdb
|
||||
import json
|
||||
import sys
|
||||
|
||||
def init_db():
|
||||
return mdb.connect(host="127.0.0.1", port=3306, user="user", password="testing432")
|
||||
|
||||
c = 0
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route("/api/<endpoint>", methods = ["GET", "POST", "PUT", "DELETE"])
|
||||
def api_test(endpoint):
|
||||
se = endpoint
|
||||
|
||||
match se:
|
||||
case "counter":
|
||||
global c
|
||||
c += 1
|
||||
case "account":
|
||||
c = init_db()
|
||||
cur = c.cursor()
|
||||
|
||||
match request.method:
|
||||
case "GET":
|
||||
cur.execute("SELECT id, username FROM odb.account;")
|
||||
r = [{"id": i, "username": j} for i, j in cur]
|
||||
c.close()
|
||||
return json.dumps(r)
|
||||
case "POST":
|
||||
d = request.get_json()
|
||||
cur.execute(f"INSERT INTO odb.account (username, password) VALUES (\"{d['username']}\", \"{d['password']}\");")
|
||||
c.commit()
|
||||
c.close()
|
||||
return '{"success": true}\n'
|
||||
case "PUT":
|
||||
d = request.get_json()
|
||||
cur.execute(f"UPDATE odb.account SET username = \"{d['username']}\", password = \"{d['password']}\" WHERE id = {d['id']};")
|
||||
c.commit()
|
||||
c.close()
|
||||
return '{"success": true}\n'
|
||||
case "DELETE":
|
||||
d = request.get_json()
|
||||
cur.execute(f"SELECT id, username FROM odb.account WHERE id = {d['id']};")
|
||||
r = [{"id": i, "username": j} for i, j in cur]
|
||||
cur.execute(f"DELETE FROM odb.account WHERE id = {d['id']};")
|
||||
c.commit()
|
||||
c.close()
|
||||
return f'{r}\n'
|
||||
case "survey":
|
||||
c = init_db()
|
||||
cur = c.cursor()
|
||||
|
||||
match request.method:
|
||||
case "GET":
|
||||
cur.execute("SELECT id, isPaused, isNamed, name, duration, account_id FROM odb.survey;")
|
||||
r = [{"id": i[0], "isPaused": i[1], "isNamed": i[2], "name": i[3], "duration": i[4], "account_id": i[5]} for i in cur]
|
||||
c.close()
|
||||
return json.dumps(r)
|
||||
|
||||
case "POST":
|
||||
d = request.get_json()
|
||||
cur.execute(f"INSERT INTO odb.survey (isPaused, isNamed, name, duration, account_id) VALUES ({d['isPaused']}, {d['isNamed']}, \"{d['name']}\", \"{d['duration']}\", {d['account_id']});")
|
||||
c.commit()
|
||||
c.close()
|
||||
return '{"success": true}\n'
|
||||
|
||||
case "PUT":
|
||||
d = request.get_json()
|
||||
cur.execute(f"UPDATE odb.survey SET isPaused = {d['isPaused']}, isNamed = {d['isNamed']}, name = \"{d['name']}\", duration = \"{d['duration']}\" WHERE id = {d['id']};")
|
||||
c.commit()
|
||||
c.close()
|
||||
return '{"success": true}\n'
|
||||
|
||||
case "DELETE":
|
||||
d = request.get_json()
|
||||
cur.execute(f"SELECT id, isPaused, isNamed, name, duration, account_id FROM odb.survey WHERE id = {d['id']};")
|
||||
r = [{"id": i[0], "isPaused": i[1], "isNamed": i[2], "name": i[3], "duration": i[4], "account_id": i[5]} for i in cur]
|
||||
cur.execute(f"DELETE FROM odb.survey WHERE id = {d['id']};")
|
||||
c.commit()
|
||||
c.close()
|
||||
return f'{r}\n'
|
||||
|
||||
case "link":
|
||||
c = init_db()
|
||||
cur = c.cursor()
|
||||
|
||||
match request.method:
|
||||
case "GET":
|
||||
cur.execute("SELECT id, uses, responces, usageLimit, responceLimit, path, survey_id FROM odb.link;")
|
||||
r = [{"id": i[0], "uses": i[1], "responces": i[2], "usageLimit": i[3], "responceLimit": i[4], "path": i[5], "survey_id": i[6]} for i in cur]
|
||||
c.close()
|
||||
return json.dumps(r)
|
||||
|
||||
case "POST":
|
||||
d = request.get_json()
|
||||
cur.execute(f"INSERT INTO odb.link (usageLimit, responceLimit, path, survey_id) VALUES ({d['usageLimit']}, {d['responceLimit']}, \"{d['path']}\", {d['survey_id']});")
|
||||
c.commit()
|
||||
c.close()
|
||||
return '{"success": true}\n'
|
||||
|
||||
case "PUT":
|
||||
d = request.get_json()
|
||||
cur.execute(f"UPDATE odb.link SET uses = {d['uses']}, responces = {d['responces']}, usageLimit = \"{d['usageLimit']}\", responceLimit = \"{d['responceLimit']}\", path = \"{d['path']}\", survey_id = {d['survey_id']} WHERE id = {d['id']};")
|
||||
c.commit()
|
||||
c.close()
|
||||
return '{"success": true}\n'
|
||||
|
||||
case "DELETE":
|
||||
d = request.get_json()
|
||||
cur.execute(f"SELECT id, uses, responces, usageLimit, responceLimit, path, survey_id FROM odb.survey WHERE id = {d['id']};")
|
||||
r = [{"id": i[0], "uses": i[1], "responces": i[2], "usageLimit": i[3], "responceLimit": i[4], "path": i[5], "survey_id": i[6]} for i in cur]
|
||||
cur.execute(f"DELETE FROM odb.link WHERE id = {d['id']};")
|
||||
c.commit()
|
||||
c.close()
|
||||
return f'{r}\n'
|
||||
|
||||
case "question":
|
||||
c = init_db()
|
||||
cur = c.cursor()
|
||||
|
||||
match request.method:
|
||||
case "GET":
|
||||
cur.execute("SELECT id, text, survey_id FROM odb.question;")
|
||||
r = [{"id": i[0], "text": i[1], "survey_id": i[2]} for i in cur]
|
||||
c.close()
|
||||
return json.dumps(r)
|
||||
|
||||
case "POST":
|
||||
d = request.get_json()
|
||||
cur.execute(f"INSERT INTO odb.question (text, survey_id) VALUES (\"{d['text']}\", {d['survey_id']});")
|
||||
c.commit()
|
||||
c.close()
|
||||
return '{"success": true}\n'
|
||||
|
||||
case "PUT":
|
||||
d = request.get_json()
|
||||
cur.execute(f"UPDATE odb.question SET text = \"{d['text']}\", survey_id = {d['survey_id']} WHERE id = {d['id']};")
|
||||
c.commit()
|
||||
c.close()
|
||||
return '{"success": true}\n'
|
||||
|
||||
case "DELETE":
|
||||
d = request.get_json()
|
||||
cur.execute(f"SELECT id, text, survey_id FROM odb.question WHERE id = {d['id']};")
|
||||
r = [{"id": i[0], "text": i[1], "survey_id": i[2]} for i in cur]
|
||||
cur.execute(f"DELETE FROM odb.question WHERE id = {d['id']};")
|
||||
c.commit()
|
||||
c.close()
|
||||
return f'{r}\n'
|
||||
|
||||
case "responce":
|
||||
c = init_db()
|
||||
cur = c.cursor()
|
||||
|
||||
match request.method:
|
||||
case "GET":
|
||||
cur.execute("SELECT id, value, question_id, account_id FROM odb.responce;")
|
||||
r = [{"id": i[0], "value": i[1], "question_id": i[2], "account_id": i[3]} for i in cur]
|
||||
c.close()
|
||||
return json.dumps(r)
|
||||
|
||||
case "POST":
|
||||
d = request.get_json()
|
||||
cur.execute(f"INSERT INTO odb.responce (text, question_id, account_id) VALUES (\"{d['value']}\", {d['question_id']}, {d['account_id']});")
|
||||
c.commit()
|
||||
c.close()
|
||||
return '{"success": true}\n'
|
||||
|
||||
case "PUT":
|
||||
d = request.get_json()
|
||||
cur.execute(f"UPDATE odb.responce SET value = \"{d['value']}\", question_id = {d['question_id']}, account_id = {d['account_id']} WHERE id = {d['id']};")
|
||||
c.commit()
|
||||
c.close()
|
||||
return '{"success": true}\n'
|
||||
|
||||
case "DELETE":
|
||||
d = request.get_json()
|
||||
cur.execute(f"SELECT id, value, question_id, account_id FROM odb.responce WHERE id = {d['id']};")
|
||||
r = [{"id": i[0], "value": i[1], "question_id": i[2], "account_id": i[3]} for i in cur]
|
||||
cur.execute(f"DELETE FROM odb.responce WHERE id = {d['id']};")
|
||||
c.commit()
|
||||
c.close()
|
||||
return f'{r}\n'
|
||||
case _:
|
||||
return f"work {c}\n"
|
||||
|
||||
@app.route("/api/survey/<no>", methods = ["GET", "PUT", "DELETE"])
|
||||
def api_numbered(no):
|
||||
c = init_db()
|
||||
cur = c.cursor()
|
||||
|
||||
match request.method:
|
||||
case "GET":
|
||||
cur.execute(f"SELECT id, isPaused, isNamed, name, duration, account_id FROM odb.survey WHERE id = {no};")
|
||||
r = [{"id": i[0], "isPaused": i[1], "isNamed": i[2], "name": i[3], "duration": i[4], "account_id": i[5]} for i in cur]
|
||||
c.close()
|
||||
return json.dumps(r)
|
||||
|
||||
case "PUT":
|
||||
d = request.get_json()
|
||||
cur.execute(f"UPDATE odb.survey SET isPaused = {d['isPaused']}, isNamed = {d['isNamed']}, name = \"{d['name']}\", duration = \"{d['duration']}\" WHERE id = {no};")
|
||||
c.commit()
|
||||
c.close()
|
||||
return '{"success": true}\n'
|
||||
|
||||
case "DELETE":
|
||||
cur.execute(f"SELECT id, isPaused, isNamed, name, duration, account_id FROM odb.survey WHERE id = {no};")
|
||||
r = [{"id": i[0], "isPaused": i[1], "isNamed": i[2], "name": i[3], "duration": i[4], "account_id": i[5]} for i in cur]
|
||||
cur.execute(f"DELETE FROM odb.survey WHERE id = {no};")
|
||||
c.commit()
|
||||
c.close()
|
||||
return f'{r}\n'
|
||||
3
src/sql/README.md
Normal file
3
src/sql/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# SQL-скрипти
|
||||
|
||||
В цьому розділі розміщені сирцеві коди для створення бази даних.
|
||||
107
src/sql/script.sql
Normal file
107
src/sql/script.sql
Normal file
@@ -0,0 +1,107 @@
|
||||
-- MySQL Workbench Forward Engineering
|
||||
|
||||
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
|
||||
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
|
||||
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Schema mydb
|
||||
-- -----------------------------------------------------
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Schema mydb
|
||||
-- -----------------------------------------------------
|
||||
CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 ;
|
||||
USE `mydb` ;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `mydb`.`Account`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `mydb`.`Account` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`username` CHAR(255) NOT NULL,
|
||||
`password` CHAR(255) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE INDEX `id_UNIQUE` (`id` ASC) VISIBLE,
|
||||
UNIQUE INDEX `username_UNIQUE` (`username` ASC) VISIBLE)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `mydb`.`Survey`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `mydb`.`Survey` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`isPaused` TINYINT UNSIGNED NOT NULL,
|
||||
`isNamed` TINYINT UNSIGNED NOT NULL,
|
||||
`name` CHAR(255) NULL,
|
||||
`duration` CHAR(255) NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE INDEX `id_UNIQUE` (`id` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_Survey_Account1`
|
||||
FOREIGN KEY (`id`)
|
||||
REFERENCES `mydb`.`Account` (`id`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `mydb`.`Question`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `mydb`.`Question` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`Text` CHAR(255) NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE INDEX `id_UNIQUE` (`id` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_Question_Survey1`
|
||||
FOREIGN KEY (`id`)
|
||||
REFERENCES `mydb`.`Survey` (`id`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `mydb`.`Response`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `mydb`.`Response` (
|
||||
`id` INT UNSIGNED NULL AUTO_INCREMENT,
|
||||
`Value` VARCHAR(16384) NULL,
|
||||
UNIQUE INDEX `id_UNIQUE` (`id` ASC) VISIBLE,
|
||||
PRIMARY KEY (`id`),
|
||||
CONSTRAINT `fk_Response_Question`
|
||||
FOREIGN KEY (`id`)
|
||||
REFERENCES `mydb`.`Question` (`id`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `fk_Response_Account1`
|
||||
FOREIGN KEY (`id`)
|
||||
REFERENCES `mydb`.`Account` (`id`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `mydb`.`Link`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `mydb`.`Link` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`uses` INT NOT NULL,
|
||||
`responces` INT NOT NULL,
|
||||
`usageLimit` INT NULL,
|
||||
`responceLimit` INT NULL,
|
||||
`path` CHAR(32) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
CONSTRAINT `fk_Link_Survey1`
|
||||
FOREIGN KEY (`id`)
|
||||
REFERENCES `mydb`.`Survey` (`id`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
SET SQL_MODE=@OLD_SQL_MODE;
|
||||
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
|
||||
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
|
||||
Reference in New Issue
Block a user