pf03 / server

BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

SERVER


ORDER OF LAUNCH AND TESTING (tested only for Windows)

  1. Run commands:
  2. To run the binary file successfully, copy the following files and folders from repository into the same folder with the binary file:
    • curl
    • migrations
    • photos
    • config-example.json
  3. Rename the config-example.json file to config.json and, if necessary, edit it
  4. To initialize DB tables and bring them up to date, start the server with the db-init flag. The rest of the command line options that might be useful for testing are listed below.
  5. To update the token file dist/curl/tokens.sh, start the server with the gen-tokens flag
  6. API functions could be tested using curl requests in the corresponding folder
  7. To test pure functions run stack test
  8. Rules for registration of migrations:
    • file names are in the strict 1234_migration_name.sql format and in strict order, starting at 0000_migration_name.sql;
    • the drop.sql file is used to drop tables;
    • files with other names are ignored.

For migrations test:

STARTING THE SERVER:

MIGRATION:

CURL:


MODULES

The server operation logic is divided into the following layers (presented in the corresponding folders in the src) from low to high:

  1. Common - common functions;
  2. Interface - classes of types that implement abstract access of higher layers to interfaces:
    • MError - error handling,
    • MLog - logging,
    • MCache - working with changing data in pure code,
    • MDB - work with PostgreSQL database;
  3. Logic - the main logic of the program, for convenience it is divided into:
    • Pure - pure functions,
    • IO - IO functions,
    • DB - functions for working with the database;
  4. T - one of the possible implementations of the interface - transformer T;
  5. App - application layer functions that have access to both the interface and its implementation.

Lower layers should not import modules from higher layers.

API

The server supports the following api functions (paths). Some paths are available only for admin (marked with ). In this case, other users receive an Unknown path error. Some paths are available only for authorized users () or for all users (). For testing each path, there is a separate file in the curl folder. The requests in the file are duplicated for different tokens (users). The posts request is tested with different filters. All possible paths are written in the Logic.Pure.API.router function. All possible parameters for each path are written in theLogic.Pure.Params.Internal.possibleParamDescs function. All requests for creating, editing, deleting entities and uploading photos return the number of changed entities.

Paths list:

  1. Login
    /login - login
  2. Files
    /photos/upload - upload photo, for all;
    photos/fileName - download photo by fileName;
    photos - returns list of photos filenames;
  3. DB
    • Insert
      users/create - create a user;
      authors/create - create an author;
      categories/create - create a category;
      tags/create - create a tag;
      drafts/create - create a draft;
      drafts/n/publish - publish a draft (delete draft and create post);
      posts/n/comments/create - create a comment to a post with id = n;
    • Update
      users/n/edit - edit user with id = n;
      user/edit - edit current user;
      authors/n/edit - edit author with id = n;
      categories/n/edit - edit category with id = n;
      tags/n/edit - edit tag with id = n;
      drafts/n/edit - edit draft with id = n;
      posts/n/edit - edit post with id = n;
    • Delete
      users/n/delete - delete user with id = n;
      authors/n/delete - delete author with id = n;
      categories/n/delete - delete category with id = n;
      tags/n/delete - delete tag with id = n;
      drafts/n/delete - delete draft with id = n;
      posts/n/delete - delete post with id = n;
      comments/n/delete - delete comment with id = n;
    • Select many
      users - select many users with pagination;
      authors - select many authors with pagination;
      categories - select many categories with pagination;
      tags - select many tags with pagination;
      posts - select many posts with pagination and filters;
      drafts - select many drafts with pagination;
      posts/n/comments - select many comments with pagination for post with id = n;
    • Select by id
      users/n - select user with id = n;
      user - select current user;
      authors/n - select author with id = n;
      categories/n - select category with id = n;
      tags/n - select tag with id = n;
      posts/n - select post with id = n;
      drafts/n - select draft with id = n.