Запил документации: API и настройка БД

This commit is contained in:
2023-08-05 06:26:09 +03:00
parent d30c4f011d
commit acede7d03b
5 changed files with 55 additions and 6 deletions

40
docs/API.md Normal file
View File

@@ -0,0 +1,40 @@
# API structure
## GET vs. POST
Some parts of API accepts both GET and POST type requests. We recommend you to prefer second option, when it's possible, just because it is more private, when used with SSL or Tor. However, authentification and authenticated requests can be performed **only** with POST.
## Naming conventions
Files starting from "_" ("_example.php") are intended for internal use only.
## Version 1
- _db.php: connection to database and all related
- _auth.php: things related to authentification
- stats.php (GET/POST): all general statistics about this instance
- admin/ (POST): private statistics about this instance
- admin/dbview.php (POST): manage databases
- admin/nukelock.php (POST): emergency "red button" to lock all operations to read-only mode
- user/ (GET/POST): get user information by id
- user/list.php (GET/POST): get list of all users
- user/create.php (POST): create new user account
- user/edit.php (POST): edit user profile
- user/delete.php (POST): delete user account
- post/ (GET/POST): get single post by id
- post/list.php (GET/POST): get list of posts from range
- post/create.php (POST): create new post with image
- post/edit.php (POST): edit tags of post
- post/delete.php (POST): delete post
- post/vote.php (POST): rate the existing post
- comments/ (GET/POST): show all comments from section by id
- comments/create.php (POST): create new comment at selected section
- comments/edit.php (POST): edit existing comment
- comments/delete.php (POST): remove existing comment

38
docs/DB.md Normal file
View File

@@ -0,0 +1,38 @@
# Databases
## How to setup DB
We are using MariaDB, but any MySQL-compatible database should be enough. There are instructions how to setup it for using with E949.
```bash
mysql -u root -p
```
```mysql
CREATE USER e949@localhost IDENTIFIED BY 'password';
CREATE DATABASE e949 CHARACTER SET = 'utf8';
GRANT ALL PRIVILEGES ON e949.* TO e949@localhost;
FLUSH PRIVILEGES;
EXIT
```
```bash
mysql -u e949 -p
```
```mysql
USE e949;
CREATE TABLE posts (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'Unique identifier of post',
author_id BIGINT UNSIGNED NOT NULL COMMENT 'Identifier of post author',
comment_section_id BIGINT UNSIGNED NULL COMMENT 'Identifier of post comment section',
posted_at TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT 'When post was published',
tags VARCHAR(2048) NOT NULL COMMENT 'Comma-delimited list of post tags',
title VARCHAR(8192) NULL COMMENT 'Caption for the post',
votes_up INT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Amount of positive reactions',
votes_down INT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Amount of negative reactions',
views BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Amount of post views',
pic_path VARCHAR(256) NOT NULL COMMENT 'Path or URL of picture',
preview_path VARCHAR(256) NULL COMMENT 'Path or URL of preview version of picture'
);
```

View File

@@ -1,4 +1,6 @@
# Repo Directory Structure
**api**: E949 PHP API
**docs**: all documentation here
**html_drafts**: peaces of html markup
<!--**html_drafts**: peaces of html markup-->
**front**: things for frontend, like CSS