diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index c0d2c6d..03824b0 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -15,7 +15,7 @@ module.exports = { }] ], port: 3030, - base: '/edu-dis-labs/', + base: '/OBD-lab6/', theme: 'cool', // dest: 'dist', head: [ @@ -66,12 +66,6 @@ module.exports = { title: 'Висновки', path:"/conclusion/" }, - - { - title: 'API', - path:"/api/" - } - ], sidebarDepth: 2, displayAllHeaders: true, // Default: false diff --git a/docs/README.md b/docs/README.md index cb7c880..1749cb2 100644 --- a/docs/README.md +++ b/docs/README.md @@ -6,23 +6,12 @@ actionLink: /intro/ footer: "ECL 2.0 Licensed | Copyright © 2024 [Your Name]" --- -**Виконали:** +**Виконав:** -*студенти 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)]* +*студент 2-го курсу, групи ІО-23:* *Євгеній ГОЛОВАТЕНКО [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)]* **Керівник** diff --git a/docs/software/README.md b/docs/software/README.md index bef4c7c..225ec7d 100644 --- a/docs/software/README.md +++ b/docs/software/README.md @@ -110,4 +110,147 @@ ENGINE = InnoDB; SET SQL_MODE=@OLD_SQL_MODE; SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; -``` \ No newline at end of file +``` + +## Програмний код RESTful-сервісу + +```python +from flask import Flask, request, jsonify +import mysql.connector +from mysql.connector import Error +from db_config import db_config + +app = Flask(name) + + +def get_db_connection(): + try: + conn = mysql.connector.connect(**db_config) + return conn + except Error as e: + return jsonify({"error": f"Error in connection to database: {str(e)}"}), 500 + + +@app.route('/links', methods=['GET']) +def get_links(): + try: + conn = get_db_connection() + if isinstance(conn, tuple): + return conn + cursor = conn.cursor(dictionary=True) + cursor.execute('SELECT * FROM link') + links = cursor.fetchall() + cursor.close() + conn.close() + return jsonify(links) + except Error as e: + return jsonify({"error": f"Error getting data: {str(e)}"}), 500 + + +@app.route('/link/', methods=['GET']) +def get_link(): + try: + conn = get_db_connection() + if isinstance(conn, tuple): + return conn + cursor = conn.cursor(dictionary=True) + cursor.execute('SELECT * FROM link WHERE id = %s', [1]) + link = cursor.fetchone() + cursor.close() + conn.close() + if link is None: + return jsonify({"error": "Link is not found"}), 404 + return jsonify(link) + except Error as e: + return jsonify({"error": f"Error getting data: {str(e)}"}), 500 + + +@app.route('/link', methods=['POST']) +def create_link(): + try: + new_link = request.json + conn = get_db_connection() + if isinstance(conn, tuple): + return conn + cursor = conn.cursor() + + cursor.execute(''' + INSERT INTO link (uses, responses, usageLimit, responseLimit, path, Survey_id) + VALUES (%s, %s, %s, %s, %s, %s) + ''', ( + new_link.get('uses'), + new_link.get('responses'), + new_link.get('usageLimit'), + new_link.get('responseLimit'), + new_link.get('path'), + new_link.get('Survey_id') + )) + + conn.commit() + cursor.close() + conn.close() + return jsonify({"success": "Link created successfully", "data": new_link}), 201 + except Error as e: + return jsonify({"error": f"Error creating link: {str(e)}"}), 500 + + +@app.route('/link/', methods=['PUT']) +def update_link(): + try: + update_link = request.json + conn = get_db_connection() + if isinstance(conn, tuple): + return conn + cursor = conn.cursor() + + cursor.execute(''' + UPDATE link SET + uses = %s, + responses = %s, + usageLimit = %s, + responseLimit = %s, + path = %s, + Survey_id = %s + WHERE id = %s + ''', ( + update_link.get('uses'), + update_link.get('responses'), + update_link.get('usageLimit'), + update_link.get('responseLimit'), + update_link.get('path'), + update_link.get('Survey_id'), + id + )) + + conn.commit() + cursor.close() + conn.close() + if cursor.rowcount == 0: + return jsonify({"error": f"Update error: link is not found"}), 404 + else: + return jsonify({"success": f"Link from ID {id} updated successfully", "data": update_link}), 202 + except Error as e: + return jsonify({"error": f"Error updating link: {str(e)}"}), 500 + +@app.route('/link/', methods=['DELETE']) +def delete_link(): + try: + conn = get_db_connection() + if isinstance(conn, tuple): + return conn + cursor = conn.cursor() + cursor.execute('DELETE FROM Link WHERE id = %s', [1]) + conn.commit() + cursor.close() + conn.close() + if cursor.rowcount == 0: + return jsonify({"error": f"Delete error: link is not found"}), 404 + else: + return jsonify({"success": f"Link from ID {id} deleted successfully"}), 200 + except Error as e: + return jsonify({"error": f"Error deleting link: {str(e)}"}), 500 + + +if name == 'main': + app.run(debug=False) +``` diff --git a/docs/test/README.md b/docs/test/README.md index 4cf2563..316bbd2 100644 --- a/docs/test/README.md +++ b/docs/test/README.md @@ -1,4 +1,93 @@ # Тестування працездатності системи -*В цьому розділі необхідно вказати засоби тестування, навести вихідні коди тестів та результати тестування.* +## Обробка запитів з методом GET +
+ +![](./img/photo_2024-06-06_18-23-41.jpg) + +
+ +
+ +![](./img/photo_2024-06-06_18-23-49.jpg) + +
+ +
+ +![](./img/photo_2024-06-06_18-23-52.jpg) + +
+ +
+ +![](./img/photo_2024-06-06_18-23-55.jpg) + +
+ +## Обробка запитів з методом POST + +
+ +![](./img/photo_2024-06-06_18-23-46.jpg) + +
+ +## Обробка запитів з методом PUT + +
+ +![](./img/photo_2024-06-06_18-24-01.jpg) + +
+ +## Обробка запитів з методом DELETE + +
+ +![](./img/photo_2024-06-06_18-23-57.jpg) + +
diff --git a/docs/test/img/photo_2024-06-06_18-23-41.jpg b/docs/test/img/photo_2024-06-06_18-23-41.jpg new file mode 100644 index 0000000..059adc6 Binary files /dev/null and b/docs/test/img/photo_2024-06-06_18-23-41.jpg differ diff --git a/docs/test/img/photo_2024-06-06_18-23-46.jpg b/docs/test/img/photo_2024-06-06_18-23-46.jpg new file mode 100644 index 0000000..ecc5ec4 Binary files /dev/null and b/docs/test/img/photo_2024-06-06_18-23-46.jpg differ diff --git a/docs/test/img/photo_2024-06-06_18-23-49.jpg b/docs/test/img/photo_2024-06-06_18-23-49.jpg new file mode 100644 index 0000000..c5aa11d Binary files /dev/null and b/docs/test/img/photo_2024-06-06_18-23-49.jpg differ diff --git a/docs/test/img/photo_2024-06-06_18-23-52.jpg b/docs/test/img/photo_2024-06-06_18-23-52.jpg new file mode 100644 index 0000000..6a17dce Binary files /dev/null and b/docs/test/img/photo_2024-06-06_18-23-52.jpg differ diff --git a/docs/test/img/photo_2024-06-06_18-23-55.jpg b/docs/test/img/photo_2024-06-06_18-23-55.jpg new file mode 100644 index 0000000..6ad1c41 Binary files /dev/null and b/docs/test/img/photo_2024-06-06_18-23-55.jpg differ diff --git a/docs/test/img/photo_2024-06-06_18-23-57.jpg b/docs/test/img/photo_2024-06-06_18-23-57.jpg new file mode 100644 index 0000000..5187825 Binary files /dev/null and b/docs/test/img/photo_2024-06-06_18-23-57.jpg differ diff --git a/docs/test/img/photo_2024-06-06_18-24-01.jpg b/docs/test/img/photo_2024-06-06_18-24-01.jpg new file mode 100644 index 0000000..558939d Binary files /dev/null and b/docs/test/img/photo_2024-06-06_18-24-01.jpg differ diff --git a/publish.sh b/publish.sh index 68af665..84c3519 100755 --- a/publish.sh +++ b/publish.sh @@ -20,6 +20,6 @@ git commit -m '[automated]: pushing regenerated documentation' # git push -f git@github.com:boldak/.github.io.git master # if you are deploying to https://.github.io/ -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/EugenIO/edu-dis-labs master:gh-pages cd -