Giter VIP home page Giter VIP logo

post-server's Introduction

post-server

Haskell CI

The REST-API is an HTTP-based interface. The response contains a JSON object

Project Description:

  • Using Warp as Web-server;
  • Using PostgreSQL as BD;
  • The response contains a JSON object;
  • Supports 4 levels of logging:
    • error-level(default): show only error messages;
    • warning-level: show only error and warning messages;
    • info-level: show info, error and warning messages;
    • debug-level: show even more details than info-level;

Installation:

You may clone GitHub repository

git clone https://github.com/LyuPo7/post-server.git

Create BD:

Project uses PostgreSQL as BD. Before use server you'll need to setup BD;

  1. Install PostgreSQL BD (https://www.postgresqltutorial.com/install-postgresql-linux/)
  2. Create PostgreSQL BD user:
    • sudo su - postgres # create super user postgres;
    • psql #connect the database;
    • CREATE ROLE your_username WITH LOGIN CREATEDB ENCRYPTED PASSWORD 'your_password'; #create user with password (option CREATEDB enable to create dbbase);
  3. Create PostgreSQL BD:
    • su 'your_username' # switch to user account (for which was created PostgreSQL user in previous step);
    • createdb 'dbName' #connect the database;
  4. Using PostgreSQL BD in data/config.json:
    • Use 'dbName' for field db_settings.dbName;
    • Use 'your_username' for field db_settings.user;
    • Use 'your_password' for field db_settings.password;

How to use?

  1. Setup 'data/config.json'

    (for example see config-json-file: 'data/config_example.json')
    • "logger_settings"
      • "verbocity": [Optional]-[String] level of logging - must be one of ["debug", "info", "warning", "error"] By default will be use "info" level;
    • "db_settings"
      • "dbName": [Required]-[String] dbname of PostgreSQL DB using for Server;
      • "user": [Required]-[String] user-owner of PostgreSQL DB using for Server;
      • "password": [Required]-[String] user-password of PostgreSQL DB using for Server;
      • "admins": [Required]-[Array of String] List of admins;
    • "server_settings"
      • "host": [Required]-[String] Server host;
      • "port": [Optional]-[String] Server port;
  2. Since bot use PostgreSQL You'll need check if you have installed PostgreSQL in your system (if not - use):

      $ sudo apt-get update -y && sudo apt-get install libpq-dev postgresql -y
  3. Build project using stack:

      $ stack build
  4. Run project using stack:

      $ stack exec post-server-exe

    For more information see asciinema below:

Making requests

  • All supported requests contain in 'data/curl/'
    • Every directory contains executables .sh scripts for supported requests;
    • For unicode symbols in requests using .sh scripts use folowing:
      • Whitespace: %20
      • Left square parenthesis "[": %5B
      • Right square parenthesis "[": %5D
  • Supported requests:
    • Account:
      • login:
        • Use this method to get new Token for User by login;
        • Request: http://HOST:PORT/publishDraft?PARAMETERS
        • Parameter Type Required Description
          password String Yes User's password
          login String Yes User's login
        • Curl:
          • Script location: 'data/curl/account/login.sh'
          • Usage (from 'data/curl/account/'): '$ ./login.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -k User password;
            • -n User login;
        • Response:
          • Success: JSON TextResponse object;
          • Fail: JSON TextResponse object with text error;
    • User:
      • getUsers:
        • Use this method to get all User records;
        • This method is available for all registered Users;
        • In one request You may recieve maximum 50 records;
        • For recieve more than 50 records You'll need to use several requests with different offset;
        • Request: http://HOST:PORT/getUsers?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token
          offset Integer Yes Offset from first User's record (ordered by User's id). Must be >=0
        • Curl:
          • Script location: 'data/curl/user/getUsers.sh'
          • Usage (from 'data/curl/user/'): '$ ./getUsers.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token;
            • -o Offset from the first record (ordered by User's id);
        • Response:
          • Success: JSON UserResponse object;
          • Fail: JSON TextResponse object with text error;
      • createUser:
        • Use this method to register new User;
        • This method is available for all;
        • Request: http://HOST:PORT/createUser?PARAMETERS
        • Parameter Type Required Description
          first_name String Yes User's first name
          last_name String Yes User's last name
          login String Yes User's login
          password String Yes User's password
        • Curl:
          • Script location: 'data/curl/user/createUser.sh'
          • Usage (from 'data/curl/user/'): '$ ./createUser.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -f User's first name;
            • -l User's last name;
            • -k User's password;
            • -n User's login;
        • Response:
          • Success: JSON TextResponse object with text success;
          • Fail: JSON TextResponse object with text error;
      • setUserPhoto:
        • Use this method to set Photo for User;
        • This method is available only for User-account owner;
        • Request: http://HOST:PORT/setUserPhoto?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. For successful request account and token must belong to the same User
          path String Yes Local path to photo
        • Curl:
          • Script location: 'data/curl/user/setUserPhoto.sh'
          • Usage (from 'data/curl/user/'): '$ ./setUserPhoto.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token;
            • -l Path to photo;
        • Response:
          • Success: JSON TextResponse object with text success;
          • Fail:
            • If User's token includes required permissions: JSON TextResponse object with text success;
            • If User's token doesn't includes required permissions: JSON TextResponse object with text error;
      • removeUser:
        • Use this method to remove User;
        • This method is available only for admins;
        • Request: http://HOST:PORT/removeUser?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. Token of User making request. For successful request User must have Admin Permissions
          id String Yes User's id (User's to remove)
        • Curl:
          • Script location: 'data/curl/user/removeUser.sh'
          • Usage (from 'data/curl/user/'): '$ ./removeUser.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token. Token of User making request. For successful request User must have Admin Permissions;
            • -i User's id (User's to remove)
        • Response:
          • Success: JSON TextResponse object with text success;
          • Fail:
            • If User's token includes required permissions: JSON TextResponse object with text success;
            • If User's token doesn't includes required permissions: JSON TextResponse object with text error;
    • Author:
      • getAuthors:
        • Use this method to get all Author records;
        • This method is available only for admins;
        • In one request You may recieve maximum 50 records;
        • For recieve more than 50 records You'll need to use several requests with different offset;
        • Request: http://HOST:PORT/getAuthors?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. Token of User making request. For successful request User must have Admin Permissions
          offset Integer Yes Offset from first Author's record (ordered by Author's id). Must be >=0
        • Curl:
          • Script location: 'data/curl/author/getAuthors.sh'
          • Usage (from 'data/curl/author/'): '$ ./getAuthors.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token. Token of User making request. For successful request User must have Admin Permissions;
            • -o Offset from first Author's record (ordered by Author's id);
        • Response:
          • Success: JSON AuthorResponse object;
          • Fail:
            • If User's token includes required permissions: JSON TextResponse object with text success;
            • If User's token doesn't includes required permissions: JSON TextResponse object with text error;
      • createAuthor:
        • Use this method to create new Author of already existed User;
        • This method is available only for admins;
        • Request: http://HOST:PORT/createAuthor?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. Token of User making request. For successful request User must have Admin Permissions
          id Integer Yes User's id (for Author creation)
          description String Yes Author's description
        • Curl:
          • Script location: 'data/curl/author/createAuthor.sh'
          • Usage (from 'data/curl/author/'): '$ ./createAuthor.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token. Token of User making request. For successful request User must have Admin Permissions;
            • -i User's id (for Author creation);
            • -d Author's description;
        • Response:
          • Success: JSON TextResponse object with text success;
          • Fail:
            • If User's token includes required permissions: JSON TextResponse object with text success;
            • If User's token doesn't includes required permissions: JSON TextResponse object with text error;
      • editAuthor:
        • Use this method to edit Author's description;
        • This method is available only for admins;
        • Request: http://HOST:PORT/editAuthor?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. Token of User making request. For successful request User must have Admin Permissions
          id Integer Yes User's id (corresponding to proper Author)
          description String Yes New Author's description
        • Curl:
          • Script location: 'data/curl/author/editAuthor.sh'
          • Usage (from 'data/curl/author/'): '$ ./editAuthor.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token. Token of User making request. For successful request User must have Admin Permissions;
            • -i User's id (corresponding to proper Author);
            • -d New Author's description;
        • Response:
          • Success: JSON TextResponse object with text success;
          • Fail:
            • If User's token includes required permissions: JSON TextResponse object with text success;
            • If User's token doesn't includes required permissions: JSON TextResponse object with text error;
      • removeAuthor:
        • Use this method to remove Author. If Author has Posts it's imposible to remove his record. Firstly You'll need to remove all his Posts;
        • This method is available only for admins;
        • Request: http://HOST:PORT/removeAuthor?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. Token of User making request. For successful request User must have Admin Permissions
          id Integer Yes User's id (corresponding to proper Author)
        • Curl:
          • Script location: 'data/curl/authors/removeAuthor.sh'
          • Usage: '$ ./removeAuthor.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token. Token of User making request. For successful request User must have Admin Permissions;
            • -i User's id (corresponding to proper Author);
        • Response:
          • Success: JSON TextResponse object with text success;
          • Fail:
            • If User's token includes required permissions: JSON TextResponse object with text success;
            • If User's token doesn't includes required permissions: JSON TextResponse object with text error;
    • Category:
      • getCategories:
        • Use this method to get all Category records;
        • This method is available for all registered Users;
        • In one request You may recieve maximum 50 records;
        • For recieve more than 50 records You'll need to use several requests with different offset;
        • Request: http://HOST:PORT/getCategories?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. Token of User making request
          offset Integer Yes Offset from first Category's record (ordered by Category's id). Must be >=0
        • Curl:
          • Script location: 'data/curl/category/getCategories.sh'
          • Usage (from 'data/curl/category/'): '$ ./getCategories.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token. Token of User making request;
            • -o Offset from first Category's record (ordered by Category's id);
        • Response:
          • Success: JSON CategoryResponse object;
          • Fail:
            • If User's token includes required permissions: JSON TextResponse object with text success;
            • If User's token doesn't includes required permissions: JSON TextResponse object with text error;
      • createCategory:
        • Use this method to create new Category. Category's title and SubCategory's title can't be the same;
        • This method is available only for admins;
        • Request: http://HOST:PORT/createCategory?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. Token of User making request. For successful request User must have Admin Permissions
          title String Yes Category's title
          subcategory String Optional SubCategory's title (if Category expects to have one)
        • Curl:
          • Script location: 'data/curl/category/createCategory.sh'
          • Usage (from 'data/curl/category/'): '$ ./createCategory.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token. Token of User making request. For successful request User must have Admin Permissions;
            • -n Category's title;
            • [-s] SubCategory's title (if Category expects to have one);
        • Response:
          • Success: JSON TextResponse object with text success;
          • Fail:
            • If User's token includes required permissions: JSON TextResponse object with text success;
            • If User's token doesn't includes required permissions: JSON TextResponse object with text error;
      • editCategory:
        • Use this method to edit Category's title, Category's subCategory or both. Category's title and SubCategory's title can't be the same. The SubCategory's title using for request already must exists. You can't use for Category title, title what already exists;
        • This method is available only for admins;
        • Request: http://HOST:PORT/editCategory?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. Token of User making request. For successful request User must have Admin Permissions
          id Integer Yes Category's id
          title String Optional New Category's title (if You want to change Category's title)
          subcategory String Optional SubCategory's title (if You want to change/set SubCategory of Category)
        • Curl:
          • Script location: 'data/curl/category/editCategory.sh'
          • Usage (from 'data/curl/category/'): '$ ./editCategory.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token. Token of User making request. For successful request User must have Admin Permissions;
            • -i Category's id;
            • [-s] SubCategory's title (if You want to change/set SubCategory of Category);
            • [-n] New Category's title (if You want to change Category's title);
        • Response:
          • Success: JSON TextResponse object with text success;
          • Fail:
            • If User's token includes required permissions: JSON TextResponse object with text success;
            • If User's token doesn't includes required permissions: JSON TextResponse object with text error;
      • removeCategory:
        • Use this method to remove Category. If Category is used for Posts it's imposible to remove his record. Firstly You'll need to remove all Posts which included thic Category;
        • This method is available only for admins;
        • Request: http://HOST:PORT/removeCategory?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. Token of User making request. For successful request User must have Admin Permissions
          id Integer Yes Category's id
        • Curl:
          • Script location: 'data/curl/category/removeCategory.sh'
          • Usage (from 'data/curl/category/'): '$ ./removeCategory.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token. Token of User making request. For successful request User must have Admin Permissions;
            • -i Category's id;
        • Response:
          • Success: JSON TextResponse object with text success;
          • Fail:
            • If User's token includes required permissions: JSON TextResponse object with text success;
            • If User's token doesn't includes required permissions: JSON TextResponse object with text error;
    • Tag:
      • getTags:
        • Use this method to get all Tag records;
        • This method is available for all registered Users;
        • In one request You may recieve maximum 50 records;
        • For recieve more than 50 records You'll need to use several requests with different offset;
        • Request: http://HOST:PORT/getTags?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. Token of User making request
          offset Integer Yes Offset from first Tag's record (ordered by Tag's id). Must be >=0
        • Curl:
          • Script location: 'data/curl/tag/getTags.sh'
          • Usage (from 'data/curl/tag/'): '$ ./getTags.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token. Token of User making request;
            • -o Offset from first Tag's record (ordered by Tag's id);
        • Response:
          • Success: JSON TagResponse object;
          • Fail:
            • If User's token includes required permissions: JSON TextResponse object with text success;
            • If User's token doesn't includes required permissions: JSON TextResponse object with text error;
      • createTag:
        • Use this method to create new Tag;
        • This method is available only for admins;
        • Request: http://HOST:PORT/createTag?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. Token of User making request. For successful request User must have Admin Permissions
          title String Yes Tag's title
        • Curl:
          • Script location: 'data/curl/tag/createTag.sh'
          • Usage (from 'data/curl/tag/'): '$ ./createTag.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token. Token of User making request. For successful request User must have Admin Permissions;
            • -n Tag's title;
        • Response:
          • Success: JSON TextResponse object with text success;
          • Fail:
            • If User's token includes required permissions: JSON TextResponse object with text success;
            • If User's token doesn't includes required permissions: JSON TextResponse object with text error;
      • editTag:
        • Use this method to edit Tag's title;
        • This method is available only for admins;
        • Request: http://HOST:PORT/editTag?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. Token of User making request. For successful request User must have Admin Permissions
          new_title String Yes New Tag's title
          old_title String Yes Old Tag's title
        • Curl:
          • Script location: 'data/curl/tag/editTag.sh'
          • Usage (from 'data/curl/tag/'): '$ ./editTag.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token. Token of User making request. For successful request User must have Admin Permissions;
            • -n New Tag's title;
            • -o Old Tag's title;
        • Response:
          • Success: JSON TextResponse object with text success;
          • Fail:
            • If User's token includes required permissions: JSON TextResponse object with text success;
            • If User's token doesn't includes required permissions: JSON TextResponse object with text error;
      • removeTag:
        • Use this method to remove Tag. If Tag is used for Posts it'll be remove from all Posts records;
        • This method is available only for admins;
        • Request: http://HOST:PORT/removeTag?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. Token of User making request. For successful request User must have Admin Permissions
          title String Yes Tag's title
        • Curl:
          • Script location: 'data/curl/tag/removeTag.sh'
          • Usage: '$ ./removeTag.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token. Token of User making request. For successful request User must have Admin Permissions
            • -n Tag's title;
        • Response:
          • Success: JSON TextResponse object with text success;
          • Fail:
            • If User's token includes required permissions: JSON TextResponse object with text success;
            • If User's token doesn't includes required permissions: JSON TextResponse object with text error;
    • Post:
      • getPosts:
        • Use this method to get all Posts records. This method supports:
          • Ordering by:
            • Date of Post creation;
            • Author of Post;
            • Category's title;
            • Number of photos in Post;
          • Search only in Post's text;
          • Search only in Post's title;
          • Search in Post's title/Post's text/Author's First name and Author's Last name/Category's title Tag's title;
          • Search with exact Category's id;
          • Search with exact Tag's id;
          • Search Posts with Tag's Id ONE of [tag_id];
          • Search Posts with Tag's Id ALL in [tag_id];
          • Search Posts by Author name (must contain 'first_name' and 'last_name' separated by whitespace.");
          • Search Posts with exact date of creation;
          • Search Posts created later than specified date;
          • Search Posts created earlier than specified date;
        • This method is available for all registered Users;
        • In one request You may recieve maximum 50 records;
        • For recieve more than 50 records You'll need to use several requests with different offset;
        • Request: http://HOST:PORT/getPosts?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. Token of User making request
          offset Integer Yes Offset from first Post's record corresponding to request options (ordered by Post's id). Must be >=0
          order_by_date - Optional Using by default. Activate order by date of Post creation. For activate use in query string: "order_by_date=true"
          order_by_author - Optional Activate order by Author of Post. For activate use in query string: "order_by_author=true" (by default using 'order_by_date')
          order_by_category - Optional Activate order by Category's title. For activate use in query string: "order_by_category=true" (by default using 'order_by_date')
          order_by_photo - Optional Activate order by number of photos in Post. For activate use in query string: "order_by_photo=true" (by default using 'order_by_date')
          find_in_title String with wildcards Optional Find string for search in Post's title (Sting may use wildcards - for more info see Appendix A)
          find_in_text String with wildcards Optional Find string for search in Post's text (Sting may use wildcards - for more info see Appendix A)
          find String with wildcards Optional Find string for search in (Post's title and Post's text) & (Author's First name and Author's Last name) & (Category's title) & (Tag's title) - the result is union of all searches (Sting may use wildcards - for more info see Appendix A)
          category Integer Optional Search Posts with exact Category's id
          tag [Integer] Optional Search Posts with exact Tag's id. Formed like singleton [tag_id]
          tag__in [Integer] Optional Search Posts with Tag's Id ONE of [tag_id]
          tag__all [Integer] Optional Search Posts with Tag's Id ALL in [tag_id]
          author String with wildcards Optional Search Posts by Author name (must contain 'first_name' and 'last_name' separated by whitespace.")
          created_at String Optional Search Posts with exact date of creation (formated like "DD.MM.YY")
          created_at__gt String Optional Search Posts created later than specified date (formated like "DD.MM.YY")
          created_at__lt String Optional Search Posts created earlier than specified date (formated like "DD.MM.YY")
        • Curl:
          • Script location: 'data/curl/posts/getPosts.sh'
          • Usage (from 'data/curl/posts/'): '$ ./getPosts.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token;
            • -o Offset from the first record;
            • [-s] Order: key one of ['order_by_date', 'order_by_author', 'order_by_category', 'order_by_photo'] - formated like "key=true";
            • [-f] Find string for search in Post's title (Sting may use wildcards - for more info see Appendix A);
            • [-e] Find string for search in Post's text (Sting may use wildcards - for more info see Appendix A);
            • [-a] Find string for search in (Post's title and Post's text) & (Author's First name and Author's Last name) & (Category's title) & (Tag's title) - the result is union of all searches (Sting may use wildcards - for more info see Appendix A);
            • [-c] Search with exact Category's id;
            • [-n] Search Posts with exact Tag's Id [tag_id] (lenght [tag_id] == 1);
            • [-i] Search Posts with Tag's Id ONE of [tag_id];
            • [-k] Search Posts with Tag's Id ALL in [tag_id];
            • [-l] Search Posts by Author name (must contain 'first_name' and 'last_name' separated by whitespace.");
            • [-q] Search Posts with exact date of creation;
            • [-g] Search Posts created later than specified date;
            • [-j] Search Posts created earlier than specified date;
        • Response:
          • Success: JSON PostResponse object;
          • Fail:
            • If User's token includes required permissions: JSON TextResponse object with text success;
            • If User's token doesn't includes required permissions: JSON TextResponse object with text error;
      • createPost:
        • Use this method to create new Post;
        • This method is available only for Authors;
        • Request: http://HOST:PORT/createTag?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. Token of User making request. For successful request User must have Admin Permissions
          title String Yes Post's title
          text String Yes Post's text
          category_id Integer Yes Category's id
          tag_ids [Integer] Yes Array of Tag's id
        • Curl:
          • Script location: 'data/curl/post/createPost.sh'
          • Usage (from 'data/curl/post/'): '$ ./createTag.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token. Token of User making request. For successful request User must have Admin Permissions;
            • -n Post's title;
            • -b Post's text;
            • -c Category's id;
            • -m Tag's ids;
        • Response:
          • Success: JSON TextResponse object with text success;
          • Fail:
            • If User's token includes required permissions: JSON TextResponse object with text success;
            • If User's token doesn't includes required permissions: JSON TextResponse object with text error;
      • setPostMainPhoto:
        • Use this method to set Main Photo for Post. If Post already has Main Photo, Main Photo will be updated;
        • This method is available only for Author-Post owner;
        • Request: http://HOST:PORT/setPostMainPhoto?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. For successful request token must belong to User who is the Author of this Post
          id Integer Yes Post's id
          path String Yes Local path to photo
        • Curl:
          • Script location: 'data/curl/post/setPostMainPhoto.sh'
          • Usage (from 'data/curl/post/'): '$ ./setPostMainPhoto.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token;
            • -i Post's id
            • -l Path to photo
        • Response:
          • Success: JSON TextResponse object with text success;
          • Fail:
            • If User's token includes required permissions: JSON TextResponse object with text success;
            • If User's token doesn't includes required permissions: JSON TextResponse object with text error;
      • setAddMainPhoto:
        • Use this method to add Additional Photo for Post;
        • This method is available only for Author-Post owner;
        • Request: http://HOST:PORT/setAddMainPhoto?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. For successful request token must belong to User who is the Author of this Post
          id Integer Yes Post's id
          path String Yes Local path to photo
        • Curl:
          • Script location: 'data/curl/post/setAddMainPhoto.sh'
          • Usage (from 'data/curl/post/'): '$ ./setAddMainPhoto.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token;
            • -i Post's id
            • -l Path to photo
        • Response:
          • Success: JSON TextResponse object with text success;
          • Fail:
            • If User's token includes required permissions: JSON TextResponse object with text success;
            • If User's token doesn't includes required permissions: JSON TextResponse object with text error;
      • removePost:
        • Use this method to remove Post;
        • This method is available only for admins;
        • Request: http://HOST:PORT/removePost?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. Token of User making request. For successful request User must have Admin Permissions
          id Integer Yes Post's id
        • Curl:
          • Script location: 'data/curl/post/removePost.sh'
          • Usage (from 'data/curl/post/'): '$ ./removePost.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token. Token of User making request. For successful request User must have Admin Permissions;
            • -i Post's id;
        • Response:
          • Success: JSON TextResponse object with text success;
          • Fail:
            • If User's token includes required permissions: JSON TextResponse object with text success;
            • If User's token doesn't includes required permissions: JSON TextResponse object with text error;
    • Draft:
      • getDrafts:
        • Use this method to get all Draft records of Author;
        • This method is available only for Author-Post owner;
        • In one request You may recieve maximum 50 records;
        • For recieve more than 50 records You'll need to use several requests with different offset;
        • Request: http://HOST:PORT/getDrafts?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. Token of User making request. For successful request User must have Read Author Permissions;
          offset Integer Yes Offset from first Draft's record (ordered by Draft's id). Must be >=0
        • Curl:
          • Script location: 'data/curl/tag/getDrafts.sh'
          • Usage (from 'data/curl/tag/'): '$ ./getDrafts.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token. Token of User making request. For successful request User must have Read Author Permissions;
            • -o Offset from first Draft's record (ordered by Draft's id);
        • Response:
          • Success: JSON DraftResponse object;
          • Fail:
            • If User's token includes required permissions: JSON TextResponse object with text success;
            • If User's token doesn't includes required permissions: JSON TextResponse object with text error;
      • createDraft:
        • Use this method to create Draft of Post;
        • This method is available only for Author-Post owner;
        • Request: http://HOST:PORT/createDraft?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. Token of User making request. For successful request User must have Admin Permissions
          post_id Integer Yes Post's id corresponding to Draft
          text String Yes Draft's text
        • Curl:
          • Script location: 'data/curl/draft/createDraft.sh'
          • Usage (from 'data/curl/draft/'): '$ ./createDraft.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token. Token of User making request. For successful request User must have Read Author Permissions;
            • -b Draft's text;
            • -i Post's id corresponding to Draft;
        • Response:
          • Success: JSON TextResponse object with text success;
          • Fail:
            • If User's token includes required permissions: JSON TextResponse object with text success;
            • If User's token doesn't includes required permissions: JSON TextResponse object with text error;
      • editDraft:
        • Use this method to edit Draft's text;
        • This method is available only for Author-Post owner;
        • Request: http://HOST:PORT/editDraft?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. Token of User making request. For successful request User must have Admin Permissions
          post_id Integer Yes Post's id corresponding to Draft
          text String Yes New Draft's text
        • Curl:
          • Script location: 'data/curl/drafts/editDraft.sh'
          • Usage (from 'data/curl/drafts/'): '$ ./editDraft.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token. Token of User making request. For successful request User must have Admin Permissions;
            • -b New Draft's text;
            • -i Post's id corresponding to Draft;
        • Response:
          • Success: JSON TextResponse object with text success;
          • Fail:
            • If User's token includes required permissions: JSON TextResponse object with text success;
            • If User's token doesn't includes required permissions: JSON TextResponse object with text error;
      • publishDraft:
        • Use this method to publish text of Draft (Change corresponding Post's text to Draft's text);
        • This method is available only for Author-Post owner;
        • Request: http://HOST:PORT/publishDraft?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. Token of User making request. For successful request User must have Admin Permissions
          post_id Integer Yes Post's id corresponding to Draft
        • Curl:
          • Script location: 'data/curl/draft/publishDraft.sh'
          • Usage (from 'data/curl/draft/'): '$ ./publishDraft.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token. Token of User making request. For successful request User must have Admin Permissions;
            • -i Post's id corresponding to Draft;
        • Response:
          • Success: JSON TextResponse object with text success;
          • Fail:
            • If User's token includes required permissions: JSON TextResponse object with text success;
            • If User's token doesn't includes required permissions: JSON TextResponse object with text error;
      • removeDraft:
        • Use this method to remove Draft;
        • This method is available only for Author-Post owner;
        • Request: http://HOST:PORT/removeDraft?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. Token of User making request. For successful request User must have Admin Permissions
          post_id Integer Yes Post's id corresponding to Draft
        • Curl:
          • Script location: 'data/curl/draft/removeDraft.sh'
          • Usage (from 'data/curl/draft/): '$ ./removeDraft.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -t User's token. Token of User making request. For successful request User must have Admin Permissions;
            • -i Post's id corresponding to Draft;
        • Response:
          • Success: JSON TextResponse object with text success;
          • Fail:
            • If User's token includes required permissions: JSON TextResponse object with text success;
            • If User's token doesn't includes required permissions: JSON TextResponse object with text error;
    • Comment:
      • createComment:
        • Use this method to create Comment record to specified Post;
        • This method is available for all registered Users;
        • Request: http://HOST:PORT/createComment?PARAMETERS
        • Parameter Type Required Description
          token String Yes User's token. Token of User making request
          post_id Integer Yes Post's id corresponding to Comment
          text String Yes Comment's text
        • Curl:
          • Script location: 'data/curl/comment/createComment.sh'
          • Usage (from 'data/curl/comment/'): '$ ./createComment.sh [flags]'
            • -h Print help message and exit;
            • -y Host server name;
            • -p Port server number;
            • -p Port server number;
            • -t User's token. Token of User making request;
            • -c Comment's text;
        • Response:
          • Success: JSON TextResponse object;
          • Fail: JSON TextResponse object;

    Objects

    • Post

      This object represents a Post record.

      Field Type Description
      id Integer Unique identifier for this Post
      author Author Author of Post record
      title String Title of Post record
      text String Text of Post record
      created_at String Date of creation of this Post record. Formated like "DD.MM.YY"
      category Category Category of Post record
      tags [Tag] Optional. List of Tags of Post record
      main_photo Photo Optional. Main Photo of Post record
      add_photo [Photo] Optional. Additional Photos of Post record
      comments [Comment] Optional.Comments of Post record

    • User

      This object represents a User record.

      Field Type Description
      id Integer Unique identifier for this User
      is_admin Boolean True, if this User is a admin
      first_name String User's first name
      last_name String User's last name
      photo Photo User's Photo

    • Author

      This object represents a Author record.

      Field Type Description
      user User User corresponding to this Author
      description String Author's description

    • Category

      This object represents a Category record.

      Field Type Description
      id Integer Unique identifier for this Category
      title String Category's title
      subcategory Category Optional.SubCategory of this Category

    • Tag

      This object represents a Tag record.

      Field Type Description
      id Integer Unique identifier for this Tag
      title String Tag's title

    • Draft

      This object represents a Draft record.

      Field Type Description
      id Integer Unique identifier for this Draft
      text String Draft's text
      post_id Integer Post's id corresponding to Draft

    • Photo

      This object represents a Photo record.

      Field Type Description
      id Integer Unique identifier for this Photo
      link String Link to Photo

    • Comment

      This object represents a Comment record.

      Field Type Description
      id Integer Unique identifier for this Comment
      text String Comment's text

    • Responses

      • PostResponse

        This object represents a Response containing Post records.

        Field Type Description
        offset Integer Offset from first Post's record corresponding to request options (ordered by Post's id)
        posts [Post] List of Post's records corresponding to request options (Limit 50 records in one request)

      • UserResponse

        This object represents a Response containing User records.

        Field Type Description
        offset Integer Offset from first User's record (ordered by User's id)
        users [User] List of User's records corresponding to request options (Limit 50 records in one request)

      • AuthorResponse

        This object represents a Response containing Author records.

        Field Type Description
        offset Integer Offset from first Author's record (ordered by Author's id)
        users [Author] List of Author's records corresponding to request options (Limit 50 records in one request)

      • CategoryResponse

        This object represents a Response containing Category records.

        Field Type Description
        offset Integer Offset from first Category's record (ordered by Category's id)
        categories [Category] List of Category's records corresponding to request options (Limit 50 records in one request)

      • TagResponse

        This object represents a Response containing Tag records.

        Field Type Description
        offset Integer Offset from first Tag's record (ordered by Tag's id)
        tags [Tag] List of Tag's records corresponding to request options (Limit 50 records in one request)

      • DraftResponse

        This object represents a Response containing Draft records.

        Field Type Description
        offset Integer Offset from first Draft's record (ordered by Draft's id)
        drafts [Draft] List of Draft's records corresponding to request options (Limit 50 records in one request)

      • TextResponse

        This object represents a message detailing success/error of processing request.

        Field Type Description
        message String Message detailing success/error of processing request

      Permissions

      • Admin Permission

        This type of permissions have only persons from admin list in data/config.json file

        • Permissions to get/create/edit/remove Author's records;
        • Permissions to get/remove Post's records;
        • Permissions to get/remove User's records;
        • Permissions to get/create/edit/remove Category's records;
        • Permissions to get/create/edit/remove Tag's records;
        • Permissions to create Comment's records;
      • User Permission

        This type of permissions have all registered Users

        • Permissions to get Post's records;
        • Permissions to get User's records;
        • Permissions to get Category's records;
        • Permissions to get Tag's records;
        • Permissions to create Comment's records;
      • Author Write Permission

        This type of permissions have all registered Users

        • Permissions to get/create Post's records;
        • Permissions to get User's records;
        • Permissions to get Category's records;
        • Permissions to get Tag's records;
        • Permissions to create Comment's records;
      • Author Write Permission

        This type of permissions have all registered Users

        • Permissions to get/create Post's records;
        • Permissions to get User's records;
        • Permissions to get/edit/publish/remove Draft's records of Post's belonging to this Author;
        • Permissions to get Category's records;
        • Permissions to get Tag's records;
        • Permissions to create Comment's records;

      Appendix A

      • For unicode symbols in requests (using .sh scripts) use folowing:
        • Instead of whitespace: %20
        • Instead of left square parenthesis "[": %5B
        • Instead of right square parenthesis "[": %5D
      • Supporting wildcard symbols:
        • _ denotes any single character (is comparable to . in POSIX regular expressions);
        • % denotes any string (is comparable to .* in POSIX regular expressions);
        • | denotes alternation (either of two alternatives);
        • * denotes repetition of the previous item zero or more times;
        • + denotes repetition of the previous item one or more times;
        • ? denotes repetition of the previous item zero or one time;
        • {m} denotes repetition of the previous item exactly m times;
        • {m,} denotes repetition of the previous item m or more times;
        • {m,n} denotes repetition of the previous item at least m and not more than n times;
        • Parentheses () can be used to group items into a single logical item;
        • A bracket expression [...] specifies a character class, just as in POSIX regular expressions;

post-server's People

Contributors

lyupo7 avatar

Watchers

 avatar

post-server's Issues

Миграции

А как у тебя реализованы миграции? Не могу найти это в коде и Readme

БД

Есть ли возможность визуализировать схему бд?

Запуск сервера

Из ридми файла не совсем очевидно, как запускать сервер - в частности что должно быть сделано с бд - я так понимаю, необходимо создать юзера и базу? и конфиг не подразумевает пароля к базе, это так и задумано?

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.