Skip to content

DK6asDK6/library_test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Article Management API

A backend service that stores arbitrary data as posts and controls visibility based on user permissions. The permission system has three levels:

  • access = 0Guest (default, can view public posts)
  • access = 1Moderator (can view posts with access ≤ 1)
  • access = 2Admin (can view all posts)

At the time of writing, only the backend is complete; the frontend is under development and will be documented later.


Table of Contents


Technology Stack

  • Node.js – JavaScript runtime
  • Express.js – Web framework
  • MongoDB – NoSQL database (with Mongoose ODM)
  • JavaScript (ES6+) – Full‑stack language

Code Style & Documentation

The codebase follows a strict commenting convention to keep it self‑documenting and maintainable. Every file, data structure, and function is preceded by a descriptive comment block.

File Header

Each file must begin with a comment block that describes its purpose, lists all imports (grouped by external libraries and internal modules), and declares exports.

/*
 * Brief description of the file
 * IMPORTS:
 *  - imported libraries
 *  - from internal directories
 *      - imported objects: purpose
 * EXPORTS:
 *  - exported objects
 */

File Footer

Every file ends with a footer comment that clearly marks its end.

/*
 * END OF 'filename' FILE
 */

Structure Comments

For data structures (e.g., Mongoose schemas) the following format is used:

/*
 * Brief description of the structure
 * Fields:
 *  - field name - purpose
 */

Function Comments (Route Handlers)

Route handler functions (typically POST, GET, DELETE) are documented with detailed information about the route, request body, and response body.

/*
 * Brief description of the function
 * Route: API path
 * Request body:
 *  - field: description
 *  - (if a nested structure is passed)
 *  - field: structure with following fields:
 *      - subfield: description
 * Response body:
 *  - field - description
 */

General Function Comments

For utility functions, middleware, and other non‑route functions, a simpler comment style is used (still including a description and details of parameters/return values when needed).

Project Structure

The repository is organised as follows:

.
├── client/                     # (In development) Frontend application
├── middleware/
│   ├── upload.js               # Handles file uploads, enforces file size/type limits
│   └── validation.js           # Validates incoming structures for posts and users
├── models/
│   ├── post.js                 # Mongoose schema for posts
│   └── user.js                 # Mongoose schema for users
├── routes/
│   ├── posts.js                # Route handlers for post‑related endpoints
│   └── users.js                # Route handlers for user‑related endpoints
├── package.json                # Project metadata and dependencies
└── server.js                   # Entry point – starts Node server and connects to MongoDB
  • client/ – Frontend code (currently under development, will be added later).

  • middleware/upload.js – Manages file uploads, validates file types and sizes.

  • middleware/validation.js – Validates request bodies for posts and users against defined schemas.

  • models/ – Defines the database structures (Mongoose schemas) for Post and User.

  • routes/ – Contains all route handlers for processing requests related to posts and users.

  • server.js – Bootstraps the Express server and establishes the MongoDB connection.

Frontend Status

The frontend part of the application is currently under development. Once ready, this section will be updated with instructions for setting up and running the client.

Getting started

Prerequisites

  • Node.js (v14 or later)
  • MongoDB (v7.0.37 or later)

Installation

  1. Clone the repository:
git clone https://github.com/DK6asDK6/library_test.git
cd  library_test
  1. Install dependencies:
npm install

Running the Server

Start server in production mode:

npm start

API Endpoints

The main endpoints are:

  • POST /api/users - Register new user
  • GET /api/users - Get list of all users (request allowed only for admins)
  • POST /api/users/login - Log user in
  • POST /api/users/access - Set user's access level (request allowed only for admins)
  • POST /api/users/reset - Reset user's password (old password required)
  • POST /api/users/reset_admin - Reset other user's password (request allowed only for admins)
  • POST /api/posts/:uid - Create new post (access 1 or more required)
  • GET /api/posts/:uid - Show all posts (if user is not admin, only approved ones are shown)
  • GET /api/posts/one/:id - Show one post
  • POST /api/posts/appr/:uid - Approve or Revoke post (request allowed only for admins)
  • DELETE /api/posts/:uid/:id - Remove one post (request allowed only for admins)

About

Test repository for developing a SUAI archive

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors