Skip to content

Latest commit

 

History

28 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Web Developer Assignment

Backend

cd backend
npm install
npm run db
npm start   # or: npm run dev

URL

https://backend-8bxt.onrender.com

API Backend

User Endpoints

  • GET /users → Returns a list of users with pagination support.
  • GET /users/count → Returns the total number of users.
  • GET /users/:id → Returns a single user with the total post count they have added.
  • POST /users/adders → Adds an adder to a user.

Post Endpoints

  • GET /posts → Returns posts filtered by a specific userId query parameter.
    Example: /posts?userId={userId}
  • GET /posts/count → Returns the total number of posts.
  • POST /posts → Create a new post.
  • DELETE /posts/:id → Delete a post.

Frontend

cd frontend
npm install
npm start   # or: npm run dev

URL

https://frontend-web-bbrj.onrender.com

Frontend Features

  • View the list of users.
  • View the list of posts by the user.
  • Add a new post.
  • Delete a post.
  • View post creator data at the top.

Test

  • run npm run test - to run the unit tests

Database Schema (ER Diagram)

erDiagram
    USERS {
        int id PK
        string name
        string email
        string username
        string phone

    }
    POSTS {
        int id PK
        string title
        string body
        datetime created_at
        int user_id FK
    }
    ADDERS {
        int id PK
        string key
        string value
        int user_id FK
    }

    USERS ||--o{ POSTS : "has many"
    USERS ||--o{ ADDERS : "has many"
Loading

Example SQL Templates

Select posts by user (sorted by createdAt)

SELECT *
FROM posts
WHERE user_id = ?
ORDER BY created_at DESC;

Count posts by user

SELECT COUNT(*) as postCount
FROM posts
WHERE user_id = ?;

Example Validation (Frontend)

const check = {
  title: title.trim().length > 0,
  body: body.trim().length > 0,
};
setError(check);

Notes

  • Ensure React Query is used for fetching data.
  • Backend is built with Node.js + Express + SQL.
  • Frontend is built with React + React Query + React Router.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages